コード例 #1
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
        public Task <ContainerExecResult> Exec(ContainerExec exec)
        {
            JToken response     = API.Post($"/{Client.Version}/containers/{Name}/exec", exec);
            string operationUrl = response.Value <string>("operation");

            return(ContainerExecResult.Create(API, exec, response, operationUrl));
        }
コード例 #2
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
                public static async new Task <ContainerExecResult> Create(API API, ContainerExec exec, JToken response, string operationUrl)
                {
                    var result           = new ContainerExecResultWithWebSockets(exec);
                    var webSocketStrings = exec.Interactive ? new[] { "0", "control" } : new[] { "0", "1", "2", "control" };
                    var sockets          = new List <ClientWebSocket>();

                    foreach (var i in webSocketStrings)
                    {
                        string fdsSecret = response.SelectToken($"metadata.metadata.fds.{i}").Value <string>();
                        string wsUrl     = $"{API.BaseUrlWebSocket}{operationUrl}/websocket?secret={fdsSecret}";
                        sockets.Add(await ClientWebSocketExtensions.CreateAndConnectAsync(wsUrl, API));
                    }
                    result.WebSockets = sockets.ToArray();
                    return(result);
                }
コード例 #3
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
 public static async Task <ContainerExecResult> Create(API API, ContainerExec exec, JToken response, string operationUrl)
 {
     if (exec.WaitForWebSocket)
     {
         response = API.Get(operationUrl);
         return(await ContainerExecResultWithWebSockets.Create(API, exec, response, operationUrl));
     }
     else if (exec.Interactive == false && exec.RecordOutput)
     {
         response = API.Get(operationUrl);
         return(ContainerExecResultWithRecords.Create(API, exec, response, operationUrl));
     }
     else
     {
         API.WaitForOperationComplete(response);
         return(new ContainerExecResult(exec));
     }
 }
コード例 #4
0
        public IEnumerable <ClientWebSocket> Exec(string[] command,
                                                  Dictionary <string, string> environment = null,
                                                  bool waitForWebSocket = true,
                                                  bool interactive      = true,
                                                  int width             = 80,
                                                  int height            = 25)
        {
            ContainerExec exec = new ContainerExec()
            {
                Command          = command,
                Environment      = environment,
                WaitForWebSocket = waitForWebSocket,
                Interactive      = interactive,
                Width            = width,
                Height           = height,
            };

            JToken response     = API.Post($"/{Client.Version}/containers/{Name}/exec", exec);
            string operationUrl = response.Value <string>("operation");

            if (waitForWebSocket == false)
            {
                API.WaitForOperationComplete(response);
                // wait-for-websocket is false. Nothing to return.
                return(null);
            }

            response = API.Get(operationUrl);

            int fdsN = interactive ? 1 : 3;

            List <Task <ClientWebSocket> > tasks = new List <Task <ClientWebSocket> >();

            for (int i = 0; i < fdsN; i++)
            {
                string fdsSecret            = response.SelectToken($"metadata.metadata.fds.{i}").Value <string>();
                string wsUrl                = $"{API.BaseUrlWebSocket}{operationUrl}/websocket?secret={fdsSecret}";
                Task <ClientWebSocket> task = ClientWebSocketExtensions.CreateAndConnectAsync(wsUrl);
                tasks.Add(task);
            }
            Task.WaitAll(tasks.ToArray());

            return(tasks.Select(t => t.Result));
        }
コード例 #5
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
                public static new ContainerExecResult Create(API api, ContainerExec exec, JToken response, string operationUrl)
                {
                    var result = new ContainerExecResultWithRecords(exec);

                    result.API = api;
                    response   = response.SelectToken("metadata");
                    if (response.SelectToken("status_code").Value <int>() == 103)
                    {
                        var    t     = api.Timeout;
                        string op_id = response.SelectToken("id").Value <string>();
                        api.Timeout = System.Threading.Timeout.Infinite;
                        response    = api.Get($"/1.0/operations/{op_id}/wait").SelectToken("metadata");
                        api.Timeout = t;
                    }

                    result.ReturnCode = response.SelectToken("metadata.return").Value <int>();
                    result.RecordUrls = (new[] { "1", "2" }).Select(s =>
                                                                    response.SelectToken($"metadata.output.{s}").Value <string>()
                                                                    ).ToArray();
                    return(result);
                }
コード例 #6
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
        public Task <ContainerExecResult> Exec(string[] command,
                                               Dictionary <string, string> environment = null,
                                               bool waitForWebSocket = true,
                                               bool recordOutput     = false,
                                               bool interactive      = true,
                                               int width             = 80,
                                               int height            = 25)
        {
            ContainerExec exec = new ContainerExec()
            {
                Command          = command,
                Environment      = environment,
                WaitForWebSocket = waitForWebSocket,
                RecordOutput     = recordOutput,
                Interactive      = interactive,
                Width            = width,
                Height           = height,
            };

            return(Exec(exec));
        }
コード例 #7
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
 protected ContainerExecResultWithRecords(ContainerExec exec) : base(exec)
 {
 }
コード例 #8
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
 protected ContainerExecResultWithWebSockets(ContainerExec exec) : base(exec)
 {
 }
コード例 #9
0
ファイル: Container.cs プロジェクト: impulsemachines/SharpLXD
 protected ContainerExecResult(ContainerExec exec)
 {
     ExecSettings = exec;
 }