def create_vcn(): cidr_block = getConfig("VCN", "cidr_block") vcn_client = oci.core.VirtualNetworkClient(config) vcn_details = CreateVcnDetails() vcn_details.cidr_block = cidr_block vcn_details.display_name = "".join( random.sample(string.ascii_letters + string.digits, 8)) vcn_details.compartment_id = getConfig("VCN", "compartment_id") vcn_result = vcn_client.create_vcn(vcn_details) get_vcn_response = oci.wait_until(vcn_client, vcn_client.get_vcn(vcn_result.data.id), 'lifecycle_state', 'AVAILABLE') print('Created VCN:{}'.format(get_vcn_response.data.id)) return get_vcn_response
def create_vcn(): global virtual_network_client_composite_ops global vcn_id # setup create vcn details create_vcn_details = CreateVcnDetails() create_vcn_details.cidr_block = '10.0.0.0/16' create_vcn_details.compartment_id = src_compartment_id create_vcn_details.display_name = 'test_change_service_gateway' # create vcn response = virtual_network_client_composite_ops.create_vcn_and_wait_for_state(create_vcn_details, wait_for_states=[Vcn.LIFECYCLE_STATE_AVAILABLE]) vcn_id = response.data.id info("VCN ID : %s" % vcn_id)
# Creating a VCN in Python demo script import oci config = oci.config.from_file() identity_client = oci.identity.IdentityClient(config) tenancy_id = config["tenancy"] compartment = identity_client.list_compartments(tenancy_id) print(compartment.data) # change the assignment below to match your POCCOMP1 OCID compartment_id = "ocid1.compartment.oc1..aaaaaaaal7yma7iwruue2altr2cmgns4svg57relimneoixu7t5hefneolxa" virtual_network_client = oci.core.virtual_network_client.VirtualNetworkClient( config) # prepare OCI request by assigning the desired VCN parameters from oci.core.models import CreateVcnDetails request = CreateVcnDetails() request.compartment_id = compartment_id request.display_name = "pythonvcn" request.dns_label = "pythonvcn" request.cidr_block = "172.0.0.0/16" vcn = virtual_network_client.create_vcn(request)