private void HandleOutput(GetWorkRequestRequest request)
        {
            var waiterConfig = new WaiterConfiguration
            {
                MaxAttempts           = MaxWaitAttempts,
                GetNextDelayInSeconds = (_) => WaitIntervalSeconds
            };

            switch (ParameterSetName)
            {
            case StatusParamSet:
                response = client.Waiters.ForWorkRequest(request, waiterConfig, WaitForStatus).Execute();
                break;

            case Default:
                response = client.GetWorkRequest(request).GetAwaiter().GetResult();
                break;
            }
            WriteOutput(response, response.WorkRequest);
        }
Exemplo n.º 2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetWorkRequestRequest request;

            try
            {
                request = new GetWorkRequestRequest
                {
                    WorkRequestId = WorkRequestId
                };

                HandleOutput(request);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        private static async Task CreateListener(LoadBalancerClient lbClient, string loadBalancerId, RuleSet ruleSet, string backendSetName)
        {
            logger.Info($"Creating new listener: {ListenerName} with ruleset: {RuleSetName}");

            var ruleSetNames = new List <string>()
            {
                ruleSet.Name
            };
            var createListenerDetails = new CreateListenerDetails
            {
                Name = ListenerName,
                DefaultBackendSetName = backendSetName,
                Port         = ListenerPort,
                Protocol     = ListenerProtocol,
                RuleSetNames = ruleSetNames
            };
            var createListenerRequest = new CreateListenerRequest
            {
                CreateListenerDetails = createListenerDetails,
                LoadBalancerId        = loadBalancerId
            };
            var response = await lbClient.CreateListener(createListenerRequest);

            var waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            var getWorkRequestRequest = new GetWorkRequestRequest
            {
                WorkRequestId = response.OpcWorkRequestId
            };

            lbClient.Waiters.ForWorkRequest(getWorkRequestRequest, waiterConfiguration, WorkRequest.LifecycleStateEnum.Succeeded).Execute();

            logger.Info($"listener {ListenerName} is created");
        }
 /// <summary>
 /// Creates a waiter using default wait configuration.
 /// </summary>
 /// <param name="request">Request to send.</param>
 /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
 /// <returns>a new Oci.common.Waiter instance</returns>
 public Waiter <GetWorkRequestRequest, GetWorkRequestResponse> ForWorkRequest(GetWorkRequestRequest request, params WorkRequest.StatusEnum[] targetStates)
 {
     return(this.ForWorkRequest(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates));
 }
Exemplo n.º 5
0
        private static async Task <RuleSet> CreateRuleSet(LoadBalancerClient lbClient, string loadBalancerId)
        {
            logger.Info($"Creating new rule set: {RuleSetName}");

            List <Rule> rules = new List <Rule>();

            var addHttpRequestHeaderRule = new AddHttpRequestHeaderRule
            {
                Header = "someRequestHeader",
                Value  = "/example/1"
            };
            var extendHttpRequestHeaderValueRule = new ExtendHttpRequestHeaderValueRule
            {
                Header = "someRequestHeader",
                Suffix = "Some-static-suffix-value",
                Prefix = "Some-static-prefix-value"
            };
            var removeHttpResponseHeaderRule = new RemoveHttpResponseHeaderRule
            {
                Header = "someResponseHeader"
            };

            rules.Add(addHttpRequestHeaderRule);
            rules.Add(extendHttpRequestHeaderValueRule);
            rules.Add(removeHttpResponseHeaderRule);

            var createRuleSetDetails = new CreateRuleSetDetails
            {
                Name  = RuleSetName,
                Items = rules
            };
            var createRuleSetRequest = new CreateRuleSetRequest
            {
                CreateRuleSetDetails = createRuleSetDetails,
                LoadBalancerId       = loadBalancerId
            };
            var createRuleSetResponse = await lbClient.CreateRuleSet(createRuleSetRequest);

            var waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            var getWorkRequestRequest = new GetWorkRequestRequest
            {
                WorkRequestId = createRuleSetResponse.OpcWorkRequestId
            };

            // using waiters
            lbClient.Waiters.ForWorkRequest(getWorkRequestRequest, waiterConfiguration, WorkRequest.LifecycleStateEnum.Succeeded).Execute();

            logger.Info($"RuleSet: {RuleSetName} is created");
            var getRuleSetRequest = new GetRuleSetRequest
            {
                LoadBalancerId = loadBalancerId,
                RuleSetName    = RuleSetName
            };
            var getRuleSetResponse = await lbClient.GetRuleSet(getRuleSetRequest);

            return(getRuleSetResponse.RuleSet);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("+----------------------------------------+");
            Console.WriteLine("|                                        |");
            Console.WriteLine("|         OCISDK SessionExample          |");
            Console.WriteLine("|                                        |");
            Console.WriteLine("+----------------------------------------+");

            string configPath = ".oci/config";

            System.OperatingSystem os = System.Environment.OSVersion;
            // windows
            if (os.Platform == PlatformID.Win32NT)
            {
                string rootPath = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory());
                configPath = $"{rootPath}/{configPath}";
                if (!Directory.Exists($"{rootPath}/.oci"))
                {
                    Directory.CreateDirectory($"{rootPath}/.oci");
                }
            }
            else
            {
                configPath = $"/home/user/{configPath}";
            }

            string     profile;
            ConfigFile configReader;

            if (File.Exists(configPath))
            {
                Console.Write("Connection ProfileName(Empty Input is DEFAULT): ");
                profile = Console.ReadLine();
                if (string.IsNullOrEmpty(profile))
                {
                    profile = "Cloudii";
                }

                // load connection file
                configReader = ConfigFileReader.Parse(configPath, profile);
            }
            else
            {
                profile = "DEFAULT";

                // create connection file
                Console.WriteLine("Create connection settings to Oracle Cloud Infrastructure");

                Console.Write("TenancyId (Required): ");
                string tenancyId = OCIDInput();

                Console.Write("UserId (Required): ");
                string userId = OCIDInput();

                Console.Write("Fingerprint (Required): ");
                string fingerprint = KeyInput();

                Console.Write("PrivateKeyPath (Required): ");
                string privateKeyPath = KeyInput();

                Console.Write("PrivateKeyPassphrase: ");
                string privateKeyPassphrase = InputPassword();

                string testFileContentsMyProfile = $"[{profile}]\n" +
                                                   $"tenancy={tenancyId}\n" +
                                                   $"user={userId}\n" +
                                                   $"fingerprint={fingerprint}\n" +
                                                   $"key_file={privateKeyPath}\n" +
                                                   $"pass_phrase={privateKeyPassphrase}\n";

                File.WriteAllText(configPath, testFileContentsMyProfile);

                configReader = ConfigFileReader.Parse(configPath, profile);
            }

            // ClientConfig settings
            var         configSt = new ClientConfigStream();
            IOciSession session;

            using (var st = File.OpenText(configReader.Get("key_file")))
            {
                configSt = new ClientConfigStream
                {
                    TenancyId            = configReader.Get("tenancy"),
                    UserId               = configReader.Get("user"),
                    Fingerprint          = configReader.Get("fingerprint"),
                    PrivateKey           = st,
                    PrivateKeyPassphrase = configReader.Get("pass_phrase"),
                    AccountId            = configReader.Get("accountId"),
                    DomainName           = configReader.Get("domain_name"),
                    IdentityDomain       = configReader.Get("identity_domain"),
                    UserName             = configReader.Get("user_name"),
                    Password             = configReader.Get("password"),
                    HomeRegion           = configReader.Get("home_region")
                };

                session = new OciSession(configSt);
            }

            var comClient = session.GetCommercialClient();
            var listPurchaseEntitlementsRequest = new ListPurchaseEntitlementsRequest
            {
                CompartmentId = configSt.TenancyId
            };
            var purchase = comClient.ListPurchaseEntitlements(listPurchaseEntitlementsRequest);

            var getServiceEntitlementRegistrationsRequest = new ListServiceEntitlementRegistrationsRequest()
            {
                CompartmentId = configSt.TenancyId
            };
            var services = comClient.ListServiceEntitlementRegistrations(getServiceEntitlementRegistrationsRequest);

            var costClient = session.GetUsageCostsClient();
            var getSubscriptionInfoRequest = new GetSubscriptionInfoRequest
            {
                TenancyId = configSt.TenancyId
            };
            var subsc = costClient.GetSubscriptionInfo(getSubscriptionInfoRequest);

            // get Client
            var identityClient = session.GetIdentityClient();

            var getTenancyRequest = new GetTenancyRequest()
            {
                TenancyId = configSt.TenancyId
            };
            var getTenacy = identityClient.GetTenancy(getTenancyRequest);

            Console.WriteLine($"tenantName: {getTenacy.Tenancy.Name}");

            // get compute
            var computeClient = session.GetComputeClient();

            IDictionary <string, IDictionary <string, string> > tags = new Dictionary <string, IDictionary <string, string> >();

            tags.Add("CostTracking", new Dictionary <string, string> {
                { "cost-trakcerA", "aaaa" }
            });

            var dbClient = session.GetDatabaseClient();
            GetDbSystemRequest getDbSystemRequest = new GetDbSystemRequest()
            {
                DbSystemId = "ocid1.dbsystem.oc1.iad.abuwcljrbukbjzlameegvsn3u7qb3qcqvtcdvl74jxfth7xjsya7cxkdpibq"
            };
            var dbSystem = dbClient.GetDbSystem(getDbSystemRequest);

            UpdateDbSystemRequest updateDbSystemRequest = new UpdateDbSystemRequest()
            {
                DbSystemId            = "ocid1.dbsystem.oc1.iad.abuwcljrbukbjzlameegvsn3u7qb3qcqvtcdvl74jxfth7xjsya7cxkdpibq",
                UpdateDbSystemDetails = new OCISDK.Core.Database.Model.UpdateDbSystemDetails()
                {
                    DefinedTags = tags
                }
            };

            dbClient.UpdateDbSystem(updateDbSystemRequest);

            var listCompartmentRequest = new ListCompartmentRequest()
            {
                CompartmentId          = getTenacy.Tenancy.Id,
                CompartmentIdInSubtree = true
            };
            var cmparts = identityClient.ListCompartment(listCompartmentRequest);

            foreach (var com in cmparts.Items)
            {
                Console.WriteLine($"compartmentName: {com.Name}");

                var listInstanceRequest = new ListInstancesRequest()
                {
                    CompartmentId = com.Id,
                    Limit         = 10,
                    SortOrder     = SortOrder.ASC
                };
                var instances = computeClient.ListInstances(listInstanceRequest);
                foreach (var ins in instances.Items)
                {
                    Console.WriteLine($"rootCompartmentInstanceName: {ins.DisplayName}");


                    var workReqestClient        = session.GetWorkRequestClient();
                    var listWorkRequestsRequest = new ListWorkRequestsRequest()
                    {
                        CompartmentId = ins.CompartmentId,
                        ResourceId    = ins.Id
                    };
                    var workreqs = workReqestClient.ListWorkRequests(listWorkRequestsRequest);
                    foreach (var wq in workreqs.Items)
                    {
                        Console.WriteLine($"\tWorkRequest: {wq.OperationType}, state:{wq.Status}");

                        var getWorkRequestRequest = new GetWorkRequestRequest()
                        {
                            WorkRequestId = wq.Id
                        };
                        var gw = workReqestClient.GetWorkRequest(getWorkRequestRequest);
                        Console.WriteLine($"\taccepted:{gw.WorkRequest.TimeAccepted}, finished:{gw.WorkRequest.TimeFinished}");

                        var listWorkRequestErrorsRequest = new ListWorkRequestErrorsRequest()
                        {
                            WorkRequestId = wq.Id,
                            Limit         = 100,
                            SortOrder     = SortOrder.ASC
                        };
                        var wqErrors = workReqestClient.ListWorkRequestErrors(listWorkRequestErrorsRequest);
                        foreach (var error in wqErrors.Items)
                        {
                            Console.WriteLine($"\tErrorCode: {error.Code}, ErrorMessage:{error.Message}, ErrorTimeStamp:{error.Timestamp}");
                        }

                        var listWorkRequestLogsRequest = new ListWorkRequestLogsRequest()
                        {
                            WorkRequestId = wq.Id,
                            Limit         = 100,
                            SortOrder     = SortOrder.ASC
                        };
                        var wqLogs = workReqestClient.ListWorkRequestLogs(listWorkRequestLogsRequest);
                        foreach (var log in wqLogs.Items)
                        {
                            Console.WriteLine($"\tLogMessage:{log.Message}, LogTimeStamp:{log.Timestamp}");
                        }
                    }
                }
            }

            Console.WriteLine("Exit with key press...");
            Console.ReadLine();
        }