/** * Creates a VCN and waits for it to become available to use. * * @param vcnClient the service client to use to create the VCN * @param compartmentId the OCID of the compartment where the VCN will be created * * @return the created VCN */ private static async Task <Vcn> CreateVcn(VirtualNetworkClient virtualNetworkClient, string compartmentId) { logger.Info("creating vcn"); CreateVcnDetails createVcnDetails = new CreateVcnDetails { CidrBlock = CidrBlock, CompartmentId = compartmentId, DisplayName = VcnDisplayName }; CreateVcnRequest createVcnRequest = new CreateVcnRequest { CreateVcnDetails = createVcnDetails }; CreateVcnResponse createVcnResponse = await virtualNetworkClient.CreateVcn(createVcnRequest); GetVcnRequest getVcnRequest = new GetVcnRequest { VcnId = createVcnResponse.Vcn.Id }; GetVcnResponse getVcnResponse = virtualNetworkClient.Waiters.ForVcn(getVcnRequest, Vcn.LifecycleStateEnum.Available).Execute(); Vcn vcn = getVcnResponse.Vcn; logger.Info($"Created vcn: {vcn.Id} and state is {vcn.LifecycleState}"); return(vcn); }
/** * Deletes a VCN and waits for it to be deleted. * * @param vcnClient the service client to use to delete the VCN. * @param vcn the VCN to delete. */ private static async Task DeleteVcn(VirtualNetworkClient vcnClient, Vcn vcn) { DeleteVcnRequest deleteVcnRequest = new DeleteVcnRequest { VcnId = vcn.Id }; await vcnClient.DeleteVcn(deleteVcnRequest); logger.Info($"Deleted Vcn: {vcn.Id}"); }
/** * Create all the OCI and Fn resources required to invoke a function. * * @param provider the OCI credentials provider. * @param compartmentId the compartment in which to create the required * resources. * @param image a valid OCI Registry image for the function. */ private static async Task SetUpResources(IBasicAuthenticationDetailsProvider provider, string compartmentId, string image) { logger.Info("Setting up resources"); var identityClient = new IdentityClient(provider); var vcnClient = new VirtualNetworkClient(provider); var fnManagementClient = new FunctionsManagementClient(provider); Vcn vcn = null; Subnet subnet = null; InternetGateway internetGateway = null; try { AvailabilityDomain availablityDomain = await GetAvailabilityDomain(identityClient, compartmentId); logger.Info($"availability domain is {availablityDomain.Name}"); vcn = await CreateVcn(vcnClient, compartmentId); internetGateway = await CreateInternalGateway(vcnClient, compartmentId, vcn); await AddInternetGatewayToDefaultRouteTable(vcnClient, vcn.DefaultRouteTableId, internetGateway.Id); subnet = await CreateSubnet(vcnClient, compartmentId, availablityDomain.Name, vcn.Id); var subnetIds = new List <string>() { subnet.Id }; Application app = await CreateApplication(fnManagementClient, compartmentId, subnetIds); long memoryInMBs = 128L; int timeoutInSeconds = 30; Function fn = await CreateFunction(fnManagementClient, app.Id, image, memoryInMBs, timeoutInSeconds); } catch (Exception e) { logger.Error($"failed to setup resources: {e}"); } finally { fnManagementClient.Dispose(); vcnClient.Dispose(); identityClient.Dispose(); } }
public static async Task MainContainerEngine(string[] args) { logger.Info("Starting example"); string compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID"); var provider = new ConfigFileAuthenticationDetailsProvider(OciConfigProfileName); var containerEngineClient = new ContainerEngineClient(provider); var vcnClient = new VirtualNetworkClient(provider); var identityClient = new IdentityClient(provider); Vcn vcn = null; List <Subnet> subnets = null; Cluster cluster = null; try { IdentityModels.AvailabilityDomain availablityDomain = await GetAvailabilityDomain(identityClient, compartmentId); logger.Info($"availability domain is {availablityDomain.Name}"); vcn = await CreateVcn(vcnClient, compartmentId); subnets = await CreateSubnet(vcnClient, compartmentId, availablityDomain, vcn.Id); //Create a Container Engine Cluster List <string> subnetIds = new List <string>(); foreach (Subnet subnet in subnets) { subnetIds.Add(subnet.Id); } var kubernetesVersion = await GetKubernetesVersion(containerEngineClient); cluster = await CreateCluster(containerEngineClient, vcn.Id, subnetIds, kubernetesVersion, compartmentId); // Update the container engine cluster await UpdateCluster(containerEngineClient, cluster.Id, ClusterNewDisplayName); } catch (Exception e) { logger.Error($"Failed to create container engine cluster: {e}"); } finally { logger.Info("Cleaning up..."); if (cluster != null) { await DeleteCluster(containerEngineClient, cluster.Id); } for (int i = 0; i < 2; i++) { if (subnets[i] != null) { await DeleteSubnet(vcnClient, subnets[i]); } } if (vcn != null) { await DeleteVcn(vcnClient, vcn); } containerEngineClient.Dispose(); vcnClient.Dispose(); identityClient.Dispose(); } logger.Info("End example"); }
public static async Task MainContainerEngineNodePool() { logger.Info("Starting example"); string compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID"); var provider = new ConfigFileAuthenticationDetailsProvider(OciConfigProfileName); var containerEngineClient = new ContainerEngineClient(provider); var vcnClient = new VirtualNetworkClient(provider); var identityClient = new IdentityClient(provider); Vcn vcn = null; List <Subnet> subnets = null; List <string> lbSubnetIds = new List <string>(); List <string> poolSubnetIds = new List <string>(); Cluster cluster = null; NodePool nodePool = null; try { List <IdentityModels.AvailabilityDomain> availablityDomains = await GetAvailabilityDomains(identityClient, compartmentId); vcn = await CreateVcn(vcnClient, compartmentId); subnets = await CreateSubnets(vcnClient, compartmentId, vcn); lbSubnetIds.Add(subnets[0].Id); poolSubnetIds.Add(subnets[1].Id); var kubernetesVersion = await GetKubernetesVersion(containerEngineClient); cluster = await CreateCluster(containerEngineClient, vcn.Id, lbSubnetIds, kubernetesVersion, compartmentId); // Add node pool in the cluster KeyValue keyValue = new KeyValue { Key = "key1", Value = "value1" }; List <KeyValue> initialNodeLabels = new List <KeyValue> { keyValue }; List <NodePoolPlacementConfigDetails> nodePoolPlacementConfigDetails = new List <NodePoolPlacementConfigDetails>(); foreach (var availabilityDomain in availablityDomains) { nodePoolPlacementConfigDetails.Add(new NodePoolPlacementConfigDetails { AvailabilityDomain = availabilityDomain.Name, SubnetId = poolSubnetIds[0] }); } ; var createNodePoolNodeConfigDetails = new CreateNodePoolNodeConfigDetails { Size = availablityDomains.Count, PlacementConfigs = nodePoolPlacementConfigDetails }; nodePool = await CreateNodePool(containerEngineClient, compartmentId, cluster.Id, NodePoolDisplayName, kubernetesVersion, NodeImageName, NodeShape, initialNodeLabels, createNodePoolNodeConfigDetails); logger.Info("Created node pool"); // Update the node pool await UpdateNodePool(containerEngineClient, nodePool.Id, NewNodePoolDisplayName); } catch (Exception e) { logger.Error($"Failed to create container engine cluster: {e}"); } finally { logger.Info("Cleaning up..."); if (nodePool != null) { await DeleteNodePool(containerEngineClient, nodePool.Id); } if (cluster != null) { await DeleteCluster(containerEngineClient, cluster.Id); } for (int i = 0; i < 2; i++) { if (subnets[i] != null) { await DeleteSubnet(vcnClient, subnets[i]); } } if (vcn != null) { await DeleteVcn(vcnClient, vcn); } containerEngineClient.Dispose(); vcnClient.Dispose(); identityClient.Dispose(); } logger.Info("End example"); }
/** * Creates subnets in a VCN and waits for the subnets to become available to use. * * @param vcnClient the service client to use to create the subnet * @param compartmentId the OCID of the compartment which owns the VCN * @param vcnId the ID of the VCN which will own the subnet * @param subnetName the subnet that will be created * @param cidrBlock the cidr block used to create subnet * * @return the created subnets */ private static async Task <List <Subnet> > CreateSubnets(VirtualNetworkClient virtualNetworkClient, string compartmentId, Vcn vcn) { List <Subnet> subnets = new List <Subnet>(); for (int i = 0; i < 2; i++) { CreateSubnetDetails createSubnetDetails = new CreateSubnetDetails { CompartmentId = compartmentId, DisplayName = SubnetDisplayNames[i], CidrBlock = SubnetCidrBlocks[i], VcnId = vcn.Id, }; CreateSubnetRequest createSubnetRequest = new CreateSubnetRequest { CreateSubnetDetails = createSubnetDetails }; CreateSubnetResponse createSubnetResponse = await virtualNetworkClient.CreateSubnet(createSubnetRequest); GetSubnetRequest getSubnetRequest = new GetSubnetRequest { SubnetId = createSubnetResponse.Subnet.Id }; GetSubnetResponse getSubnetResponse = virtualNetworkClient.Waiters.ForSubnet(getSubnetRequest, Subnet.LifecycleStateEnum.Available).Execute(); Subnet subnet = getSubnetResponse.Subnet; logger.Info($"Created Subnet: {subnet.Id}"); subnets.Add(getSubnetResponse.Subnet); } return(subnets); }
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}"); }
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"); } }
private static async Task <Subnet> createSubnet(VirtualNetworkClient virtualNetworkClient, string compartmentId, AvailabilityDomain availabilityDomain, string networkCidrBlock, Vcn vcn) { string subnetName = "oci-dotnet-sdk-example-subnet"; // In order to launch instances in a regional subnet, build this CreateSubnetDetails with // the field availablityDomain set to null. CreateSubnetDetails createSubnetDetails = new CreateSubnetDetails { AvailabilityDomain = availabilityDomain.Name, CompartmentId = compartmentId, DisplayName = subnetName, CidrBlock = networkCidrBlock, VcnId = vcn.Id, RouteTableId = vcn.DefaultRouteTableId }; CreateSubnetRequest createSubnetRequest = new CreateSubnetRequest { CreateSubnetDetails = createSubnetDetails }; CreateSubnetResponse createSubnetResponse = await virtualNetworkClient.CreateSubnet(createSubnetRequest); GetSubnetRequest getSubnetRequest = new GetSubnetRequest { SubnetId = createSubnetResponse.Subnet.Id }; GetSubnetResponse getSubnetResponse = virtualNetworkClient.Waiters.ForSubnet(getSubnetRequest, Subnet.LifecycleStateEnum.Available).Execute(); Subnet subnet = getSubnetResponse.Subnet; logger.Info($"Created Subnet: {subnet.Id}"); return(subnet); }
private static async Task addInternetGatewayToDefaultRouteTable(VirtualNetworkClient virtualNetworkClient, Vcn vcn, InternetGateway internetGateway) { GetRouteTableRequest getRouteTableRequest = new GetRouteTableRequest { RtId = vcn.DefaultRouteTableId }; GetRouteTableResponse getRouteTableResponse = await virtualNetworkClient.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 = internetGateway.Id }; routeRules.Add(internetAccessRoute); UpdateRouteTableDetails updateRouteTableDetails = new UpdateRouteTableDetails { RouteRules = routeRules }; UpdateRouteTableRequest updateRouteTableRequest = new UpdateRouteTableRequest { UpdateRouteTableDetails = updateRouteTableDetails, RtId = vcn.DefaultRouteTableId }; UpdateRouteTableResponse updateRouteTableResponse = await virtualNetworkClient.UpdateRouteTable(updateRouteTableRequest); getRouteTableResponse = virtualNetworkClient.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"); }); }
private static async Task <InternetGateway> createInternalGateway(VirtualNetworkClient virtualNetworkClient, string compartmentId, Vcn vcn) { string internetGatewayName = "oci-dotent-sdk-example-internet-gateway"; CreateInternetGatewayDetails createInternetGatewayDetails = new CreateInternetGatewayDetails { CompartmentId = compartmentId, DisplayName = internetGatewayName, IsEnabled = true, VcnId = vcn.Id }; CreateInternetGatewayRequest createInternetGatewayRequest = new CreateInternetGatewayRequest { CreateInternetGatewayDetails = createInternetGatewayDetails }; CreateInternetGatewayResponse createInternetGatewayResponse = await virtualNetworkClient.CreateInternetGateway(createInternetGatewayRequest); GetInternetGatewayRequest getInternetGatewayRequest = new GetInternetGatewayRequest { IgId = createInternetGatewayResponse.InternetGateway.Id }; GetInternetGatewayResponse getInternetGatewayResponse = virtualNetworkClient.Waiters.ForInternetGateway(getInternetGatewayRequest, InternetGateway.LifecycleStateEnum.Available).Execute(); InternetGateway internetGateway = getInternetGatewayResponse.InternetGateway; logger.Info($"Created internet gateway: {internetGateway.Id} and state is {internetGateway.LifecycleState}"); return(internetGateway); }
static async Task MainDatabase(string[] args) { string compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID"); string adminPassword = Environment.GetEnvironmentVariable("PASSWORD"); logger.Info("Starting example"); // Accepts profile name and creates a auth provider based on config file var provider = new ConfigFileAuthenticationDetailsProvider(OciConfigProfileName); var identityClient = new IdentityClient(provider); var virtualNetworkClient = new VirtualNetworkClient(provider); var databaseClient = new DatabaseClient(provider); var networkCidrBlock = "10.0.1.0/24"; Vcn vcn = null; Subnet subnet = null; string dbSystemId = null; AvailabilityDomain availablityDomain = await getAvailabilityDomains(identityClient, compartmentId); logger.Info($"availability domain is {availablityDomain.Name}"); try { vcn = await createVcn(virtualNetworkClient, compartmentId, networkCidrBlock); subnet = await createSubnet(virtualNetworkClient, compartmentId, availablityDomain, networkCidrBlock, vcn); logger.Info("Launching Database...."); LaunchDbSystemDetails launchDbSystemDetails = new LaunchDbSystemDetails { AvailabilityDomain = availablityDomain.Name, CompartmentId = compartmentId, CpuCoreCount = 4, Shape = "BM.DenseIO2.52", SshPublicKeys = new List <string> { "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyyA8wePstPC69PeuHFtOwyTecByonsHFAjHbVnZ+h0dpomvLZxUtbknNj3+c7MPYKqKBOx9gUKV/diR/mIDqsb405MlrI1kmNR9zbFGYAAwIH/Gxt0Lv5ffwaqsz7cECHBbMojQGEz3IH3twEvDfF6cu5p00QfP0MSmEi/eB+W+h30NGdqLJCziLDlp409jAfXbQm/4Yx7apLvEmkaYSrb5f/pfvYv1FEV1tS8/J7DgdHUAWo6gyGUUSZJgsyHcuJT7v9Tf0xwiFWOWL9WsWXa9fCKqTeYnYJhHlqfinZRnT/+jkz0OZ7YmXo6j4Hyms3RCOqenIX1W6gnIn+eQIkw== This is the key's comment" }, SubnetId = subnet.Id, DatabaseEdition = LaunchDbSystemDetails.DatabaseEditionEnum.EnterpriseEdition, DisplayName = "OCI DotNet SDK database", Hostname = "oci-dotnetsdk-host", Domain = "testdomain", DbHome = new CreateDbHomeDetails { DbVersion = "12.1.0.2", DisplayName = "Example DB Home", Database = new CreateDatabaseDetails { DbName = "dotnetdb", AdminPassword = adminPassword } } }; LaunchDbSystemRequest launchDbSystemRequest = new LaunchDbSystemRequest { LaunchDbSystemDetails = launchDbSystemDetails }; LaunchDbSystemResponse launchDbSystemResponse = await databaseClient.LaunchDbSystem(launchDbSystemRequest); logger.Info($"Database ID: {launchDbSystemResponse.DbSystem.Id} and Database display name: {launchDbSystemResponse.DbSystem.DisplayName}"); logger.Info("Waiting for Database to come to available state...."); GetDbSystemRequest getDbSystemRequest = new GetDbSystemRequest { DbSystemId = launchDbSystemResponse.DbSystem.Id }; WaiterConfiguration waiterConfiguration = new WaiterConfiguration { MaxAttempts = 20, GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds }; GetDbSystemResponse getDbSystemResponse = databaseClient.Waiters.ForDbSystem( getDbSystemRequest, waiterConfiguration, DbSystem.LifecycleStateEnum.Available).Execute(); logger.Info("Database is available"); logger.Info($"Database ID: {getDbSystemResponse.DbSystem.Id} and Database display name: {getDbSystemResponse.DbSystem.DisplayName}"); dbSystemId = getDbSystemResponse.DbSystem.Id; } catch (Exception e) { logger.Error($"failed to launch DbSystem: {e}"); } finally { if (dbSystemId != null) { await terminateDbSystem(databaseClient, dbSystemId); } if (subnet != null) { await deleteSubnet(virtualNetworkClient, subnet); } if (vcn != null) { await deleteVcn(virtualNetworkClient, vcn); } identityClient.Dispose(); virtualNetworkClient.Dispose(); databaseClient.Dispose(); logger.Info("End example"); } }
public static async Task MainFileStorage() { logger.Info("Starting example"); var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT"); var compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID"); var fileSystemDisplayName = Environment.GetEnvironmentVariable("FILE_SYSTEM_DISPLAY_NAME"); var identityClient = new IdentityClient(provider); var fileStorageClient = new FileStorageClient(provider); var vcnClient = new VirtualNetworkClient(provider); Vcn vcn = null; Subnet subnet = null; FileSystem fileSystem = null; MountTarget mountTarget = null; Export export = null; Snapshot snapshot = null; try { var availablityDomain = await GetAvailabilityDomain(identityClient, compartmentId); logger.Info($"availability domain is {availablityDomain.Name}"); // A VCN and subnet is required to create a mount target vcn = await CreateVcn(vcnClient, compartmentId); subnet = await CreateSubnet(vcnClient, compartmentId, availablityDomain, vcn); fileSystem = await CreateFileSystem(fileStorageClient, compartmentId, fileSystemDisplayName, availablityDomain); mountTarget = await CreateMountTarget(fileStorageClient, vcnClient, compartmentId, fileSystemDisplayName + "-mnt", availablityDomain, subnet); await GetExportSet(fileStorageClient, mountTarget.ExportSetId); export = await CreateExport(fileStorageClient, fileSystem.Id, mountTarget.ExportSetId); ListExports(fileStorageClient, compartmentId, fileSystem, mountTarget); snapshot = await CreateSnapshot(fileStorageClient, fileSystem); } catch (Exception e) { logger.Error($"Failed to mount file system: {e}"); } finally { logger.Info("cleaning resources...."); if (snapshot != null) { await DeleteSnapshot(fileStorageClient, snapshot); } if (export != null) { await DeleteExport(fileStorageClient, export); } if (mountTarget != null) { await DeleteMountTarget(fileStorageClient, mountTarget); } if (fileSystem != null) { await DeleteFileSystem(fileStorageClient, fileSystem); } if (subnet != null) { await DeleteSubnet(vcnClient, subnet); } if (vcn != null) { await DeleteVcn(vcnClient, vcn); } identityClient.Dispose(); fileStorageClient.Dispose(); vcnClient.Dispose(); logger.Info("End example"); } }
/** * Creates a subnet in a VCN and waits for the subnet to become available to use. * * @param virtualNetworkClient the service client to use to create the subnet * @param compartmentId the OCID of the compartment which owns the VCN * @param availabilityDomain the availability domain where the subnet will be created * @param vcn the VCN which will own the subnet * * @return the created subnet */ private static async Task <Subnet> CreateSubnet(VirtualNetworkClient virtualNetworkClient, string compartmentId, AvailabilityDomain availabilityDomain, Vcn vcn) { logger.Info("Creating subnet"); CreateSubnetDetails createSubnetDetails = new CreateSubnetDetails { AvailabilityDomain = availabilityDomain.Name, CompartmentId = compartmentId, DisplayName = SubnetDisplayName, CidrBlock = CidrBlock, VcnId = vcn.Id, RouteTableId = vcn.DefaultRouteTableId }; CreateSubnetRequest createSubnetRequest = new CreateSubnetRequest { CreateSubnetDetails = createSubnetDetails }; CreateSubnetResponse createSubnetResponse = await virtualNetworkClient.CreateSubnet(createSubnetRequest); GetSubnetRequest getSubnetRequest = new GetSubnetRequest { SubnetId = createSubnetResponse.Subnet.Id }; GetSubnetResponse getSubnetResponse = virtualNetworkClient.Waiters.ForSubnet(getSubnetRequest, Subnet.LifecycleStateEnum.Available).Execute(); Subnet subnet = getSubnetResponse.Subnet; logger.Info($"Created Subnet: {subnet.Id}"); return(subnet); }