Exemple #1
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         client?.Dispose();
         int timeout = GetPreferredTimeout();
         WriteDebug($"Cmdlet Timeout : {timeout} milliseconds.");
         client = new BlockstorageClient(AuthProvider, new Oci.Common.ClientConfiguration
         {
             RetryConfiguration = retryConfig,
             TimeoutMillis      = timeout,
             ClientUserAgent    = PSUserAgent
         });
         string region = GetPreferredRegion();
         if (region != null)
         {
             WriteDebug("Choosing Region:" + region);
             client.SetRegion(region);
         }
         if (Endpoint != null)
         {
             WriteDebug("Choosing Endpoint:" + Endpoint);
             client.SetEndpoint(Endpoint);
         }
     }
     catch (Exception ex)
     {
         TerminatingErrorDuringExecution(ex);
     }
 }
Exemple #2
0
        private static async Task DeleteBootVolumeBackup(BlockstorageClient client, string bootVolumeBackupId)
        {
            DeleteBootVolumeBackupRequest deleteBootVolumeBackupRequest = new DeleteBootVolumeBackupRequest
            {
                BootVolumeBackupId = bootVolumeBackupId
            };

            // Delete the boot volume backup
            logger.Info($"Deleting backup with id {bootVolumeBackupId}");
            logger.Info("=============");
            await client.DeleteBootVolumeBackup(deleteBootVolumeBackupRequest);

            logger.Info("Backup deleted!");
        }
Exemple #3
0
        private static BootVolumeBackup.LifecycleStateEnum GetBootVolumeBackup(BlockstorageClient client, string bootVolumeBackupId)
        {
            GetBootVolumeBackupRequest getBootVolumeBackupRequest = new GetBootVolumeBackupRequest
            {
                BootVolumeBackupId = bootVolumeBackupId
            };

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

            GetBootVolumeBackupResponse getBootVolumeBackupResponse =
                client.Waiters.ForBootVolumeBackup(getBootVolumeBackupRequest,
                                                   waiterConfiguration, new BootVolumeBackup.LifecycleStateEnum[] { BootVolumeBackup.LifecycleStateEnum.Available }).Execute();

            return(getBootVolumeBackupResponse.BootVolumeBackup.LifecycleState.Value);
        }
Exemple #4
0
        private static async Task <string> CopyBootVolumeBackup(BlockstorageClient client, string bootVolumeBackupId, string destinationRegion)
        {
            CopyBootVolumeBackupRequest copyBootVolumeBackupRequest = new CopyBootVolumeBackupRequest
            {
                BootVolumeBackupId          = bootVolumeBackupId,
                CopyBootVolumeBackupDetails = new CopyBootVolumeBackupDetails
                {
                    DestinationRegion = destinationRegion,
                    DisplayName       = "Backup-copy-example"
                }
            };

            // Pass copyBootVolumeBackupRequest to client to create the boot volume backup
            logger.Info($"Creating backup at {destinationRegion}");
            logger.Info("=============");
            CopyBootVolumeBackupResponse copyBootVolumeBackupResponse = await client.CopyBootVolumeBackup(copyBootVolumeBackupRequest);

            return(copyBootVolumeBackupResponse.BootVolumeBackup.Id);
        }
