private static async Task <Subnet> createSubnet(VirtualNetworkClient virtualNetworkClient, string compartmentId, AvailabilityDomain availabilityDomain, string networkCidrBlock, Vcn vcn)
        {
            string subnetName = "oci-dotnet-sdk-example-subnet";

            // In order to launch instances in a regional subnet, build this CreateSubnetDetails with
            // the field availablityDomain set to null.
            CreateSubnetDetails createSubnetDetails = new CreateSubnetDetails
            {
                AvailabilityDomain = availabilityDomain.Name,
                CompartmentId      = compartmentId,
                DisplayName        = subnetName,
                CidrBlock          = networkCidrBlock,
                VcnId        = vcn.Id,
                RouteTableId = vcn.DefaultRouteTableId
            };
            CreateSubnetRequest createSubnetRequest = new CreateSubnetRequest {
                CreateSubnetDetails = createSubnetDetails
            };
            CreateSubnetResponse createSubnetResponse = await virtualNetworkClient.CreateSubnet(createSubnetRequest);

            GetSubnetRequest getSubnetRequest = new GetSubnetRequest {
                SubnetId = createSubnetResponse.Subnet.Id
            };
            GetSubnetResponse getSubnetResponse = virtualNetworkClient.Waiters.ForSubnet(getSubnetRequest, Subnet.LifecycleStateEnum.Available).Execute();
            Subnet            subnet            = getSubnetResponse.Subnet;

            logger.Info($"Created Subnet: {subnet.Id}");
            return(subnet);
        }
        /**
         * Creates subnets in a VCN and waits for the subnets to become available to use.
         *
         * @param vcnClient the service client to use to create the subnet
         * @param compartmentId the OCID of the compartment which owns the VCN
         * @param availabilityDomain the availability domain where the subnet will be created
         * @param cidrBlock the cidr block used to create subnet
         * @param vcnId the ID of the VCN which will own the subnet
         * @param subnetName the subnet that will be created
         *
         * @return the created subnets
         *
         */
        private static async Task <List <Subnet> > CreateSubnet(VirtualNetworkClient virtualNetworkClient, string compartmentId, IdentityModels.AvailabilityDomain availabilityDomain, string vcnId)
        {
            List <Subnet> subnets = new List <Subnet>();

            for (int i = 0; i < 2; i++)
            {
                CreateSubnetDetails createSubnetDetails = new CreateSubnetDetails
                {
                    AvailabilityDomain = availabilityDomain.Name,
                    CompartmentId      = compartmentId,
                    DisplayName        = SubnetDisplayNames[i],
                    CidrBlock          = SubnetCidrBlocks[i],
                    VcnId = vcnId
                };
                CreateSubnetRequest createSubnetRequest = new CreateSubnetRequest {
                    CreateSubnetDetails = createSubnetDetails
                };
                CreateSubnetResponse createSubnetResponse = await virtualNetworkClient.CreateSubnet(createSubnetRequest);

                GetSubnetRequest getSubnetRequest = new GetSubnetRequest {
                    SubnetId = createSubnetResponse.Subnet.Id
                };
                GetSubnetResponse getSubnetResponse = virtualNetworkClient.Waiters.ForSubnet(getSubnetRequest, Subnet.LifecycleStateEnum.Available).Execute();
                Subnet            subnet            = getSubnetResponse.Subnet;

                logger.Info($"Created Subnet: {subnet.Id}");
                subnets.Add(getSubnetResponse.Subnet);
            }
            return(subnets);
        }
Exemplo n.º 3
0
        /**
         * Creates a subnet in a VCN and waits for the subnet to become available to use.
         *
         * @param vcnClient the service client to use to create the subnet.
         * @param compartmentId the OCID of the compartment which owns the VCN.
         * @param vcnId the ID of the VCN which will own the subnet.
         * @param availabilityDomain the availability domain where the subnet will be created.
         * @return the created subnet.
         */
        private static async Task <Subnet> CreateSubnet(VirtualNetworkClient vcnClient, string compartmentId, string availabilityDomain, string vcnId)
        {
            logger.Info("Creating subnet");

            CreateSubnetDetails createSubnetDetails = new CreateSubnetDetails
            {
                AvailabilityDomain = availabilityDomain,
                CompartmentId      = compartmentId,
                DisplayName        = SubnetName,
                CidrBlock          = SubnetCidrBlock,
                VcnId = vcnId
            };
            CreateSubnetRequest createSubnetRequest = new CreateSubnetRequest {
                CreateSubnetDetails = createSubnetDetails
            };
            CreateSubnetResponse createSubnetResponse = await vcnClient.CreateSubnet(createSubnetRequest);

            GetSubnetRequest getSubnetRequest = new GetSubnetRequest {
                SubnetId = createSubnetResponse.Subnet.Id
            };
            GetSubnetResponse getSubnetResponse = vcnClient.Waiters.ForSubnet(getSubnetRequest, Subnet.LifecycleStateEnum.Available).Execute();
            Subnet            subnet            = getSubnetResponse.Subnet;

            logger.Info($"Created Subnet: {subnet.Id}");
            return(subnet);
        }
        private void HandleOutput(GetSubnetRequest request)
        {
            var waiterConfig = new WaiterConfiguration
            {
                MaxAttempts           = MaxWaitAttempts,
                GetNextDelayInSeconds = (_) => WaitIntervalSeconds
            };

            switch (ParameterSetName)
            {
            case LifecycleStateParamSet:
                response = client.Waiters.ForSubnet(request, waiterConfig, WaitForLifecycleState).Execute();
                break;

            case Default:
                response = client.GetSubnet(request).GetAwaiter().GetResult();
                break;
            }
            WriteOutput(response, response.Subnet);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetSubnetRequest request;

            try
            {
                request = new GetSubnetRequest
                {
                    SubnetId = SubnetId
                };

                HandleOutput(request);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }