private static async Task clearRouteRulesFromDefaultRouteTable(VirtualNetworkClient virtualNetworkClient, Vcn vcn)
        {
            List <RouteRule>        routeRules = new List <RouteRule>();
            UpdateRouteTableDetails updateRouteTableDetails = new UpdateRouteTableDetails {
                RouteRules = routeRules
            };
            UpdateRouteTableRequest updateRouteTableRequest = new UpdateRouteTableRequest
            {
                UpdateRouteTableDetails = updateRouteTableDetails,
                RtId = vcn.DefaultRouteTableId
            };
            await virtualNetworkClient.UpdateRouteTable(updateRouteTableRequest);

            WaiterConfiguration waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };

            GetRouteTableRequest getRouteTableRequest = new GetRouteTableRequest
            {
                RtId = vcn.DefaultRouteTableId
            };

            virtualNetworkClient.Waiters.ForRouteTable(getRouteTableRequest, waiterConfiguration, RouteTable.LifecycleStateEnum.Available).Execute();

            logger.Info($"Cleared route rules from route table: {vcn.DefaultRouteTableId}");
        }
Exemplo n.º 2
0
        /**
         * Configure the default RouteTable of the specified InternetGateway to ensure it
         * contains a single outbound route for all traffic.
         *
         * NB: You should restrict these routes further if you keep this piece of
         *     OCI infrastructure.
         *
         * @param vcnClient      the service client to use to query a RouteTable.
         * @param routeTableId   of the default route table associated with the VCN.
         * @param igId           of the RouteTable's associated InternetGateway.
         */
        private static async Task AddInternetGatewayToDefaultRouteTable(VirtualNetworkClient vcnClient, string routeTableId, string igId)
        {
            GetRouteTableRequest getRouteTableRequest = new GetRouteTableRequest
            {
                RtId = routeTableId
            };
            GetRouteTableResponse getRouteTableResponse = await vcnClient.GetRouteTable(getRouteTableRequest);

            var routeRules = getRouteTableResponse.RouteTable.RouteRules;

            logger.Info("Current Route Rules in Default Route Table");
            logger.Info("==========================================");
            routeRules.ForEach(delegate(RouteRule rule)
            {
                logger.Info($"rule: {rule.NetworkEntityId}");
            });

            RouteRule internetAccessRoute = new RouteRule
            {
                Destination     = "0.0.0.0/0",
                DestinationType = RouteRule.DestinationTypeEnum.CidrBlock,
                NetworkEntityId = igId
            };

            routeRules.Add(internetAccessRoute);
            UpdateRouteTableDetails updateRouteTableDetails = new UpdateRouteTableDetails
            {
                RouteRules  = routeRules,
                DisplayName = RouteTableName
            };
            UpdateRouteTableRequest updateRouteTableRequest = new UpdateRouteTableRequest
            {
                UpdateRouteTableDetails = updateRouteTableDetails,
                RtId = routeTableId
            };
            UpdateRouteTableResponse updateRouteTableResponse = await vcnClient.UpdateRouteTable(updateRouteTableRequest);

            getRouteTableResponse = vcnClient.Waiters.ForRouteTable(getRouteTableRequest, RouteTable.LifecycleStateEnum.Available).Execute();
            routeRules            = getRouteTableResponse.RouteTable.RouteRules;

            logger.Info("Updated Route Rules in Default Route Table");
            logger.Info("==========================================");
            routeRules.ForEach(delegate(RouteRule rule)
            {
                logger.Info($"rule: {rule.NetworkEntityId}\n");
            });
        }
Exemplo n.º 3
0
        private void HandleOutput(GetRouteTableRequest request)
        {
            var waiterConfig = new WaiterConfiguration
            {
                MaxAttempts           = MaxWaitAttempts,
                GetNextDelayInSeconds = (_) => WaitIntervalSeconds
            };

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

            case Default:
                response = client.GetRouteTable(request).GetAwaiter().GetResult();
                break;
            }
            WriteOutput(response, response.RouteTable);
        }
Exemplo n.º 4
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetRouteTableRequest request;

            try
            {
                request = new GetRouteTableRequest
                {
                    RtId = RtId
                };

                HandleOutput(request);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Exemplo n.º 5
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);
        }