def check_create_vcn(client, composite_client, vcn): matched_vcn_ocid = None compartment_ocid = get_compartment_ocid_from_name(identity_client, config["tenancy"], vcn["compartment_name"]) compartment_exist_check = check_if_compartment_exist( identity_client, compartment_ocid) compartment_available_check = check_if_compartment_is_active( identity_client, compartment_ocid) if compartment_exist_check and compartment_available_check: print_decorator( "COMPARTMENT EXIST AND IS IN AVAILABLE LIFECYCLE STATE") vcn_name_check = check_vcn_name_match(client, compartment_ocid, vcn["name"]) vcn_cidr_check = check_vcn_cidr_match(client, compartment_ocid, vcn["cidr_block"]) if vcn_name_check: matched_vcn_ocid = get_vcn_match_ocid(client, compartment_ocid, vcn["name"]) if vcn_cidr_check: matched_vcn_ocid = get_vcn_match_ocid(client, compartment_ocid, vcn_cidr=vcn["cidr_block"]) if matched_vcn_ocid is not None: vcn_available_check = check_vcn_ocid_is_available( client, compartment_ocid, matched_vcn_ocid) if vcn_available_check: return matched_vcn_ocid elif matched_vcn_ocid is None: return create_vcn(client, composite_client, vcn)
def check_create_lpg(client, composite_client, vcn, lpg, vcn_ocid): matched_lpg_ocid = None compartment_ocid = get_compartment_ocid_from_name(identity_client, config["tenancy"], lpg["compartment_name"]) compartment_exist_check = check_if_compartment_exist( identity_client, compartment_ocid) compartment_available_check = check_if_compartment_is_active( identity_client, compartment_ocid) vcn_exist = check_vcn_exist_by_ocid(client, compartment_ocid, vcn_ocid) vcn_available_state = check_vcn_ocid_is_available(client, compartment_ocid, vcn_ocid) lpg_name_check = check_if_lpg_exist_by_name(client, compartment_ocid, vcn_ocid, lpg["name"]) if compartment_exist_check and compartment_available_check: print_decorator( "COMPARTMENT EXIST AND IS IN AVAILABLE LIFECYCLE STATE") if vcn_exist and vcn_available_state and lpg_name_check: matched_lpg_ocid = get_lpg_ocid_by_lpg_name( client, compartment_ocid, vcn_ocid, lpg["name"]) lpg_available_state = check_if_lpg_is_available( client, matched_lpg_ocid, compartment_ocid) if matched_lpg_ocid is not None and lpg_available_state: print_decorator("LPG ALREADY EXIST") return matched_lpg_ocid elif matched_lpg_ocid is None: matched_lpg_ocid = create_local_peering_gateway( composite_client, lpg["name"], compartment_ocid, vcn_ocid) return matched_lpg_ocid
def check_create_subnet(client, subnet_details, vcn_ocid): matched_subnet_ocid = None compartment_ocid = get_compartment_ocid_from_name( identity_client, config["tenancy"], subnet_details["compartment_name"]) compartment_exist_check = check_if_compartment_exist( identity_client, compartment_ocid) compartment_available_check = check_if_compartment_is_active( identity_client, compartment_ocid) if compartment_exist_check and compartment_available_check: vcn_exist = check_vcn_exist_by_ocid(client, compartment_ocid, vcn_ocid) vcn_available_state = check_vcn_ocid_is_available( client, compartment_ocid, vcn_ocid) if vcn_exist and vcn_available_state: subnet_name_match = check_subnet_name_match( client, compartment_ocid, subnet_details, vcn_ocid) if subnet_name_match: subnet_availability = check_subnet_availability( client, compartment_ocid, subnet_details, vcn_ocid) if subnet_availability: subnet_ocid = get_subnet_ocid_by_name( client, compartment_ocid, subnet_details, vcn_ocid) matched_subnet_ocid = subnet_ocid print_decorator( "SUBNET ALREADY EXISTS. SKIPPING SUBNET CREATION") if matched_subnet_ocid is None: matched_subnet_ocid = create_subnet(client, compartment_ocid, subnet_details, vcn_ocid) return matched_subnet_ocid
def check_connect_lpg(client, lpg, source_lpg_ocid, peer_lpg_ocid): if_source_lpg_peered = False if_target_lpg_peered = False peering_response = None compartment_ocid = get_compartment_ocid_from_name(identity_client, config["tenancy"], lpg["compartment_name"]) compartment_exist_check = check_if_compartment_exist( identity_client, compartment_ocid) compartment_available_check = check_if_compartment_is_active( identity_client, compartment_ocid) # vcn_exist = check_vcn_exist_by_ocid(client, lpg["compartment_id"], source_vcn_ocid) # vcn_available_state = check_vcn_ocid_is_available(client, lpg["compartment_id"], source_vcn_ocid) if_source_lpg_peered = check_peering_status(client, source_lpg_ocid) if_target_lpg_peered = check_peering_status(client, peer_lpg_ocid) # if vcn_exist and vcn_available_state: if if_source_lpg_peered: print_decorator( "SOURCE LPG {} IS ALREADY PEERED".format(source_lpg_ocid)) peering_response = None elif if_target_lpg_peered: print_decorator( "TARGET LPG {} IS ALREADY PEERED".format(peer_lpg_ocid)) peering_response = None elif not if_source_lpg_peered and not if_target_lpg_peered: peering_response = connect_local_peering_gateway( client, source_lpg_ocid, peer_lpg_ocid) else: peering_response = None return peering_response
def check_create_dhcp(client, compartment_name, vcn, vcn_ocid, dhcp): matched_dhcp_ocid = None compartment_ocid = get_compartment_ocid_from_name( identity_client, config["tenancy"], compartment_name) compartment_exist_check = check_if_compartment_exist( identity_client, compartment_ocid) compartment_available_check = check_if_compartment_is_active( identity_client, compartment_ocid) vcn_exist = check_vcn_exist_by_ocid(client, compartment_ocid, vcn_ocid) vcn_available_state = check_vcn_ocid_is_available( client, compartment_ocid, vcn_ocid) dhcp_name_check = check_if_dhcp_options_exists_by_name( client, compartment_ocid, vcn_ocid, dhcp["name"]) if compartment_exist_check and compartment_available_check: print_decorator( "COMPARTMENT EXIST AND IS IN AVAILABLE LIFECYCLE STATE") if vcn_exist and vcn_available_state and dhcp_name_check: matched_dhcp_ocid = get_dhcp_ocid_by_name( client, compartment_ocid, vcn_ocid, dhcp["name"]) dhcp_available_state = check_if_dhcp_options_lifecycle_ocid( client, compartment_ocid, vcn_ocid, matched_dhcp_ocid) if matched_dhcp_ocid is not None and dhcp_available_state: print_decorator("DHCP ALREADY EXIST") return matched_dhcp_ocid elif matched_dhcp_ocid is None: matched_dhcp_ocid = create_dhcp( virtual_network_client, compartment_ocid, vcn_ocid, dhcp["options"], dhcp["name"]) return matched_dhcp_ocid
def check_create_drg(client, drg): matched_drg_ocid = None compartment_ocid = get_compartment_ocid_from_name(identity_client, config["tenancy"], drg["compartment_name"]) drg_name_check = check_if_drg_exist_by_name(client, compartment_ocid, drg["name"]) compartment_exist_check = check_if_compartment_exist( identity_client, compartment_ocid) compartment_available_check = check_if_compartment_is_active( identity_client, compartment_ocid) if compartment_exist_check and compartment_available_check: print_decorator( "COMPARTMENT EXIST AND IS IN AVAILABLE LIFECYCLE STATE") if drg_name_check: matched_drg_ocid = get_drg_match_ocid(client, compartment_ocid, drg["name"]) drg_available_state = check_drg_ocid_is_available( client, compartment_ocid, matched_drg_ocid) if matched_drg_ocid is not None and drg_available_state: print_decorator("DRG ALREADY EXIST") return matched_drg_ocid elif matched_drg_ocid is None: matched_drg_ocid = create_drg(client, drg) return matched_drg_ocid
def create_drg(client, drg): try: compartment_ocid = get_compartment_ocid_from_name( identity_client, config["tenancy"], drg["compartment_name"]) drg_result = client.create_drg( oci.core.models.CreateDrgDetails(compartment_id=compartment_ocid, display_name=drg["name"])) drg = oci.wait_until(client, client.get_drg(drg_result.data.id), 'lifecycle_state', 'AVAILABLE') print_decorator("CREATING DRG") drg_new = convert_response_to_dict(drg) return drg_new["id"] except Exception as inst: exception = inst if inst.status and inst.message: error_handle("DRG", inst.status, inst.message) else: error_handle("DRG", "UNKNOWN", "UNKNOWN ERROR MESSAGE") return None
def create_vcn(client, composite_client, vcn): try: compartment_ocid = get_compartment_ocid_from_name( identity_client, config["tenancy"], vcn["compartment_name"]) vcn_details = oci.core.models.CreateVcnDetails( cidr_block=vcn["cidr_block"], display_name=vcn["name"], compartment_id=compartment_ocid, dns_label=vcn["dns_label"]) VCNResponse = composite_client.create_vcn_and_wait_for_state( vcn_details, wait_for_states=[oci.core.models.Vcn.LIFECYCLE_STATE_AVAILABLE]) vcn = convert_response_to_dict(VCNResponse) print_decorator("CREATING VCN") return vcn["id"] except Exception as inst: exception = inst if inst.status and inst.message: error_handle("VCN", inst.status, inst.message) else: error_handle("VCN", "UNKNOWN", "UNKNOWN ERROR MESSAGE") return None
def check_create_drg_attachment(client, drg, vcn, drg_ocid, vcn_ocid): matched_drg_attachment_ocid = None compartment_ocid = get_compartment_ocid_from_name(identity_client, config["tenancy"], drg["compartment_name"]) compartment_exist_check = check_if_compartment_exist( identity_client, compartment_ocid) compartment_available_check = check_if_compartment_is_active( identity_client, compartment_ocid) vcn_exist = check_vcn_exist_by_ocid(client, compartment_ocid, vcn_ocid) vcn_available_state = check_vcn_ocid_is_available(client, compartment_ocid, vcn_ocid) drg_name_check = check_if_drg_exist_by_name(client, compartment_ocid, drg["name"]) if compartment_exist_check and compartment_available_check: print_decorator( "COMPARTMENT EXIST AND IS IN AVAILABLE LIFECYCLE STATE") if vcn_exist and vcn_available_state and drg_name_check: drg_ocid = get_drg_match_ocid(client, compartment_ocid, drg["name"]) drg_available_state = check_drg_ocid_is_available( client, compartment_ocid, drg_ocid) if drg_ocid is not None and drg_available_state: drg_attachment_ocid = filter_drg_attachment_id( client, compartment_ocid, drg_ocid) if drg_attachment_ocid is not None: drg_attached_state = get_drg_attachment_status( client, drg_attachment_ocid) if drg_attachment_ocid is not None and drg_attached_state: matched_drg_attachment_ocid = drg_attachment_ocid print_decorator("DRG ALREADY ATTACHED TO EXISTING VCN") return matched_drg_attachment_ocid elif matched_drg_attachment_ocid is None: matched_drg_attachment_ocid = drg_attach( client, vcn_ocid, drg_ocid, drg["name"]) return matched_drg_attachment_ocid