// export image private static void ExportImage(ImsClient imsV1Client) { ExportImageRequest exportImsRequest = new ExportImageRequest { ImageId = "d70af0f0-515d-41d7-9c9f-bc4e2b233ee6", Body = new ExportImageRequestBody() { BucketUrl = "obs-494b:test.qcow2", FileFormat = ExportImageRequestBody.FileFormatEnum.QCOW2 } }; try { var exportImsResponse = imsV1Client.ExportImage(exportImsRequest); Console.WriteLine(exportImsResponse.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); } }
/// <summary> /// 导出镜像 /// </summary> public ExportImageResponse ExportImage(ExportImageRequest exportImageRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); urlParam.Add("image_id", exportImageRequest.ImageId.ToString()); string urlPath = HttpUtils.AddUrlPath("/v1/cloudimages/{image_id}/file", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", exportImageRequest); HttpResponseMessage response = DoHttpRequestSync("POST", request); return(JsonUtils.DeSerialize <ExportImageResponse>(response)); }
/// <summary> /// Creates a waiter using the provided configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="config">Wait Configuration</param> /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <ExportImageRequest, ExportImageResponse> ForExportImage(ExportImageRequest request, WaiterConfiguration config, params WorkrequestsService.Models.WorkRequest.StatusEnum[] targetStates) { return(new Waiter <ExportImageRequest, ExportImageResponse>(() => { var response = client.ExportImage(request).Result; var getWorkRequestRequest = new Oci.WorkrequestsService.Requests.GetWorkRequestRequest { WorkRequestId = response.OpcWorkRequestId }; workRequestClient.Waiters.ForWorkRequest(getWorkRequestRequest, config, targetStates).Execute(); return response; })); }
private void HandleOutput(ExportImageRequest request) { var waiterConfig = new WaiterConfiguration { MaxAttempts = MaxWaitAttempts, GetNextDelayInSeconds = (_) => WaitIntervalSeconds }; switch (ParameterSetName) { case StatusParamSet: response = client.Waiters.ForExportImage(request, waiterConfig, WaitForStatus).Execute(); break; case Default: response = client.ExportImage(request).GetAwaiter().GetResult(); break; } WriteOutput(response, response.Image); }
protected override void ProcessRecord() { base.ProcessRecord(); ExportImageRequest request; try { request = new ExportImageRequest { ImageId = ImageId, ExportImageDetails = ExportImageDetails, OpcRetryToken = OpcRetryToken, IfMatch = IfMatch }; HandleOutput(request); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/// <summary> /// Creates a waiter using default wait configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="statuses">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <ExportImageRequest, ExportImageResponse> ForExportImage(ExportImageRequest request, params WorkrequestsService.Models.WorkRequest.StatusEnum[] targetStates) { return(this.ForExportImage(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates)); }