protected override void ProcessRecord() { base.ProcessRecord(); ListSubnetsRequest request; try { request = new ListSubnetsRequest { CompartmentId = CompartmentId, Limit = Limit, Page = Page, VcnId = VcnId, DisplayName = DisplayName, SortBy = SortBy, SortOrder = SortOrder, LifecycleState = LifecycleState }; IEnumerable <ListSubnetsResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.Items, true); } if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null) { WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources."); } FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
protected override void ProcessRecord() { base.ProcessRecord(); ListSubnetsRequest request; try { request = new ListSubnetsRequest { CompartmentId = CompartmentId, Limit = Limit, Page = Page, VcnId = VcnId, DisplayName = DisplayName, SortBy = SortBy, SortOrder = SortOrder, LifecycleState = LifecycleState }; IEnumerable <ListSubnetsResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.Items, true); } FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
private static void ListSubnets(VpcClient client) { ListSubnetsRequest req = new ListSubnetsRequest { Limit = 1, }; try { ListSubnetsResponse resp = client.ListSubnets(req); foreach (var subnet in resp.Subnets) { Console.WriteLine(subnet.Id); Console.WriteLine(subnet.Name); } } 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 async Task <ListSubnetsResponse> ListSubnetsAsync(ListSubnetsRequest listSubnetsRequest) { Dictionary <string, string> urlParam = new Dictionary <string, string>(); string urlPath = HttpUtils.AddUrlPath("/v1/{project_id}/subnets", urlParam); SdkRequest request = HttpUtils.InitSdkRequest(urlPath, listSubnetsRequest); HttpResponseMessage response = await DoHttpRequestAsync("GET", request); return(JsonUtils.DeSerialize <ListSubnetsResponse>(response)); }
/** * Gets Subnet info of a single uniquely named Subnet in the specified compartment. * * @param vcnClient the service client to use to query the Subnet. * @param compartmentId of the Subnet. * @param vcnId of the Subnet. * @return the Subnet. */ private static async Task <Subnet> GetUniqueSubnetByName(VirtualNetworkClient vcnClient, string compartmentId, string vcnId) { // Find the Subnet in a specific comparment var listSubnetsRequest = new ListSubnetsRequest { CompartmentId = compartmentId, VcnId = vcnId, DisplayName = SubnetName }; var listSubnetsResponse = await vcnClient.ListSubnets(listSubnetsRequest); if (listSubnetsResponse.Items.Count != 1) { logger.Error($"Could not find unique subnet with name: {SubnetName} in compartment: {compartmentId}"); return(null); } return(listSubnetsResponse.Items[0]); }
private static void VirtualNetworkConsoleDisplay(ClientConfig config) { // create client VirtualNetworkClient client = new VirtualNetworkClient(config) { Region = Regions.US_ASHBURN_1 }; Console.WriteLine("* List VCN------------------------"); var listVcnRequest = new ListVcnRequest() { // target compartment is root compartment(tenancy) CompartmentId = config.TenancyId, Limit = 50, SortOrder = SortOrder.ASC }; // get vcns var listVcn = client.ListVcn(listVcnRequest); listVcn.Items.ForEach(vcn => { Console.WriteLine(" |-" + vcn.DisplayName); Console.WriteLine(" | " + vcn.Id); // get dhcps in vcn var listDhcpRequest = new ListDhcpOptionsRequest() { // target is same compartment and VCN CompartmentId = vcn.CompartmentId, VcnId = vcn.Id, Limit = 50, SortOrder = SortOrder.ASC }; var listDhcp = client.ListDhcpOptions(listDhcpRequest); listDhcp.Items.ForEach(dhcp => { Console.WriteLine(" |\t|- * DHCP"); Console.WriteLine(" |\t|\t" + dhcp.DisplayName); Console.WriteLine(" |\t|\t" + dhcp.Id); }); // get RouteTable in vcn var listRouteTableRequest = new ListRouteTableRequest() { // target is same compartment and VCN CompartmentId = vcn.CompartmentId, VcnId = vcn.Id, Limit = 50, SortOrder = SortOrder.ASC }; var listRouteTable = client.ListRouteTableOptions(listRouteTableRequest); listRouteTable.Items.ForEach(rt => { Console.WriteLine(" |\t|- * RouteTable"); Console.WriteLine(" |\t|\t" + rt.DisplayName); Console.WriteLine(" |\t|\t" + rt.Id); // RouteRules rt.RouteRules.ForEach(rr => { if (!string.IsNullOrEmpty(rr.DestinationType)) { Console.WriteLine(" |\t|\t|- DestinationType:" + rr.DestinationType); } if (!string.IsNullOrEmpty(rr.CidrBlock)) { Console.WriteLine(" |\t|\t|\tCidrBlock:" + rr.CidrBlock); } if (!string.IsNullOrEmpty(rr.Destination)) { Console.WriteLine(" |\t|\t|\tDestination:" + rr.Destination); } if (!string.IsNullOrEmpty(rr.NetworkEntityId)) { Console.WriteLine(" |\t|\t|\tNetworkEntityId:" + rr.NetworkEntityId); } }); }); // get RouteTable in vcn var listSecurityListRequest = new ListSecurityListsRequest() { // target is same compartment and VCN CompartmentId = vcn.CompartmentId, VcnId = vcn.Id, Limit = 50, SortOrder = SortOrder.ASC }; var listSecurityList = client.ListSecurityLists(listSecurityListRequest); listSecurityList.Items.ForEach(sl => { Console.WriteLine(" |\t|- * SecurityList"); Console.WriteLine(" |\t|\t" + sl.DisplayName); Console.WriteLine(" |\t|\t" + sl.Id); Console.WriteLine(" |\t|\t" + sl.LifecycleState); }); // get Subnet in vcn var listSubnetRequest = new ListSubnetsRequest() { // target is same compartment and VCN CompartmentId = vcn.CompartmentId, VcnId = vcn.Id, Limit = 50, SortOrder = SortOrder.ASC }; var listSubnet = client.ListSubnets(listSubnetRequest); listSubnet.Items.ForEach(sl => { Console.WriteLine(" |\t|- * Subnet"); Console.WriteLine(" |\t|\t" + sl.DisplayName); Console.WriteLine(" |\t|\t" + sl.Id); Console.WriteLine(" |\t|\t" + sl.LifecycleState); }); // get InternetGateway in vcn var listIGRequest = new ListInternetGatewaysRequest() { // target is same compartment and VCN CompartmentId = vcn.CompartmentId, VcnId = vcn.Id, Limit = 50, SortOrder = SortOrder.ASC }; var listIG = client.ListInternetGateways(listIGRequest); listDhcp.Items.ForEach(ig => { Console.WriteLine(" |\t|- * InternetGateway"); Console.WriteLine(" |\t|\t" + ig.DisplayName); Console.WriteLine(" |\t|\t" + ig.Id); }); }); Console.WriteLine("* List DRG------------------------"); var identityClient = new IdentityClient(config) { Region = Regions.US_ASHBURN_1 }; var listCompartmentRequest = new ListCompartmentRequest() { CompartmentId = config.TenancyId, CompartmentIdInSubtree = true, AccessLevel = ListCompartmentRequest.AccessLevels.ACCESSIBLE }; var compartments = identityClient.ListCompartment(listCompartmentRequest).Items; foreach (var com in compartments) { var listDrgsRequest = new ListDrgsRequest() { CompartmentId = com.Id }; var drgs = client.ListDrgs(listDrgsRequest).Items; foreach (var drg in drgs) { Console.WriteLine($" |-name: {drg.DisplayName}"); Console.WriteLine($" | state: {drg.LifecycleState}"); Console.WriteLine($" | timeCreate: {drg.TimeCreated}"); Console.WriteLine($" | compartment: {com.Name}"); } } }