/// <summary> /// Creates a new enumerable which will iterate over the responses received from the ListBootVolumes operation. This enumerable /// will fetch more data from the server as needed. /// </summary> /// <param name="request">The request object containing the details to send</param> /// <param name="retryConfiguration">The configuration for retrying, may be null</param> /// <param name="cancellationToken">The cancellation token object</param> /// <returns>The enumerator, which supports a simple iteration over a collection of a specified type</returns> public IEnumerable <ListBootVolumesResponse> ListBootVolumesResponseEnumerator(ListBootVolumesRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { return(new Common.Utils.ResponseEnumerable <ListBootVolumesRequest, ListBootVolumesResponse>( response => response.OpcNextPage, input => { if (!string.IsNullOrEmpty(input)) { request.Page = input; } return request; }, request => client.ListBootVolumes(request, retryConfiguration, cancellationToken) )); }
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); }); }
private static async Task <BootVolume> createBootVolume(BlockstorageClient blockstorageClient, string compartmentId, AvailabilityDomain availabilityDomain, Image image) { string bootVolumeName = "oci-dotnet-sdk-example-boot-volume"; // find existing boot volume by image ListBootVolumesRequest listBootVolumesRequest = new ListBootVolumesRequest { AvailabilityDomain = availabilityDomain.Name, CompartmentId = compartmentId }; ListBootVolumesResponse listBootVolumesResponse = await blockstorageClient.ListBootVolumes(listBootVolumesRequest); List <BootVolume> bootVolumes = listBootVolumesResponse.Items; BootVolume existingBootVolume = null; foreach (BootVolume bootVol in bootVolumes) { if (BootVolume.LifecycleStateEnum.Available.Equals(bootVol.LifecycleState) && image.Id.Equals(bootVol.ImageId)) { existingBootVolume = bootVol; break; } } // create a new boot volume based on existing one logger.Info($"Found BootVolume: {existingBootVolume.Id}"); BootVolumeSourceDetails existingBootVolumeDetails = existingBootVolume.SourceDetails; BootVolumeSourceDetails bootVolumeSourceDetails = new BootVolumeSourceFromBootVolumeDetails { Id = existingBootVolume.Id }; CreateBootVolumeDetails createBootVolumeDetails = new CreateBootVolumeDetails { AvailabilityDomain = availabilityDomain.Name, CompartmentId = compartmentId, DisplayName = bootVolumeName, SourceDetails = bootVolumeSourceDetails }; CreateBootVolumeRequest createBootVolumeRequest = new CreateBootVolumeRequest { CreateBootVolumeDetails = createBootVolumeDetails }; CreateBootVolumeResponse createBootVolumeResponse = await blockstorageClient.CreateBootVolume(createBootVolumeRequest); logger.Info($"Provisioning new BootVolume: " + createBootVolumeResponse.BootVolume.Id); WaiterConfiguration waiterConfiguration = new WaiterConfiguration { MaxAttempts = 20, GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds }; // wait for boot volume to be ready GetBootVolumeRequest getBootVolumeRequest = new GetBootVolumeRequest { BootVolumeId = createBootVolumeResponse.BootVolume.Id }; GetBootVolumeResponse getBootVolumeResponse = blockstorageClient.Waiters.ForBootVolume(getBootVolumeRequest, waiterConfiguration, BootVolume.LifecycleStateEnum.Available).Execute(); BootVolume bootVolume = getBootVolumeResponse.BootVolume; logger.Info($"Provisioned BootVolume: {bootVolume.Id}"); return(bootVolume); }