private static async Task <AvailabilityDomain> getAvailabilityDomains(IdentityClient identityClient, string compartmentId)
        {
            ListAvailabilityDomainsRequest listAvailabilityDomainsRequest = new ListAvailabilityDomainsRequest
            {
                CompartmentId = compartmentId
            };
            ListAvailabilityDomainsResponse listAvailabilityDomainsResponse = await identityClient.ListAvailabilityDomains(listAvailabilityDomainsRequest);

            return(listAvailabilityDomainsResponse.Items[0]);
        }
        /**
         * Retrieves a list of availability domains in a compartment.
         *
         * @param identityClient the client to use to retrieve the availability domains
         * @param compartmentId the OCID of the compartment whose availability domains we're listing
         *
         * @return a availability domain
         */
        private static async Task <AvailabilityDomain> GetAvailabilityDomain(IdentityClient identityClient, string compartmentId)
        {
            ListAvailabilityDomainsRequest listAvailabilityDomainsRequest = new ListAvailabilityDomainsRequest
            {
                CompartmentId = compartmentId
            };
            ListAvailabilityDomainsResponse listAvailabilityDomainsResponse = await identityClient.ListAvailabilityDomains(listAvailabilityDomainsRequest);

            foreach (AvailabilityDomain ad in listAvailabilityDomainsResponse.Items)
            {
                if (ad.Name.Equals("Iocq:PHX-AD-2"))
                {
                    return(ad);
                }
            }
            return(listAvailabilityDomainsResponse.Items[0]);
        }
