示例#1
0
def get_unique_function_by_name(fn_management_client, application_id,
                                display_name) -> fn_models.Function:
    """
    Find a unique Function by name.

    :param fn_management_client: OCI FunctionsManagementClient client.
    :type fn_management_client: functions.FunctionsManagementClient

    :param application_id: The OCID of the Application which owns the Function.
    :type application_id: str

    :param display_name: The display name of the Function.
    :type display_name: str

    :return: The Function.
    :rtype: core_models.Function
    """
    result = pagination.list_call_get_all_results(
        fn_management_client.list_functions,
        application_id,
        display_name=display_name)
    for fn in result.data:
        if display_name == fn.display_name:
            return fn
    raise Exception("Function not found.")
示例#2
0
def get_unique_ig_by_name(network_client, compartment_id, vcn_id,
                          display_name):
    """
    Find a unique InternetGateway by name.

    :param network_client: OCI VirtualNetworkClient client
    :type network_client: oci.core.VirtualNetworkClient

    :param compartment_id: The OCID of the compartment which owns the Vcn.
    :type compartment_id: str

    :param vcn_id: The OCID of the Vcn which will own the InternetGateway.
    :type vcn_id: str

    :param display_name: The display name of the InternetGateway.
    :type display_name: str

    :return: The InternetGateway
    :rtype: core_models.InternetGateway
    """
    result = pagination.list_call_get_all_results(
        network_client.list_internet_gateways,
        compartment_id,
        vcn_id,
        display_name=display_name)
    for ig in result.data:
        if display_name == ig.display_name:
            return ig
示例#3
0
def get_unique_route_table_by_name(network_client, compartment_id, vcn_id,
                                   display_name):
    """
    Find a unique RouteTable by name.

    :param network_client: OCI VirtualNetworkClient client
    :type network_client: oci.core.VirtualNetworkClient

    :param compartment_id: The OCID of the compartment which owns the RouteTable.
    :type compartment_id: str

    :param vcn_id: The OCID of the Vcn which will own the RouteTable.
    :type vcn_id: str

    :param display_name: The display name of the RouteTable.
    :type display_name: str

    :return: The RouteTable.
    :rtype: core_models.RouteTable
    """
    result = pagination.list_call_get_all_results(
        network_client.list_route_tables,
        compartment_id,
        vcn_id,
        display_name=display_name)
    for rt in result.data:
        if display_name == rt.display_name:
            return rt
示例#4
0
 def get_routing_tables(self, vcn_id):
     result = pagination.list_call_get_all_results(
         self.network_client.list_route_tables,
         self._resource_config.compartment_ocid,
         vcn_id=vcn_id,
     )
     return result.data
示例#5
0
def get_unique_subnet_by_name(network_client, compartment_id, vcn_id,
                              display_name):
    """
    Find a unique Subnet by name.

    :param network_client: OCI VirtualNetworkClient client
    :type network_client: oci.core.VirtualNetworkClient

    :param compartment_id: The OCID of the compartment which owns the VCN.
    :type compartment_id: str

    :param vcn_id: The OCID of the VCN which will own the subnet.
    :type vcn_id: str

    :param display_name: The display name of the subnet.
    :type display_name: str

    :return: The Subnet
    :rtype: core_models.Subnet
    """
    result = pagination.list_call_get_all_results(network_client.list_subnets,
                                                  compartment_id,
                                                  vcn_id,
                                                  display_name=display_name)
    for subnet in result.data:
        if display_name == subnet.display_name:
            return subnet
示例#6
0
    def object_put(self, namespace_name, bucket_name, object_name, file_name, md5_sum=None, resume_upload=False):
        '''
        Upload object to object storage

        namespace_name  :   Object Storage Namespace
        bucket_name     :   Bucket name
        object_name     :   Name of uploaded object
        file_name       :   Name of local file to upload
        md5_sum         :   Md5 sum of local file
        '''
        self.logger.info(f'Starting upload of file "{file_name}" to namespace "{namespace_name}" '
                         f'bucket "{bucket_name}" and object name "{object_name}"')
        upload_resumed = False
        if resume_upload:
            self.logger.debug(f'Checking if object name "{object_name}" is in list of pending uploads')
            multipart_uploads = list_call_get_all_results(self.object_storage_client.list_multipart_uploads,
                                                          namespace_name, bucket_name)
            for multipart_upload in multipart_uploads.data:
                # Assume namespace and bucket are the same
                if multipart_upload.object == object_name:
                    self.logger.debug(f'Resuming file upload {multipart_upload.upload_id} for object "{object_name}"')
                    response = self.upload_manager.resume_upload_file(namespace_name, bucket_name, object_name, file_name, multipart_upload.upload_id)
                    upload_resumed = True
                    break
        if not upload_resumed:
            response = self.upload_manager.upload_file(namespace_name, bucket_name, object_name, file_name, content_md5=md5_sum)
        if response.status != 200:
            raise ObjectStorageException(f'Error uploading object, Reponse code {str(response.status)}')
        self.logger.info(f'File "{file_name}" uploaded to object storage with object name "{object_name}"')
        return True
