internal static Container Initialize(string id, IntPtr computeSystem, bool terminateOnClose, bool creatingContainer, 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); if (creatingContainer) { watcher.Wait(HCS_NOTIFICATIONS.HcsNotificationSystemCreateCompleted); } return(container); }
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); }
/// <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)); }
/// <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)); }
/// <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)); }