private Container(string id, IntPtr computeSystem, bool terminateOnClose, HcsNotificationWatcher watcher, IHcs hcs)
 {
     _hcs         = hcs;
     _killOnClose = terminateOnClose;
     _cs          = computeSystem;
     _watcher     = watcher;
 }
示例#2
0
        public static List <Container> EmulateComputerSystem(IHcs hcs = null)
        {
            IntPtr computeSystem;
            string output;
            var    h = hcs ?? HcsFactory.GetHcs();

            h.EnumerateComputeSystems("SELECT * FROM {0}", out output);
            return(null);
        }
示例#3
0
        /// <summary>
        /// Retrieves an existing container.
        /// </summary>
        /// <param name="id">The ID of the container.</param>
        /// <returns>A Container object that can be used to manipulate the container.</returns>
        public static Container GetComputeSystem(string id, IHcs hcs = null)
        {
            IntPtr computeSystem;
            var    h = hcs ?? HcsFactory.GetHcs();

            h.OpenComputeSystem(id, out computeSystem);

            return(Container.Initialize(id, computeSystem, false, h));
        }
示例#4
0
        /// <summary>
        /// Retrieves an existing container.
        /// </summary>
        /// <param name="id">The ID of the container.</param>
        /// <returns>A Container object that can be used to manipulate the container.</returns>
        public static Container GetComputeSystem(string id, IHcs hcs = null)
        {
            IntPtr computeSystem;
            var    h   = hcs ?? HcsFactory.GetHcs();
            bool   ret = h.OpenComputeSystem(id, out computeSystem);

            if (ret)
            {
                Console.WriteLine("123");
            }

            return(Container.Initialize(id, computeSystem, false, h));
        }
 internal Process(IntPtr process, StreamWriter stdin, StreamReader stdout, StreamReader stderr, bool killOnClose, IHcs hcs)
 {
     _hcs         = hcs;
     _p           = process;
     _stdin       = stdin;
     _stdout      = stdout;
     _stderr      = stderr;
     _killOnClose = killOnClose;
     _watcher     = new HcsNotificationWatcher(
         _p,
         _hcs.RegisterProcessCallback,
         _hcs.UnregisterProcessCallback,
         new HCS_NOTIFICATIONS[] {
         HCS_NOTIFICATIONS.HcsNotificationProcessExited
     }
         );
 }
        public HvContainer()
        {
            HcsFactory    hcsFactory   = new HcsFactory();
            IHcs          Hvhcs        = HcsFactory.GetHcs();
            DockerMonitor dockerLoader = new DockerMonitor();
            IList <ContainerListResponse> containerListResponses = dockerLoader.GetContainerListAsync().GetAwaiter().GetResult();

            foreach (ContainerListResponse c in containerListResponses)
            {
                Container container = HostComputeService.GetComputeSystem(c.ID);
                dockerLoader.GetContainerStats(c.ID).GetAwaiter().GetResult();
                //Console.WriteLine(perfInfo.memLimit);
                //Console.WriteLine(container.GetType().Name);

                //ContainerSettings containerSettings = new ContainerSettings();

                //Console.WriteLine(container.);
            }
        }
示例#7
0
        /// <summary>
        /// Creates (but does not start) a new container.
        /// </summary>
        /// <param name="id">The ID of the new container. Must be unique on the machine.</param>
        /// <param name="settings">The settings for the container.</param>
        /// <returns>A Container object that can be used to manipulate the container.</returns>
        public static Container CreateContainer(string id, ContainerSettings settings, IHcs hcs = null)
        {
            var h           = hcs ?? HcsFactory.GetHcs();
            var hcsSettings = new Schema.ContainerSettings
            {
                SystemType      = Schema.SystemType.Container,
                LayerFolderPath = settings.SandboxPath,
                Layers          = settings.Layers.Select(x => new Schema.Layer {
                    Id = x.Id, Path = x.Path
                }).ToArray(),
                HvPartition = settings.HyperVContainer,
                TerminateOnLastHandleClosed = settings.KillOnClose,
            };

            if (settings.MappedDirectories != null)
            {
                hcsSettings.MappedDirectories = settings.MappedDirectories.Select(x => new Schema.MappedDirectory {
                    HostPath = x.HostPath, ContainerPath = x.ContainerPath
                }).ToArray();
            }

            if (settings.NetworkId != Guid.Empty)
            {
                hcsSettings.NetworkEndpoints = new Schema.NetworkEndpoint[]
                {
                    new Schema.NetworkEndpoint
                    {
                        NetworkId    = settings.NetworkId,
                        EndpointName = id,
                    }
                };
            }

            if (settings.UtilityVmPath != null)
            {
                hcsSettings.HvRuntime = new Schema.UtilityVmSettings
                {
                    ImagePath = settings.UtilityVmPath
                };
            }

            IntPtr computeSystem;

            h.CreateComputeSystem(id, JsonHelper.ToJson(hcsSettings), IntPtr.Zero, out computeSystem);
            return(Container.Initialize(id, computeSystem, settings.KillOnClose, h));
        }
        internal static Container Initialize(string id, IntPtr computeSystem, bool terminateOnClose, IHcs hcs = null)
        {
            var h       = hcs ?? HcsFactory.GetHcs();
            var watcher = new HcsNotificationWatcher(
                computeSystem,
                h.RegisterComputeSystemCallback,
                h.UnregisterComputeSystemCallback,
                new HCS_NOTIFICATIONS[] {
                HCS_NOTIFICATIONS.HcsNotificationSystemExited,
                HCS_NOTIFICATIONS.HcsNotificationSystemCreateCompleted,
                HCS_NOTIFICATIONS.HcsNotificationSystemStartCompleted
            }
                );
            var container = new Container(
                id,
                computeSystem,
                terminateOnClose,
                watcher,
                h);

            watcher.Wait(HCS_NOTIFICATIONS.HcsNotificationSystemCreateCompleted);

            return(container);
        }