/// <summary>
        /// 弹性云服务器挂载磁盘
        /// </summary>
        public AttachServerVolumeResponse AttachServerVolume(AttachServerVolumeRequest attachServerVolumeRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("server_id", attachServerVolumeRequest.ServerId.ToString());
            string      urlPath  = HttpUtils.AddUrlPath("/v1/{project_id}/cloudservers/{server_id}/attachvolume", urlParam);
            SdkRequest  request  = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", attachServerVolumeRequest);
            SdkResponse response = DoHttpRequest("POST", request);

            return(JsonUtils.DeSerialize <AttachServerVolumeResponse>(response));
        }
        /// <inheritdoc />
        public ServerVolume AttachServerVolume(string serverId, string volumeId, string storageDevice = null, string region = null,
                                               CloudIdentity identity = null)
        {
            var urlPath = new Uri(string.Format("{0}/servers/{1}/os-volume_attachments", GetServiceEndpoint(identity, region), serverId));

            var request = new AttachServerVolumeRequest {
                ServerVolumeData = new AttachServerVolumeData {
                    Device = storageDevice, VolumeId = volumeId
                }
            };
            var response = ExecuteRESTRequest <ServerVolumeResponse>(identity, urlPath, HttpMethod.POST, request);

            if (response == null || response.Data == null)
            {
                return(null);
            }

            return(response.Data.ServerVolume);
        }
Ejemplo n.º 3
0
        private static void AttachServerVolume(EcsClient clint)
        {
            var req = new AttachServerVolumeRequest
            {
                ServerId = "f0a34dd7-a103-400b-a448-9baad3077af2",
                Body     = new AttachServerVolumeRequestBody
                {
                    VolumeAttachment = new AttachServerVolumeOption
                    {
                        VolumeId = "87e52ada-278f-43dd-aac2-9dc3c2876f6f"
                    }
                }
            };

            try
            {
                var resp           = clint.AttachServerVolume(req);
                var respStatusCode = resp.HttpStatusCode;
                var jobId          = resp.JobId;
                Console.WriteLine(respStatusCode);
                Console.WriteLine(jobId);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }