示例#1
0
        static void Main(string[] args)
        {
            var id = Guid.Parse("716025c3-441b-4ae5-a985-1b44fa698530");

            Layer[] layers;
            switch (args[0])
            {
            case "-dismount":
                ContainerStorage.DismountSandbox(args[1]);
                break;

            case "-mount":
                layers = new Layer[] { new Layer {
                                           Id = id, Path = args[2]
                                       } };
                var sandbox = ContainerStorage.MountSandbox(args[1], layers);
                Console.Out.WriteLine(sandbox.MountPath);
                break;

            case "-create":
                layers = new Layer[] { new Layer {
                                           Id = id, Path = args[2]
                                       } };
                ContainerStorage.CreateSandbox(args[1], layers);
                break;

            case "-destroy":
                ContainerStorage.DestroyLayer(args[1]);
                break;

            case "-process":
                ContainerStorage.ProcessBaseLayer(args[1]);
                break;

            case "-processvm":
                ContainerStorage.ProcessUtilityVMImage(args[1]);
                break;
            }
        }
        public Sandbox(ContainerType containerType, Guid id)
        {
            string parent;
            string baseLayerEnv;

            switch (containerType)
            {
            case ContainerType.ServerCore:
                baseLayerEnv = servercoreBaseLayerEnv;
                break;

            case ContainerType.NanoServer:
                baseLayerEnv = nanoserverBaseLayerEnv;
                break;

            default:
                throw new ArgumentException("Invalid container type");
            }
            parent = Environment.GetEnvironmentVariable(baseLayerEnv);

            path = String.Format("C:\\\\ComputeVirtualizationTest\\{0}", id.ToString());

            layers = new Layer[]
            {
                new Layer {
                    Id = id, Path = parent
                }
            };

            try
            {
                ContainerStorage.CreateSandbox(path, layers);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Failed to create sandbox, ensure that environment variable {0} is set to a valid base layer path", baseLayerEnv), ex);
            }
        }
示例#3
0
        public Sandbox(Guid id)
        {
            string parent;

            parent = Environment.GetEnvironmentVariable(baseLayerEnv);

            path = String.Format("C:\\\\ComputeVirtualizationTest\\{0}", id.ToString());

            layers = new Layer[]
            {
                new Layer {
                    Id = id, Path = parent
                }
            };

            try
            {
                ContainerStorage.CreateSandbox(path, layers);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Failed to create sandbox, ensure that environment variable {0} is set to a valid base layer path", baseLayerEnv), ex);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            try
            {
                var parent  = args[0];
                var path    = args[1];
                var command = args[2];
                var id      = Guid.NewGuid();
                var layers  = new Layer[]
                {
                    new Layer {
                        Id = id, Path = parent
                    }
                };

                ContainerStorage.CreateSandbox(path, layers);
                try
                {
                    Console.Out.WriteLine("creating container");

                    var cs = new ContainerSettings
                    {
                        SandboxPath = path,
                        Layers      = layers,
                        KillOnClose = true,
                        NetworkId   = HostComputeService.FindNatNetwork(),
                    };
                    using (var container = HostComputeService.CreateContainer(id.ToString(), cs))
                    {
                        Console.Out.WriteLine("starting container");
                        Console.Out.Flush();
                        container.Start();
                        try
                        {
                            var si = new ProcessStartInfo
                            {
                                CommandLine            = command,
                                RedirectStandardOutput = true,
                                KillOnClose            = true,
                            };
                            using (var process = container.CreateProcess(si))
                            {
                                Console.Out.Write(process.StandardOutput.ReadToEnd());
                                process.WaitForExit(5000);
                                Console.Out.WriteLine("process exited with {0}", process.ExitCode);
                            }
                        }
                        finally
                        {
                            Console.Out.WriteLine("shutting down container");
                            container.Shutdown(Timeout.Infinite);
                        }
                    }
                }
                finally
                {
                    ContainerStorage.DestroyLayer(path);
                }
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
                Console.Out.WriteLine(e.StackTrace);
                Environment.Exit(1);
            }
        }