Exemple #5
0
        public static async Task MainWaiter()
        {
            // Accepts profile name and creates a auth provider based on config file
            var    provider          = new ConfigFileAuthenticationDetailsProvider(OciConfigSourceProfileName);
            string bootVolumeBackup  = Environment.GetEnvironmentVariable("OCI_BOOT_VOLUME_BACKUP_ID");
            string destinationRegion = Environment.GetEnvironmentVariable("OCI_DESTINATION_REGION");

            // Create clients for the service to enable using its APIs
            var blockStorageClient = new BlockstorageClient(provider, new ClientConfiguration());

            try
            {
                // Copy Boot Volume backup
                var backupCopyId = await CopyBootVolumeBackup(blockStorageClient, bootVolumeBackup, destinationRegion);

                logger.Info($"Create backup copy with OCID:{backupCopyId}");

                // Create new client for making a retrying call for new backup copy in destination region
                var destinationProvider = new ConfigFileAuthenticationDetailsProvider(OciConfigDestinationProfileName);
                blockStorageClient = new BlockstorageClient(destinationProvider, new ClientConfiguration());
                var state = GetBootVolumeBackup(blockStorageClient, backupCopyId);

                logger.Info($"Successfully create backup copy with Lifecyle State:{state}");

                // Delete the backup copy for cleanup
                await DeleteBootVolumeBackup(blockStorageClient, backupCopyId);
            }
            catch (Exception e)
            {
                logger.Info($"Received exception due to {e.Message}");
            }
            finally
            {
                blockStorageClient.Dispose();
            }
        }
        public static void InstanceConsoleDisplay(ClientConfig config)
        {
            // create client
            ComputeClient computeClient = new ComputeClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            BlockstorageClient blockstorageClient = new BlockstorageClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            VirtualNetworkClient networkingClient = new VirtualNetworkClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            // get instanse list(RUNNING only)
            Console.WriteLine("* List Instance------------------------");
            var listInstanceRequest = new ListInstancesRequest()
            {
                // target compartment is root compartment(tenancy)
                CompartmentId  = computeClient.Config.TenancyId,
                Limit          = 50,
                LifecycleState = ListInstancesRequest.LifecycleStates.RUNNING,
                SortOrder      = SortOrder.ASC,
                SortBy         = ListInstancesRequest.SortByParam.TIMECREATED
            };
            // get instance
            var listInstance = computeClient.ListInstances(listInstanceRequest);

            listInstance.Items.ForEach(instance => {
                GetInstanceRequest getInstanceRequest = new GetInstanceRequest()
                {
                    InstanceId = instance.Id
                };
                var insDetail = computeClient.GetInstance(getInstanceRequest).Instance;
                Console.WriteLine(" |-" + insDetail.DisplayName);
                Console.WriteLine(" | id: " + insDetail.Id);
                Console.WriteLine(" | AD: " + insDetail.AvailabilityDomain);
                Console.WriteLine(" | shape: " + insDetail.Shape);
                Console.WriteLine(" | state: " + insDetail.LifecycleState);
                Console.WriteLine(" |\t|- * SourceDetails");
                Console.WriteLine(" |\t|\t type: " + insDetail.SourceDetails.SourceType);
                if ("image".Equals(insDetail.SourceDetails.SourceType))
                {
                    Console.WriteLine(" |\t|\t id: " + insDetail.SourceDetails.ImageId);

                    // get sourceDetail machine image
                    GetImageRequest getImageRequest = new GetImageRequest()
                    {
                        ImageId = insDetail.SourceDetails.ImageId
                    };
                    var machineimage = computeClient.GetImage(getImageRequest);
                    Console.WriteLine(" |\t|\t name: " + machineimage.Image.DisplayName);
                    Console.WriteLine(" |\t|\t sizeInMBs: " + machineimage.Image.SizeInMBs);
                }
                else
                {
                    Console.WriteLine(" |\t|\t id: " + insDetail.SourceDetails.BootVolumeId);

                    // get sourceDetail bootVolume
                    GetBootVolumeRequest getBootVolumeRequest = new GetBootVolumeRequest()
                    {
                        BootVolumeId = insDetail.SourceDetails.BootVolumeId
                    };
                    var bootvol = blockstorageClient.GetBootVolume(getBootVolumeRequest);
                    Console.WriteLine(" |\t|\t name: " + bootvol.BootVolume.DisplayName);
                    Console.WriteLine(" |\t|\t sizeInGBs: " + bootvol.BootVolume.SizeInGBs.Value);
                }

                // get instance atattch bootvolumes
                var bootvolumeAtattch = new ListBootVolumeAttachmentsRequest()
                {
                    InstanceId         = instance.Id,
                    CompartmentId      = instance.CompartmentId,
                    AvailabilityDomain = instance.AvailabilityDomain,
                    Limit = 50
                };
                var listBvAtattch = computeClient.ListBootVolumeAttachments(bootvolumeAtattch);
                listBvAtattch.Items.ForEach(bootVolAtt => {
                    Console.WriteLine(" |\t|- * BootVolume");

                    // get bootvolume
                    var getBootVolumeRequest = new GetBootVolumeRequest()
                    {
                        BootVolumeId = bootVolAtt.BootVolumeId
                    };
                    var bv = blockstorageClient.GetBootVolume(getBootVolumeRequest);
                    Console.WriteLine(" |\t|\t name:" + bv.BootVolume.DisplayName);
                    Console.WriteLine(" |\t|\t id:" + bv.BootVolume.Id);
                    Console.WriteLine(" |\t|\t state:" + bv.BootVolume.LifecycleState);
                    Console.WriteLine(" |\t|\t sizeInGBs:" + bv.BootVolume.SizeInGBs.Value);
                });

                // get instance atattch vnics
                var vnicAtattch = new ListVnicAttachmentsRequest()
                {
                    InstanceId         = instance.Id,
                    CompartmentId      = instance.CompartmentId,
                    AvailabilityDomain = instance.AvailabilityDomain,
                    Limit = 50
                };
                var listVnicAtattch = computeClient.ListVnicAttachments(vnicAtattch);
                listVnicAtattch.Items.ForEach(vnicA => {
                    Console.WriteLine(" |\t|- * Vnic");
                    GetVnicRequest getVnicRequest = new GetVnicRequest()
                    {
                        VnicId = vnicA.VnicId
                    };
                    var vnic = networkingClient.GetVnic(getVnicRequest);
                    Console.WriteLine(" |\t|\t name:" + vnic.Vnic.DisplayName);
                    Console.WriteLine(" |\t|\t id:" + vnic.Vnic.Id);
                    Console.WriteLine(" |\t|\t state:" + vnic.Vnic.LifecycleState);
                    Console.WriteLine(" |\t|\t privateIp:" + vnic.Vnic.PrivateIp);
                    Console.WriteLine(" |\t|\t publicIp:" + vnic.Vnic.PublicIp);
                });

                // get instance atattch volumes
                var volumeAtattch = new ListVolumeAttachmentsRequest()
                {
                    InstanceId         = instance.Id,
                    CompartmentId      = instance.CompartmentId,
                    AvailabilityDomain = instance.AvailabilityDomain,
                    Limit = 50
                };
                var listVolAtattch = computeClient.ListVolumeAttachments(volumeAtattch);
                listVolAtattch.Items.ForEach(volAtt => {
                    Console.WriteLine(" |\t|- * Volume");

                    // get bootvolume
                    var getVolumeRequest = new GetVolumeRequest()
                    {
                        VolumeId = volAtt.VolumeId
                    };
                    var vol = blockstorageClient.GetVolume(getVolumeRequest);
                    Console.WriteLine(" |\t|\t name:" + vol.Volume.DisplayName);
                    Console.WriteLine(" |\t|\t id:" + vol.Volume.Id);
                    Console.WriteLine(" |\t|\t state:" + vol.Volume.LifecycleState);
                    Console.WriteLine(" |\t|\t sizeInGBs:" + vol.Volume.SizeInGBs.Value);
                });
            });

            // get list Machine Images
            Console.WriteLine();
            Console.WriteLine("* List Image------------------------ max 10");
            var listImagesRequest = new ListImagesRequest()
            {
                // target compartment is root compartment(tenancy)
                CompartmentId  = config.TenancyId,
                Limit          = 10,
                LifecycleState = ListImagesRequest.LifecycleStates.AVAILABLE,
                SortOrder      = SortOrder.ASC,
                SortBy         = ListImagesRequest.SortByParam.TIMECREATED
            };
            // get instance
            var listImage = computeClient.ListImages(listImagesRequest);

            listImage.Items.ForEach(image =>
            {
                Console.WriteLine(" |-" + image.DisplayName);
                Console.WriteLine(" | id: " + image.Id);
                Console.WriteLine(" | os: " + image.OperatingSystem);
                Console.WriteLine(" | os ver: " + image.OperatingSystemVersion);
                Console.WriteLine(" | lifecycle: " + image.LifecycleState);
                Console.WriteLine(" | sizeInMBs: " + image.SizeInMBs);
                Console.WriteLine(" | BaseMachineId: " + image.BaseImageId);
            });
        }
