private static CreateKeypairResponse CreateKeypair(KpsClient client) { var request = new CreateKeypairRequest { Body = new CreateKeypairRequestBody() { Keypair = new CreateKeypairAction { Name = "KpsTest" } } }; try { var resp = client.CreateKeypair(request); Console.WriteLine(resp.ToString()); return(resp); } 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); } return(null); }
/// <summary> /// 创建和导入SSH密钥对 /// </summary> public async Task <CreateKeypairResponse> CreateKeypairAsync(CreateKeypairRequest createKeypairRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); string urlPath = HttpUtils.AddUrlPath("/v3/{project_id}/keypairs", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", createKeypairRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <CreateKeypairResponse>(response)); }