Exemplo n.º 3
0
        public static void BlockStoragesConsoleDisplay(ClientConfig config)
        {
            // create client
            BlockstorageClient blockstorageClient = new BlockstorageClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            // get list BootVolumes
            IdentityClient identityClient = new IdentityClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };
            // get ADs
            ListAvailabilityDomainsRequest listADsRequest = new ListAvailabilityDomainsRequest()
            {
                CompartmentId = config.TenancyId
            };
            var ads = identityClient.ListAvailabilityDomains(listADsRequest);

            ads.Items.ForEach(ad => {
                Console.WriteLine("* List BootVolumes-------------------" + ad.Name);
                var listBootVolumesRequest = new ListBootVolumesRequest()
                {
                    // target compartment is root compartment(tenancy)
                    CompartmentId      = config.TenancyId,
                    AvailabilityDomain = ad.Name,
                    Limit = 10,
                };
                var listBV = blockstorageClient.ListBootVolumes(listBootVolumesRequest);
                listBV.Items.ForEach(bv =>
                {
                    Console.WriteLine(" |-" + bv.DisplayName);
                    Console.WriteLine(" | id: " + bv.Id);
                    Console.WriteLine(" | lifecycle: " + bv.LifecycleState);
                    Console.WriteLine(" | sizeInGBs: " + bv.SizeInGBs);
                    Console.WriteLine(" | VolumeGroupId: " + bv.VolumeGroupId);
                });

                Console.WriteLine("* List VolumeGroups-------------------" + ad.Name);
                var listVolumeGroupsRequest = new ListVolumeGroupsRequest()
                {
                    // target compartment is root compartment(tenancy)
                    CompartmentId      = config.TenancyId,
                    AvailabilityDomain = ad.Name,
                    Limit = 10,
                };
                var listVolGroups = blockstorageClient.ListVolumeGroups(listVolumeGroupsRequest);
                listVolGroups.Items.ForEach(vg =>
                {
                    Console.WriteLine(" |-" + vg.DisplayName);
                    Console.WriteLine(" | id: " + vg.Id);
                    Console.WriteLine(" | lifecycle: " + vg.LifecycleState);
                    Console.WriteLine(" | sizeInGBs: " + vg.SizeInGBs);
                });
            });

            ListCompartmentRequest listCompartmentRequest = new ListCompartmentRequest()
            {
                CompartmentId          = config.TenancyId,
                CompartmentIdInSubtree = true,
                AccessLevel            = ListCompartmentRequest.AccessLevels.ACCESSIBLE
            };
            var listCom = identityClient.ListCompartment(listCompartmentRequest);

            Console.WriteLine("* List BootVolumeBackup-------------------");
            listCom.Items.ForEach(com => {
                ListBootVolumeBackupsRequest listBootVolumeBackupsRequest = new ListBootVolumeBackupsRequest()
                {
                    CompartmentId = com.Id,
                    SortOrder     = SortOrder.ASC
                };
                var listBootVolumeBackup = blockstorageClient.ListBootVolumeBackups(listBootVolumeBackupsRequest);
                listBootVolumeBackup.Items.ForEach(bvB =>
                {
                    Console.WriteLine(" |-" + bvB.DisplayName);
                    Console.WriteLine(" | id: " + bvB.Id);
                    Console.WriteLine(" | lifecycle: " + bvB.LifecycleState);
                    Console.WriteLine(" | type: " + bvB.Type);
                });
            });

            Console.WriteLine("* List VolumeBackup-------------------");
            listCom.Items.ForEach(com => {
                ListVolumeBackupsRequest listVolumeBackupsRequest = new ListVolumeBackupsRequest()
                {
                    CompartmentId = com.Id
                };
                var listVolumeBackup = blockstorageClient.ListVolumeBackups(listVolumeBackupsRequest);
                listVolumeBackup.Items.ForEach(vB =>
                {
                    Console.WriteLine(" |-" + vB.DisplayName);
                    Console.WriteLine(" | id: " + vB.Id);
                    Console.WriteLine(" | lifecycle: " + vB.LifecycleState);
                    Console.WriteLine(" | type: " + vB.Type);
                });
            });

            Console.WriteLine("* List Volume-------------------");
            listCom.Items.ForEach(com => {
                ListVolumesRequest listVolumesRequest = new ListVolumesRequest()
                {
                    CompartmentId = com.Id
                };
                var listVolume = blockstorageClient.ListVolumes(listVolumesRequest);
                listVolume.Items.ForEach(vol =>
                {
                    Console.WriteLine(" |-" + vol.DisplayName);
                    Console.WriteLine(" | id: " + vol.Id);
                    Console.WriteLine(" | lifecycle: " + vol.LifecycleState);
                    Console.WriteLine(" | sizeInGBs: " + vol.SizeInGBs);

                    var getVolumeKmsKeyRequest = new GetVolumeKmsKeyRequest()
                    {
                        VolumeId = vol.Id
                    };
                    try
                    {
                        var kms = blockstorageClient.GetVolumeKmsKey(getVolumeKmsKeyRequest);
                        Console.WriteLine(" | kms: " + kms.VolumeKmsKey.KmsKeyId);
                    }
                    catch (WebException we)
                    {
                        if (we.Status.Equals(WebExceptionStatus.ProtocolError))
                        {
                            var code = ((HttpWebResponse)we.Response).StatusCode;
                            if (code != HttpStatusCode.NotFound)
                            {
                                throw we;
                            }
                        }
                    }
                });
            });

            Console.WriteLine("* List VolumeGroupBackUp-------------------");
            listCom.Items.ForEach(com => {
                var listVolumeGroupBackupsRequest = new ListVolumeGroupBackupsRequest()
                {
                    CompartmentId = com.Id
                };
                var listVolumeGroupB = blockstorageClient.ListVolumeGroupBackups(listVolumeGroupBackupsRequest);
                listVolumeGroupB.Items.ForEach(vol =>
                {
                    Console.WriteLine(" |-" + vol.DisplayName);
                    Console.WriteLine(" | id: " + vol.Id);
                    Console.WriteLine(" | lifecycle: " + vol.LifecycleState);
                    Console.WriteLine(" | sizeInGBs: " + vol.SizeInGBs);
                });
            });

            Console.WriteLine("* List VolumeBackUpPolicy-------------------");
            var listVolumeBackupPoliciesRequest = new ListVolumeBackupPoliciesRequest()
            {
                Limit = 10
            };
            var backupPolicies = blockstorageClient.ListVolumeBackupPolicies(listVolumeBackupPoliciesRequest);

            backupPolicies.Items.ForEach(policy =>
            {
                Console.WriteLine(" |-" + policy.DisplayName);
                Console.WriteLine(" | id: " + policy.Id);
                Console.WriteLine(" | timeCreated: " + policy.TimeCreated);
            });
        }
        /**
         * Retrieves a list of availability domains in a compartment.
         *
         * @param identityClient the client to use to retrieve the availability domains
         * @param compartmentId the OCID of the compartment whose availability domains we're listing
         *
         * @return first one in the list of availability domains
         */
        private static async Task <IdentityModels.AvailabilityDomain> GetAvailabilityDomain(IdentityClient identityClient, string compartmentId)
        {
            IdentityRequests.ListAvailabilityDomainsRequest listAvailabilityDomainsRequest = new IdentityRequests.ListAvailabilityDomainsRequest
            {
                CompartmentId = compartmentId
            };
            IdentityResponses.ListAvailabilityDomainsResponse listAvailabilityDomainsResponse = await identityClient.ListAvailabilityDomains(listAvailabilityDomainsRequest);

            return(listAvailabilityDomainsResponse.Items[0]);
        }
