Ejemplo n.º 1
0
    public int CreateContainer(string customId, string workingDirectory, string dockerfile, IList <string> peripheralIds)
    {
        VagrantController.PrepareContainerDirectory(customId, dockerfile);
        VagrantController.PreparePeripheralDirectory(customId);

        foreach (var peripheral in peripheralIds)
        {
            VagrantController.PreparePeripheral(customId, peripheral);
        }

        if (!string.IsNullOrEmpty(workingDirectory))
        {
            VagrantController.CopyBuildContext(workingDirectory, customId);
        }

        VagrantController.DockerImageBuild(customId, out var imageId);

        if (string.IsNullOrEmpty(imageId))
        {
            return((int)Errors.ImageBuildError);
        }

        VagrantController.DockerContainerCreate(customId, imageId, peripheralIds.Count > 0, out var containerId);

        _containersIds.Add(customId, containerId);

        return((int)Errors.OK);
    }
Ejemplo n.º 2
0
    public int DeleteContainer(string customId)
    {
        if (!_containersIds.ContainsKey(customId))
        {
            return((int)Errors.NoSuchContainer);
        }

        VagrantController.DockerContainerRemove(_containersIds[customId]);

        return((int)Errors.OK);
    }
Ejemplo n.º 3
0
    public int Stop()
    {
        foreach (var pair in _containersIds)
        {
            var containerId = pair.Value;
            StopContainer(containerId);
            DeleteContainer(containerId);
        }

        VagrantController.VagrantStop();

        return((int)Errors.OK);
    }
Ejemplo n.º 4
0
    public int CreateTTY(string customId, out StreamWriter stdin, out StreamReader stdout, bool forceSTY = false)
    {
        if (!_containersIds.ContainsKey(customId))
        {
            stdout = null;
            stdin  = null;
            return((int)Errors.NoSuchContainer);
        }

        VagrantController.DockerContainerAttach(_containersIds[customId], out stdin, out stdout, out var stderr, forceSTY);
        //Logger.Log(stderr, "[AttachErr]"); This freezes the thing for some reason

        return((int)Errors.OK);
    }
Ejemplo n.º 5
0
    public int Disconnect(string containerIdA, string containerIdB)
    {
        var tuple = _determinableTuple(containerIdA, containerIdB);

        if (!_networks.ContainsKey(tuple))
        {
            return((int)Errors.NotConnected);
        }

        var netname = _networks[tuple];

        VagrantController.DockerNetworkDisconnect(_containersIds[containerIdA], netname);
        VagrantController.DockerNetworkDisconnect(_containersIds[containerIdB], netname);
        VagrantController.DockerNetworkRemove(netname);
        return((int)Errors.OK);
    }
Ejemplo n.º 6
0
    public int StopSnoopOn(string containerIdA, string containerIdB, string containerSnooping)
    {
        var tuple = _determinableTuple(containerIdA, containerIdB);

        if (!_networks.ContainsKey(tuple))
        {
            return((int)Errors.NotConnected);
        }

        var netName = _networks[tuple];

        VagrantController.DockerNetworkDisconnect(_containersIds[containerSnooping], netName);
        var ipa        = VagrantController.GetContainerIP(_containersIds[containerIdA], netName);
        var ipb        = VagrantController.GetContainerIP(_containersIds[containerIdB], netName);
        var ipAttacker = VagrantController.GetContainerIP(_containersIds[containerSnooping], netName);

        VagrantController.IptablesRemoveEavesdropping(ipa, ipb, ipAttacker);
        return((int)Errors.OK);
    }
Ejemplo n.º 7
0
    public int Connect(string containerIdA, string containerIdB)
    {
        if (!_containersIds.ContainsKey(containerIdA) || !_containersIds.ContainsKey(containerIdB))
        {
            return((int)Errors.NoSuchContainer);
        }

        var tuple = _determinableTuple(containerIdA, containerIdB);

        if (_networks.ContainsKey(tuple))
        {
            return((int)Errors.AlreadyConnected);
        }

        var netName = Convert.ToBase64String(new Guid().ToByteArray());

        _networks.Add(tuple, netName);

        VagrantController.DockerNetworkCreate(netName);
        VagrantController.DockerNetworkConnect(_containersIds[containerIdA], netName);
        VagrantController.DockerNetworkConnect(_containersIds[containerIdB], netName);

        return((int)Errors.OK);
    }
Ejemplo n.º 8
0
 public void Begin()
 {
     VagrantController.VagrantPrepare();
 }
Ejemplo n.º 9
0
 public string VagrantDebugExecute(string command)
 {
     return(VagrantController.DebugExecute(command));
 }
Ejemplo n.º 10
0
 public StreamWriter GetPeripheralOutgoingStream(string containerId, string peripheralId)
 {
     return(VagrantController.GetPeripheralOutstream(peripheralId, containerId));
 }
Ejemplo n.º 11
0
 public StreamReader GetPeripheralIngoingStream(string containerId, string peripheralId)
 {
     return(VagrantController.GetPeripheralInstream(peripheralId, containerId));
 }