public override Task <Response> HandleAsync() { return(Task.Run <Response>(async() => { var config = new WardenConfig(); var handle = new ContainerHandle(); var containerService = new ContainerService( config.ContainerBasePath, config.WardenUsersGroup); var containerSpec = new ContainerSpec { Handle = handle, BindMounts = GetBindMounts(request).ToArray(), }; var container = containerService.CreateContainer(containerSpec); var containerClient = new ContainerClient(containerService, container, new FileSystemManager()); await containerClient.InitializeAsync(null, null, null); containerManager.AddContainer(containerClient); return new CreateResponse { Handle = handle }; })); }
public void DestroyContainer(ContainerHandle handle) { if (handle == null) { throw new ArgumentNullException("handle"); } Container removed; if (containers.TryRemove(handle, out removed)) { try { removed.Destroy(); } catch { log.Error("Error destroying container! Re-adding to collection."); containers[handle] = removed; throw; } } else { throw new WardenException("Could not remove container '{0}' from collection!", handle); } }
public RestoreContainers() { Handle = new ContainerHandle().ToString(); ContainerPath = Path.Combine(TempDirectory, Handle); Directory.CreateDirectory(ContainerPath); }
public Container() { this.handle = new ContainerHandle(); this.user = new ContainerUser(handle, shouldCreate: true); this.directory = new ContainerDirectory(this.handle, this.user, true); this.state = ContainerState.Born; this.processManager = new ProcessManager(this.user); }
public void GeneratesUniqueIds() { var handle1 = new ContainerHandle(); var handle2 = new ContainerHandle(); Assert.Equal(11, handle1.ToString().Length); Assert.Equal(11, handle2.ToString().Length); Assert.NotEqual(handle1, handle2); }
public Container GetContainer(string handle) { var cHandle = new ContainerHandle(handle); Container retrieved; if (!containers.TryGetValue(cHandle, out retrieved)) { // TODO: throw exception with message that matches ruby warden log.Warn("Expected to find container with handle '{0}'", handle); } return retrieved; }
private static DirectoryInfo FindContainerDirectory(ContainerHandle handle) { var dirInfo = GetContainerDirectoryInfo(handle); if (Directory.Exists(dirInfo.Item2)) { return new DirectoryInfo(dirInfo.Item2); } else { throw new WardenException("Directory '{0}' does not exist!", dirInfo.Item2); } }
private static DirectoryInfo CreateContainerDirectory(ContainerHandle handle, ContainerUser user) { var dirInfo = GetContainerDirectoryInfo(handle); var inheritanceFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit; var accessRule = new FileSystemAccessRule(user, FileSystemRights.FullControl, inheritanceFlags, PropagationFlags.None, AccessControlType.Allow); DirectoryInfo containerBaseInfo = dirInfo.Item1; DirectorySecurity security = containerBaseInfo.GetAccessControl(); security.AddAccessRule(accessRule); string containerDirectory = dirInfo.Item2; return Directory.CreateDirectory(containerDirectory, security); }
public ProcessCommandTests() { // Create a temporary directory to use as the container root tempDir = CreateTempDir(); handle = new ContainerHandle("TestContainerHandle"); user = Substitute.For <IContainerUser>(); user.UserName.Returns("TestUser"); user.GetCredential().ReturnsForAnyArgs(new System.Net.NetworkCredential("TestUser", "TestUserPassword")); directory = Substitute.For <IContainerDirectory>(); process = Substitute.For <IProcess>(); container = Substitute.For <IContainer>(); container.ContainerDirectoryPath.Returns(tempDir); }
public ContainerDirectory(ContainerHandle handle, ContainerUser user, bool shouldCreate = false) { if (handle == null) { throw new ArgumentNullException("handle"); } if (shouldCreate) { this.containerDirectory = CreateContainerDirectory(handle, user); } else { this.containerDirectory = FindContainerDirectory(handle); } }
/// <summary> /// Used for restore. /// </summary> private Container(string handle, ContainerState containerState) { if (handle.IsNullOrWhiteSpace()) { throw new ArgumentNullException("handle"); } this.handle = new ContainerHandle(handle); if (containerState == null) { throw new ArgumentNullException("containerState"); } this.state = containerState; this.user = new ContainerUser(handle); this.directory = new ContainerDirectory(this.handle, this.user); this.processManager = new ProcessManager(this.user); if (this.state == ContainerState.Active) { this.RestoreProcesses(); } }
private static Tuple<DirectoryInfo, string> GetContainerDirectoryInfo(ContainerHandle handle) { var config = new WardenConfig(); string containerBasePath = config.ContainerBasePath; string containerDirectory = Path.Combine(containerBasePath, handle); return new Tuple<DirectoryInfo, string>(new DirectoryInfo(containerBasePath), containerDirectory); }
public void GivenInputData_GeneratesExpectedID(long input, string expectedID) { var handle = new ContainerHandle(input); Assert.Equal <string>(expectedID, handle); }
public void GeneratesIdFromRandomGenerator(int input, string expectedId) { var handle = new ContainerHandle(new Random(input)); Assert.Equal <string>(expectedId, handle); }
public void GivenInputData_GeneratesExpectedID(long input, string expectedID) { var handle = new ContainerHandle(input); Assert.Equal<string>(expectedID, handle); }