public async Task <CreateVpcResponse> CreateVpcAsync(string cidrBlock) { var request = new CreateVpcRequest(cidrBlock); var response = await _cloudComputeClient.CreateVpcAsync(request); return(response); }
public bool load_vpc_id() { write_log(region + " の VPC を確認しています。"); try { var client = get_client(); var query_req = new DescribeVpcsRequest(); query_req.Filters.Add(new Filter() { Name = "tag-value", Values = new List <string>() { Helper.build_name(setting_, "vpc") } }); var query_res = client.DescribeVpcs(query_req); if (query_res.Vpcs.Count != 0) { vpc_id = query_res.Vpcs[0].VpcId; return(true); } write_log(region + " に VPC を作成しています。"); var create_req = new CreateVpcRequest(); create_req.CidrBlock = "10.0.0.0/16"; var create_res = client.CreateVpc(create_req); set_name_tag(client, create_res.Vpc.VpcId, Helper.build_name(setting_, "vpc")); vpc_id = create_res.Vpc.VpcId; } catch (Exception ex) { write_log("ERROR: " + ex.ToString()); return(false); } return(true); }
/// <summary> /// 创建VPC /// </summary> public async Task <CreateVpcResponse> CreateVpcAsync(CreateVpcRequest createVpcRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); string urlPath = HttpUtils.AddUrlPath("/v1/{project_id}/vpcs", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", createVpcRequest); HttpResponseMessage response = await DoHttpRequestAsync("POST", request); return(JsonUtils.DeSerialize <CreateVpcResponse>(response)); }
public static void CreateVPCEndpoint() { AmazonEC2Client client = new AmazonEC2Client(); CreateVpcRequest vpcRequest = new CreateVpcRequest("10.32.0.0/16"); CreateVpcResponse vpcResponse = client.CreateVpc(vpcRequest); Vpc vpc = vpcResponse.Vpc; CreateVpcEndpointRequest endpointRequest = new CreateVpcEndpointRequest(); endpointRequest.VpcId = vpc.VpcId; endpointRequest.ServiceName = "com.amazonaws.us-west-2.s3"; CreateVpcEndpointResponse cVpcErsp = client.CreateVpcEndpoint(endpointRequest); VpcEndpoint vpcEndPoint = cVpcErsp.VpcEndpoint; }
public async Task CreateVpc() { _context.Logger.WriteLine("CreateVpc"); var request = new CreateVpcRequest { CidrBlock = _cluster.VpcCidr, InstanceTenancy = Tenancy.Default }; var response = await _client.CreateVpcAsync(request); _context.Logger.WriteLine($"Vpc Created: {response.Vpc.CidrBlock} Id: {response.Vpc.VpcId}"); }
private static void CreateVpc(VpcClient client) { CreateVpcRequest req = new CreateVpcRequest { Body = new CreateVpcRequestBody { Vpc = new CreateVpcOption { Name = "test-vpc", Description = "Test vpc", Cidr = "192.168.0.0/24", EnterpriseProjectId = "0" } } }; try { var resp = client.CreateVpc(req); Console.WriteLine(resp.Vpc.Id); Console.WriteLine(resp.HttpStatusCode); foreach (var route in resp.Vpc.Routes) { Console.WriteLine(route.Destination); } } 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); } }
public void STSAssumeRoleCredentialWithPolicyTest() { if (GetRoleArn().Equals("FakeRoleArn")) { return; } var profile = DefaultProfile.GetProfile("cn-shanghai", GetBasicAccessKeyId(), GetBasicAccessKeySecret()); var basicCredential = new BasicCredentials(GetBasicAccessKeyId(), GetBasicAccessKeySecret()); var policy = "{ \"Version\": \"1\",\"Statement\": [{\"Effect\": \"Deny\",\"Action\": \"vpc:Create*\",\"Resource\": \"acs:vpc:cn-hangzhou:*:*\"}]}"; var provider = new STSAssumeRoleSessionCredentialsProvider(basicCredential, GetRoleArn(), policy, profile); var client = new DefaultAcsClient(profile, provider); var request = new CreateVpcRequest(); var exception = Assert.Throws <ClientException>(() => { var response = client.GetAcsResponse(request); }); Assert.Contains( "Forbidden.RAM : User not authorized to operate on the specified resource, or this API doesn't support RAM.", exception.Message); }