/**
         * Creates a VCN and waits for it to become available to use.
         *
         * @param vcnClient the service client to use to create the VCN
         * @param compartmentId the OCID of the compartment where the VCN will be created
         *
         * @return the created VCN
         */
        private static async Task <Vcn> CreateVcn(VirtualNetworkClient virtualNetworkClient, string compartmentId)
        {
            logger.Info("creating vcn");

            CreateVcnDetails createVcnDetails = new CreateVcnDetails
            {
                CidrBlock     = CidrBlock,
                CompartmentId = compartmentId,
                DisplayName   = VcnDisplayName
            };
            CreateVcnRequest createVcnRequest = new CreateVcnRequest
            {
                CreateVcnDetails = createVcnDetails
            };
            CreateVcnResponse createVcnResponse = await virtualNetworkClient.CreateVcn(createVcnRequest);

            GetVcnRequest getVcnRequest = new GetVcnRequest
            {
                VcnId = createVcnResponse.Vcn.Id
            };
            GetVcnResponse getVcnResponse = virtualNetworkClient.Waiters.ForVcn(getVcnRequest, Vcn.LifecycleStateEnum.Available).Execute();
            Vcn            vcn            = getVcnResponse.Vcn;

            logger.Info($"Created vcn: {vcn.Id} and state is {vcn.LifecycleState}");
            return(vcn);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CreateVcnRequest request;

            try
            {
                request = new CreateVcnRequest
                {
                    CreateVcnDetails = CreateVcnDetails,
                    OpcRetryToken    = OpcRetryToken
                };

                response = client.CreateVcn(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Vcn);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
예제 #3
0
        private static void CreateVirtualNetwork(ClientConfig config)
        {
            // warning
            Console.WriteLine("Continuing this example, a new VCN will be created. The compartments are root fixed.");

            Console.Write("Are you sure you want to continue? (Y/N)");

            var presskey = Console.ReadKey();

            if (presskey.KeyChar != 'Y' && presskey.KeyChar != 'y')
            {
                Console.WriteLine("Exit CreateVirtualNetworkExample");
                return;
            }
            Console.WriteLine();

            // create client
            VirtualNetworkClient client = new VirtualNetworkClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            // input VCN details
            var createVcnDetails = new CreateVcnDetails();

            Console.WriteLine("Create new VertualCloudNetwork(VCN)");
            Console.Write("VCN name: ");
            createVcnDetails.DisplayName = Console.ReadLine();
            Console.Write("CidrBlock: ");
            createVcnDetails.CidrBlock = Console.ReadLine();

            createVcnDetails.CompartmentId = config.TenancyId;

            var createVcnRequest = new CreateVcnRequest()
            {
                CreateVcnDetails = createVcnDetails
            };

            var newVCNRes = client.CreateVcn(createVcnRequest);
            var newVCN    = newVCNRes.Vcn;

            Console.WriteLine("* Create new VCN--------------------------");
            Console.WriteLine(" name: " + newVCN.DisplayName);
            Console.WriteLine(" id: " + newVCN.Id);
            Console.WriteLine(" DNSlabel: " + newVCN.DnsLabel);
            Console.WriteLine(" domainName: " + newVCN.VcnDomainName);
            Console.WriteLine(" timeCreate: " + newVCN.TimeCreated);

            //get created default DHCP
            Console.WriteLine(" DefaultDHCP: ");
            Console.WriteLine("\t| id: " + newVCN.DefaultSecurityListId);
            var getDhcpRequest = new GetDhcpRequest()
            {
                DhcpId = newVCN.DefaultDhcpOptionsId
            };
            var defaultDHCP = client.GetDhcp(getDhcpRequest).DhcpOptions;

            Console.WriteLine("\t| name: " + defaultDHCP.DisplayName);
            Console.WriteLine("\t| id: " + defaultDHCP.Id);
            Console.WriteLine("\t| state: " + defaultDHCP.LifecycleState);
            Console.WriteLine("\t| timeCreate: " + defaultDHCP.TimeCreated);

            // get created default seculityList
            Console.WriteLine(" DefaultSeculityList: ");
            Console.WriteLine("\t| id: " + newVCN.DefaultSecurityListId);
            var getSecurityListRequest = new GetSecurityListRequest()
            {
                SecurityListId = newVCN.DefaultSecurityListId
            };
            var defaultSL = client.GetSecurityList(getSecurityListRequest).SecurityList;

            Console.WriteLine("\t| name: " + defaultSL.DisplayName);
            Console.WriteLine("\t| id: " + defaultSL.Id);
            Console.WriteLine("\t| state: " + defaultSL.LifecycleState);
            Console.WriteLine("\t| timeCreate: " + defaultSL.TimeCreated);

            // get craeted default
            Console.WriteLine(" DefaultRouteTableId: ");
            Console.WriteLine("\t| id: " + newVCN.DefaultRouteTableId);
            var getRouteTableIdRequest = new GetRouteTableRequest()
            {
                RtId = newVCN.DefaultRouteTableId
            };
            var defaultRT = client.GetRouteTable(getRouteTableIdRequest).RouteTable;

            Console.WriteLine("\t| name: " + defaultRT.DisplayName);
            Console.WriteLine("\t| id: " + defaultRT.Id);
            Console.WriteLine("\t| state: " + defaultRT.LifecycleState);
            Console.WriteLine("\t| timeCreate: " + defaultRT.TimeCreated);
        }