Exemple #7
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);
            });
        }
 public BlockstorageWaiters(BlockstorageClient client, Oci.WorkrequestsService.WorkRequestClient workRequestClient)
 {
     this.client            = client;
     this.workRequestClient = workRequestClient;
 }
        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);
        }
        public static async Task MainInstance()
        {
            logger.Info("Starting example");

            var provider      = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
            var compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");

            var identityClient       = new IdentityClient(provider);
            var computeClient        = new ComputeClient(provider, new ClientConfiguration());
            var virtualNetworkClient = new VirtualNetworkClient(provider);
            var blockStorageClient   = new BlockstorageClient(provider);
            var networkCidrBlock     = "10.0.1.0/24";

            LaunchInstanceDetails launchInstanceDetails = null;
            Instance          instance               = null;
            BootVolume        bootVolume             = null;
            Instance          instanceFromBootVolume = null;
            Vcn               vcn               = null;
            Subnet            subnet            = null;
            CreateVnicDetails createVnicDetails = null;
            InternetGateway   internetGateway   = null;

            AvailabilityDomain availablityDomain = await getAvailabilityDomains(identityClient, compartmentId);

            logger.Info($"availability domain is {availablityDomain.Name}");

            Shape shape = await getShape(computeClient, compartmentId, availablityDomain);

            if (shape == null)
            {
                logger.Error($"No Shapes available in the availability domain: {availablityDomain.Name}");
                return;
            }
            logger.Info($"shape is {shape.ShapeProp}");
            Image image = await getImage(computeClient, compartmentId, shape);

            try
            {
                vcn = await createVcn(virtualNetworkClient, compartmentId, networkCidrBlock);

                // The Internet Gateway with updated Route Rules will enable the instance to connect to the public
                // internet. If it is not desired, remove the following two lines below that create an internet
                // gateway and add that internet gateway to the VCN route table.
                internetGateway = await createInternalGateway(virtualNetworkClient, compartmentId, vcn);
                await addInternetGatewayToDefaultRouteTable(virtualNetworkClient, vcn, internetGateway);

                subnet = await createSubnet(virtualNetworkClient, compartmentId, availablityDomain, networkCidrBlock, vcn);

                createVnicDetails = new CreateVnicDetails {
                    SubnetId = subnet.Id
                };

                launchInstanceDetails = new LaunchInstanceDetails
                {
                    AvailabilityDomain = availablityDomain.Name,
                    CompartmentId      = compartmentId,
                    Shape             = shape.ShapeProp,
                    CreateVnicDetails = createVnicDetails,
                    ImageId           = image.Id
                };

                instance = await createInstance(computeClient, launchInstanceDetails);
                await printInstance(computeClient, virtualNetworkClient, instance);

                logger.Info("Instance is being created via boot volume ...");
                // This boot volume is created based on the boot volume of previous instance which needs to be running
                bootVolume = await createBootVolume(blockStorageClient, compartmentId, availablityDomain, image);

                launchInstanceDetails  = createLaunchInstanceDetailsFromBootVolume(launchInstanceDetails, bootVolume);
                instanceFromBootVolume = await createInstance(computeClient, launchInstanceDetails);
                await printInstance(computeClient, virtualNetworkClient, instanceFromBootVolume);
            }
            catch (Exception e)
            {
                logger.Error($"Failed to call LaunchInstance API: {e.Message}");
            }
            finally
            {
                logger.Info("cleaning up resources");
                if (instanceFromBootVolume != null)
                {
                    await terminateInstance(computeClient, instanceFromBootVolume);
                }

                if (instance != null)
                {
                    await terminateInstance(computeClient, instance);
                }

                if (internetGateway != null)
                {
                    await clearRouteRulesFromDefaultRouteTable(virtualNetworkClient, vcn);
                    await deleteInternetGateway(virtualNetworkClient, internetGateway);
                }

                if (subnet != null)
                {
                    await deleteSubnet(virtualNetworkClient, subnet);
                }

                if (vcn != null)
                {
                    await deleteVcn(virtualNetworkClient, vcn);
                }

                identityClient.Dispose();
                computeClient.Dispose();
                virtualNetworkClient.Dispose();
                blockStorageClient.Dispose();

                logger.Info("End example");
            }
        }
Exemple #11
0
 public BlockstoragePaginators(BlockstorageClient client)
 {
     this.client = client;
 }