Exemplo n.º 5
0
        public static void CompartmentConsoleDisplay(ClientConfig config)
        {
            IdentityClient identityClient = new IdentityClient(config)
            {
                Region = config.HomeRegion
            };

            Console.WriteLine("* GetTenacy------------------------");
            GetTenancyRequest getTenancyRequest = new GetTenancyRequest()
            {
                TenancyId = identityClient.Config.TenancyId
            };
            var getTenacy = identityClient.GetTenancy(getTenancyRequest);

            Console.WriteLine(" name:" + getTenacy.Tenancy.Name + ",");
            Console.WriteLine(" id:" + getTenacy.Tenancy.Id + ",");
            Console.WriteLine(" description:" + getTenacy.Tenancy.Description + ",");
            Console.WriteLine(" homeregion:" + config.GetRegionName(getTenacy.Tenancy.HomeRegionKey) + ",");
            // tagNamespaces get in tetancy(root compartment)
            Console.WriteLine(" tagNamespaces:");
            var listTagNamespacesRequest = new ListTagNamespacesRequest()
            {
                CompartmentId = getTenacy.Tenancy.Id,
                Limit         = 50
            };
            var listTagNs = identityClient.ListTagNamespaces(listTagNamespacesRequest);

            listTagNs.Items.ForEach(tagNs => {
                Console.WriteLine("\t|- name: " + tagNs.Name);
                Console.WriteLine("\t|  id: " + tagNs.Id);
                Console.WriteLine("\t|  description: " + tagNs.Description);
                //tag list
                var listTagsRequest = new ListTagsRequest()
                {
                    TagNamespaceId = tagNs.Id,
                    Limit          = 50
                };
                var listTags = identityClient.ListTags(listTagsRequest);
                listTags.Items.ForEach(tag => {
                    Console.WriteLine("\t|\t|- * " + tag.Name);
                    Console.WriteLine("\t|\t| id: " + tag.Id);
                    Console.WriteLine("\t|\t| costTracking: " + tag.IsCostTracking);
                });
            });

            // tagDefaults get in tetancy(root compartment)
            Console.WriteLine(" tagDefaults:");
            var listTagsDefaultRequest = new ListTagDefaultsRequest()
            {
                CompartmentId = getTenacy.Tenancy.Id,
                Limit         = 50
            };
            var listDefaultTags = identityClient.ListTagDefaults(listTagsDefaultRequest);

            listDefaultTags.Items.ForEach(tag => {
                Console.WriteLine("\t|- DefaultTags");
                Console.WriteLine("\t|  id: " + tag.Id);
                Console.WriteLine("\t|  tagDefinitionName: " + tag.TagDefinitionName);
                Console.WriteLine("\t|  tagNamespaceId: " + tag.TagNamespaceId);
                Console.WriteLine("\t|  tagDefinitionId: " + tag.TagDefinitionId);
                Console.WriteLine("\t|  lifecycleState: " + tag.LifecycleState);
            });

            var listCostTrackingTagsRequest = new ListCostTrackingTagsRequest()
            {
                CompartmentId = getTenacy.Tenancy.Id,
                Limit         = 100
            };
            var listCostTrackingTags = identityClient.ListCostTrackingTags(listCostTrackingTagsRequest);

            listCostTrackingTags.Items.ForEach(tag => {
                Console.WriteLine("\t|- CostTackingTags");
                Console.WriteLine("\t|  id: " + tag.Id);
                Console.WriteLine("\t|  isCostTracking: " + tag.IsCostTracking);
                Console.WriteLine("\t|  tagNamespaceId: " + tag.TagNamespaceId);
                Console.WriteLine("\t|  tagNamespaceName: " + tag.TagNamespaceName);
                Console.WriteLine("\t|  name: " + tag.Name);
            });

            Console.WriteLine();
            Console.WriteLine("* ListRegions------------------------");
            var listRegion = identityClient.ListRegions();

            listRegion.Items.ForEach(r => {
                Console.WriteLine("\tname: " + r.Name);
                Console.WriteLine("\tkey: " + r.Key);
            });

            Console.WriteLine("* ListRegionsSubscriptions------------------------");
            var listRegionSubscriptionsRequest = new ListRegionSubscriptionsRequest()
            {
                TenancyId = getTenacy.Tenancy.Id,
            };
            var listRegionSubscriptions = identityClient.ListRegionSubscriptions(listRegionSubscriptionsRequest);

            listRegionSubscriptions.Items.ForEach(r => {
                Console.WriteLine("\tname: " + r.RegionKey);
                Console.WriteLine("\tkey: " + r.RegionName);
                Console.WriteLine("\tstatus: " + r.Status);
                Console.WriteLine("\thome: " + r.IsHomeRegion);
            });

            Console.WriteLine();
            Console.WriteLine("* ListAvailabilityDomain------------------------");
            var listAvailabilityDomainRequest = new ListAvailabilityDomainsRequest()
            {
                CompartmentId = getTenacy.Tenancy.Id
            };
            var listAD = identityClient.ListAvailabilityDomains(listAvailabilityDomainRequest);

            listAD.Items.ForEach(ad => {
                Console.WriteLine("\tname: " + ad.Name);
                Console.WriteLine("\tid: " + ad.Id);
            });

            Console.WriteLine();
            Console.WriteLine("* ListCompartment------------------------");
            var listCompartmenRequest = new ListCompartmentRequest()
            {
                CompartmentId          = getTenacy.Tenancy.Id,
                CompartmentIdInSubtree = true,
                AccessLevel            = ListCompartmentRequest.AccessLevels.ACCESSIBLE,
                Limit = 10
            };
            var listCompartment = identityClient.ListCompartment(listCompartmenRequest);

            listCompartment.Items.ForEach(comp => {
                // compartment detail get
                var getCompartmentRequest = new GetCompartmentRequest()
                {
                    CompartmentId = comp.Id
                };
                var getCompartment = identityClient.GetCompartment(getCompartmentRequest);
                Console.WriteLine("\t|- name: " + getCompartment.Compartment.Name);
                Console.WriteLine("\t|\t id: " + getCompartment.Compartment.Id);
                Console.WriteLine("\t|\t lifecycleState: " + getCompartment.Compartment.LifecycleState);
                Console.WriteLine("\t|\t timeCreated: " + getCompartment.Compartment.TimeCreated);
                Console.WriteLine("\t|\t inactiveStatus: " + getCompartment.Compartment.InactiveStatus);
                var path = GetCompartmetPath(identityClient, getCompartment.Compartment.Id);
                Console.WriteLine("\t|\t path: " + path);
                getCompartmentRequest = new GetCompartmentRequest()
                {
                    CompartmentId = getCompartment.Compartment.CompartmentId
                };
                getCompartment = identityClient.GetCompartment(getCompartmentRequest);
                Console.WriteLine("\t|\t parent: " + getCompartment.Compartment.Name);

                // tagNamespaces get in compartment
                Console.WriteLine("\t|\t tgaNamespaces:");
                listTagNamespacesRequest = new ListTagNamespacesRequest()
                {
                    CompartmentId = comp.Id,
                    Limit         = 50
                };
                listTagNs = identityClient.ListTagNamespaces(listTagNamespacesRequest);
                listTagNs.Items.ForEach(tagNs => {
                    Console.WriteLine("\t|\t |- name: " + tagNs.Name);
                    Console.WriteLine("\t|\t |  id: " + tagNs.Id);
                    Console.WriteLine("\t|\t |  description: " + tagNs.Description);
                    Console.WriteLine("\t|\t |  timeCreated: " + tagNs.TimeCreated);
                });
            });
        }