示例#7
0
def get_unique_application_by_name(fn_management_client, compartment_id,
                                   display_name) -> fn_models.Application:
    """
    Find a unique Application by name.

    :param fn_management_client: OCI FunctionsManagementClient client
    :type fn_management_client: functions.FunctionsManagementClient

    :param compartment_id: The OCID of the compartment which owns the Application.
    :type compartment_id: str

    :param display_name: The display name of the subnet.
    :type display_name: str

    :return: The Subnet
    :rtype: core_models.Subnet
    """
    result = pagination.list_call_get_all_results(
        fn_management_client.list_applications,
        compartment_id,
        display_name=display_name)
    for app in result.data:
        if display_name == app.display_name:
            return app
    raise Exception("Application not found")
示例#8
0
 def list_boot_volume_backups(self, compartment_id):
     try:
         return list_call_get_all_results(
             self.block_storage_client.list_boot_volume_backups,
             compartment_id).data
     except oci.exceptions.ServiceError as identifier:
         print(identifier)
         exit()
示例#9
0
 async def get_policies(self):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(
                 self._client.list_policies, self._credentials.get_scope()))
         return response.data
     except Exception as e:
         print_exception(f'Failed to retrieve policies: {e}')
         return None
示例#10
0
 def list_volume_attachments(self, compartment_id):
     try:
         return list_call_get_all_results(
             self.compute_client.list_volume_attachments,
             compartment_id).data
     except ServiceError as identifier:
         print(identifier)
         # logger.error(identifier.message)
         exit()
示例#11
0
 async def get_user_api_keys(self, user_id):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(self._client.list_api_keys,
                                               user_id))
         return response.data
     except Exception as e:
         print_exception(f'Failed to retrieve user api keys: {e}')
         return []
示例#12
0
 def get_private_ip_object(self, subnet_id, ip_address):
     result = pagination.list_call_get_all_results(
         self.network_client.list_private_ips,
         subnet_id=subnet_id,
         ip_address=ip_address,
     )
     for ip in result.data:
         if ip.ip_address == ip_address:
             return ip
示例#13
0
 async def get_namespace(self):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(self._client.get_namespace))
         # for some reason it returns a list of chars instead of a string
         return ''.join(response.data)
     except Exception as e:
         print_exception(f'Failed to get Object Storage namespace: {e}')
         return None
示例#14
0
 async def get_groups(self):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(
                 self._client.list_groups, self._credentials.get_scope()))
         return response.data
     except Exception as e:
         print_exception('Failed to retrieve groups: {}'.format(e))
         return []
示例#15
0
 async def get_buckets(self, namespace):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(
                 self._client.list_buckets, namespace,
                 self._credentials.get_scope()))
         return response.data
     except Exception as e:
         print_exception(f'Failed to get Object Storage buckets: {e}')
         return []
示例#16
0
 async def get_vaults(self):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(
                 self._vault_client.list_vaults, self._credentials.
                 compartment_id))
         return response.data
     except Exception as e:
         print_exception('Failed to get KMS vaults: {}'.format(e))
         return []
示例#17
0
 async def get_bucket_objects(self, namespace, bucket_name):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(self._client.list_objects,
                                               namespace, bucket_name))
         return response.data
     except Exception as e:
         print_exception(
             'Failed to get Object Storage bucket objects: {}'.format(e))
         return []
示例#18
0
 def list_volume_backups(self, compartment_id):
     try:
         return list_call_get_all_results(
             self.block_storage_client.list_volume_backups,
             compartment_id,
             retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data
     except oci.exceptions.ServiceError as identifier:
         logging.error(traceback.format_exc())
         logging.error(identifier + " " + compartment_id)
         exit()
示例#19
0
 async def get_keys(self, keyvault):
     try:
         key_client = KmsManagementClient(self._credentials.config,
                                          keyvault['management_endpoint'])
         response = await run_concurrently(
             lambda: list_call_get_all_results(
                 key_client.list_keys, self._credentials.get_scope()))
         return response.data
     except Exception as e:
         print_exception(f'Failed to get KMS vaults: {e}')
         return []
示例#20
0
 def list_volume_attachments(self, compartment_id):
     try:
         return list_call_get_all_results(
             self.compute_client.list_volume_attachments,
             compartment_id,
             retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY,
         ).data
     except ServiceError as identifier:
         logging.error(traceback.format_exc())
         logging.error(identifier + " " + compartment_id)
         exit()
示例#21
0
 async def get_group_users(self, group_id):
     try:
         response = await run_concurrently(
             lambda: list_call_get_all_results(
                 self._client.list_user_group_memberships,
                 self._credentials.get_scope(),
                 group_id=group_id))
         return response.data
     except Exception as e:
         print_exception(f'Failed to retrieve group users: {e}')
         return []
示例#22
0
    def object_list(self, namespace_name, bucket_name):
        '''
        Return list of object storage objects

        namespace_name  :   Object Storage Namespace
        bucket_name     :   Bucket Name
        '''
        self.logger.info("Retrieving object list from namespace %s and bucket %s",
                         namespace_name, bucket_name)
        all_objects_response = list_call_get_all_results(self.object_storage_client.list_objects,
                                                         namespace_name, bucket_name, fields='name,md5,size,timeCreated')
        return [to_dict(obj) for obj in all_objects_response.data.objects]
示例#23
0
    def get_vcn_by_tag(self, tag_value):
        """Find a Vcn by reservation_id.

        :return: The Vcn
        :rtype: list<oci.core.models.Vcn>
        """
        result = pagination.list_call_get_all_results(
            self.network_client.list_vcns,
            self._resource_config.compartment_ocid)
        response = []
        for vcn in result.data:
            if vcn.freeform_tags.get("ReservationId", "") == tag_value:
                response.append(vcn)
        return response
示例#24
0
    def get_inet_gateways(self, vcn_id):
        """Find a unique Subnet by name.

        :param vcn_id: The OCID of the VCN which will own the subnet.
        :type vcn_id: str
        :return: The Subnet
        :rtype: core_models.Subnet
        """
        result = pagination.list_call_get_all_results(
            self.network_client.list_internet_gateways,
            self._resource_config.compartment_ocid,
            vcn_id=vcn_id,
        )

        return result.data
示例#25
0
    def get_vcn(self, name=None):
        """Find a Vcn by reservation_id.

        :return: The Vcn
        :rtype: core_models.Vcn
        """
        if not name:
            name = self._resource_config.reservation_id
        result = pagination.list_call_get_all_results(
            self.network_client.list_vcns,
            self._resource_config.compartment_ocid,
            display_name=name,
        )
        for vcn in result.data:
            if vcn.display_name == name:
                return vcn
示例#26
0
def get_availability_domains(identity_client, compartment_id):
    """
    Gets the list of AvailabilityDomain for the specified compartment.

    :param network_client: OCI VirtualNetworkClient client
    :type network_client: oci.core.VirtualNetworkClient

    :param compartment_id: The OCID of the compartment to check.
    :type compartment_id: str

    :return: The AvailabilityDomains
    :rtype: [identity_models.AvailabilityDomain]
    """
    result = pagination.list_call_get_all_results(
        identity_client.list_availability_domains, compartment_id)
    return result.data
    def identity_read_compartments(identity, tenancy, secret_data):
        result = []
        try:
            compartments = list_call_get_all_results(
                identity.list_compartments,
                tenancy.id,
                compartment_id_in_subtree=True).data

            # Add root compartment which is not part of list_compartments
            for compartment in compartments:
                if compartment.id == secret_data['tenancy'] or \
                        compartment.lifecycle_state == Compartment.LIFECYCLE_STATE_ACTIVE:
                    result.append(compartment)
            result.append(tenancy)
            return result
        except Exception as e:
            raise RuntimeError(
                "[ERROR: ResourceInfo] Error on identity_read_compartments: " +
                str(e.args))
示例#28
0
def get_instance(signer, compartment, instance_name, compute_client):
    """
    Identifies instance ID by its name within the particular compartment
    :param signer: OCI resource principal signer
    :param compartment: OCI tenancy compartment returned by IdentityClient
    :param instance_name: OCI compute instance name
    :param compute_client: OCI ComputeClient
    :return: OCI tenancy compartment
    """
    result = pagination.list_call_get_all_results(
        compute_client.list_instances,
        compartment.id,
    )

    for i in result.data:
        if instance_name == i.display_name:
            print(type(i))
            return i

    raise Exception("instance not found")
示例#29
0
def get_compartment(signer, compartment_name):
    """
    Identifies compartment ID by its name within the particular tenancy
    :param signer: OCI resource principal signer
    :param compartment_name: OCI tenancy compartment name
    :return: OCI tenancy compartment
    """
    identity_client = identity.IdentityClient(config={}, signer=signer)
    result = pagination.list_call_get_all_results(
        identity_client.list_compartments,
        signer.tenancy_id,
        compartment_id_in_subtree=True,
        access_level="ACCESSIBLE",
    )
    for c in result.data:
        if compartment_name == c.name:
            print(type(c))
            return c

    raise Exception("compartment not found")
示例#30
0
def get_compartment(oci_cfg,
                    compartment_name: str) -> identity_models.Compartment:
    """
    Identifies compartment ID by its name within the particular tenancy
    :param oci_cfg: OCI auth config
    :param compartment_name: OCI tenancy compartment name
    :return: OCI tenancy compartment
    """
    identity_client = identity.IdentityClient(oci_cfg)
    result = pagination.list_call_get_all_results(
        identity_client.list_compartments,
        cfg["tenancy"],
        compartment_id_in_subtree=True,
        access_level="ACCESSIBLE",
    )
    for c in result.data:
        if compartment_name == c.name:
            print(type(c))
            return c

    raise Exception("compartment not found")