mds_plugin/object_store.py
def delete_bucket_object(name=None, **kwargs):
    """Deletes an object store bucket objects

    Args:
        name (str): The name of the object, can include * to match multiple 
            objects
        **kwargs: Additional options

    Keyword Args:
        bucket_name (str): The name of the bucket.
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): If set to false, function returns true on success
    Returns:
         None or True
    """

    bucket_name = kwargs.get('bucket_name')
    compartment_id = kwargs.get('compartment_id')
    config = kwargs.get('config')
    interactive = kwargs.get('interactive', True)

    # Get the active config and compartment
    try:
        config = configuration.get_current_config(config=config)
        compartment_id = configuration.get_current_compartment_id(
            compartment_id=compartment_id, config=config)
        bucket_name = configuration.get_current_bucket_name(
            bucket_name=bucket_name, config=config)

        import oci.object_storage
        import mysqlsh
        import re

        bucket = get_bucket(
            bucket_name=bucket_name, compartment_id=compartment_id,
            config=config)
        if bucket is None:
            if interactive:
                print("Operation Cancelled.\n")
            return

        # Initialize the  Object Store client
        os_client = core.get_oci_object_storage_client(config=config)

        # Get Object Store namespace
        namespace_name = get_object_store_namespace(config)

        # If the user specified * as name, delete all
        if name and (name == '*' or '*' in name):
            # Get object list
            objects = oci.pagination.list_call_get_all_results(
                os_client.list_objects,
                namespace_name=namespace_name,
                bucket_name=bucket.name,
                limit=1000).data.objects
            # Filter list
            if name != '*':
                name = name.lower()
                # Filter list if PARs
                if '*' in name:
                    name_pattern = '^' + name.replace('*', '.+')
                    objects = [obj for obj in objects
                               if re.search(name_pattern, obj.name.lower())]
                else:
                    objects = [obj for obj in objects
                               if name == obj.name.lower()]

            # Get object count
            obj_count = len(objects)
            if obj_count == 0:
                print("No objects to delete in this bucket.")
                return

            # Prompt the user for confirmation
            if interactive:
                prompt = mysqlsh.globals.shell.prompt(
                    f"Are you sure you want to delete {obj_count} object"
                    f"{'s' if obj_count > 1 else ''} from {bucket.name} "
                    f"[yes/NO]: ",
                    {'defaultValue': 'no'}).strip().lower()
                if prompt != "yes":
                    print("Deletion aborted.\n")
                    return

            # Delete all objects
            print(f"Deleting {obj_count} "
                  f"object{'s' if obj_count > 1 else ''}.")

            import threading

            thread_count = NTHREAD if obj_count > NTHREAD else obj_count

            ths = [threading.Thread(
                target=delete_file_from_list_from_bucket,
                args=(i, os_client, objects, namespace_name, bucket.name,
                      thread_count))
                   for i in range(thread_count)]
            for th in ths:
                th.daemon = True
                th.start()
            for th in ths:
                th.join()

            if interactive:
                print(f"Bucket object{'s' if '*' in name else ''} "
                      f"deleted successfully.")
        elif name:
            os_client.delete_object(
                namespace_name=namespace_name, bucket_name=bucket.name,
                object_name=name)

            print(f"Bucket object '{name}' deleted successfully.")
        elif interactive:
            # Get object list
            bucket_objects = oci.pagination.list_call_get_all_results(
                os_client.list_objects,
                namespace_name=namespace_name,
                bucket_name=bucket.name,
                limit=1000).data.objects

            print(format_bucket_objects_listing(bucket_objects=bucket_objects))

            obj_summary = core.prompt_for_list_item(
                item_list=bucket_objects,
                prompt_caption="Please enter the index or name of an object: ",
                item_name_property="name")
            if obj_summary is None:
                print("Operation cancelled.")
                return
            name = obj_summary.name

            os_client.delete_object(
                namespace_name=namespace_name, bucket_name=bucket.name,
                object_name=name)

            print(f"Bucket object '{name}' deleted successfully.")
        else:
            print('No Object name given.')

        if not interactive:
            return True

    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except Exception as e:
        print(f'ERROR: {e}')
        return
Deletes an object store bucket objects

    Args:
        name (str): The name of the object, can include * to match multiple 
            objects
        **kwargs: Additional options

    Keyword Args:
        bucket_name (str): The name of the bucket.
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): If set to false, function returns true on success
    Returns:
         None or True
    
Deletes an object store bucket objects
Deletes an object store bucket objects
def delete_bucket_object(name=None, **kwargs):
    bucket_name = kwargs.get('bucket_name')
    compartment_id = kwargs.get('compartment_id')
    config = kwargs.get('config')
    interactive = kwargs.get('interactive', True)
    try:
        config = configuration.get_current_config(config=config)
        compartment_id = configuration.get_current_compartment_id(
            compartment_id=compartment_id, config=config)
        bucket_name = configuration.get_current_bucket_name(
            bucket_name=bucket_name, config=config)
        import oci.object_storage
        import mysqlsh
        import re
        bucket = get_bucket(
            bucket_name=bucket_name, compartment_id=compartment_id,
            config=config)
        if bucket is None:
            if interactive:
                print("Operation Cancelled.\n")
            return
        os_client = core.get_oci_object_storage_client(config=config)
        namespace_name = get_object_store_namespace(config)
        if name and (name == '*' or '*' in name):
            objects = oci.pagination.list_call_get_all_results(
                os_client.list_objects,
                namespace_name=namespace_name,
                bucket_name=bucket.name,
                limit=1000).data.objects
            if name != '*':
                name = name.lower()
                if '*' in name:
                    name_pattern = '^' + name.replace('*', '.+')
                    objects = [obj for obj in objects
                               if re.search(name_pattern, obj.name.lower())]
                else:
                    objects = [obj for obj in objects
                               if name == obj.name.lower()]
            obj_count = len(objects)
            if obj_count == 0:
                print("No objects to delete in this bucket.")
                return
            if interactive:
                prompt = mysqlsh.globals.shell.prompt(
                    f"Are you sure you want to delete {obj_count} object"
                    f"{'s' if obj_count > 1 else ''} from {bucket.name} "
                    f"[yes/NO]: ",
                    {'defaultValue': 'no'}).strip().lower()
                if prompt != "yes":
                    print("Deletion aborted.\n")
                    return
            print(f"Deleting {obj_count} "
                  f"object{'s' if obj_count > 1 else ''}.")
            import threading
            thread_count = NTHREAD if obj_count > NTHREAD else obj_count
            ths = [threading.Thread(
                target=delete_file_from_list_from_bucket,
                args=(i, os_client, objects, namespace_name, bucket.name,
                      thread_count))
                   for i in range(thread_count)]
            for th in ths:
                th.daemon = True
                th.start()
            for th in ths:
                th.join()
            if interactive:
                print(f"Bucket object{'s' if '*' in name else ''} "
                      f"deleted successfully.")
        elif name:
            os_client.delete_object(
                namespace_name=namespace_name, bucket_name=bucket.name,
                object_name=name)
            print(f"Bucket object '{name}' deleted successfully.")
        elif interactive:
            bucket_objects = oci.pagination.list_call_get_all_results(
                os_client.list_objects,
                namespace_name=namespace_name,
                bucket_name=bucket.name,
                limit=1000).data.objects
            print(format_bucket_objects_listing(bucket_objects=bucket_objects))
            obj_summary = core.prompt_for_list_item(
                item_list=bucket_objects,
                prompt_caption="Please enter the index or name of an object: ",
                item_name_property="name")
            if obj_summary is None:
                print("Operation cancelled.")
                return
            name = obj_summary.name
            os_client.delete_object(
                namespace_name=namespace_name, bucket_name=bucket.name,
                object_name=name)
            print(f"Bucket object '{name}' deleted successfully.")
        else:
            print('No Object name given.')
        if not interactive:
            return True
    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except Exception as e:
        print(f'ERROR: {e}')
        return
def delete_bucket_object ( name = None , ** kwargs ) : bucket_name = kwargs . get ( 'bucket_name' ) compartment_id = kwargs . get ( 'compartment_id' ) config = kwargs . get ( 'config' ) interactive = kwargs . get ( 'interactive' , True ) try : config = configuration . get_current_config ( config = config ) compartment_id = configuration . get_current_compartment_id ( compartment_id = compartment_id , config = config ) bucket_name = configuration . get_current_bucket_name ( bucket_name = bucket_name , config = config ) import oci . object_storage import mysqlsh import re bucket = get_bucket ( bucket_name = bucket_name , compartment_id = compartment_id , config = config ) if bucket is None : if interactive : print ( "Operation Cancelled.\n" ) return os_client = core . get_oci_object_storage_client ( config = config ) namespace_name = get_object_store_namespace ( config ) if name and ( name == '*' or '*' in name ) : objects = oci . pagination . list_call_get_all_results ( os_client . list_objects , namespace_name = namespace_name , bucket_name = bucket . name , limit = 1000 ) . data . objects if name != '*' : name = name . lower ( ) if '*' in name : name_pattern = '^' + name . replace ( '*' , '.+' ) objects = [ obj for obj in objects if re . search ( name_pattern , obj . name . lower ( ) ) ] else : objects = [ obj for obj in objects if name == obj . name . lower ( ) ] obj_count = len ( objects ) if obj_count == 0 : print ( "No objects to delete in this bucket." ) return if interactive : prompt = mysqlsh . globals . shell . prompt ( f"Are you sure you want to delete {obj_count} object" f"{'s' if obj_count > 1 else ''} from {bucket.name} " f"[yes/NO]: " , { 'defaultValue' : 'no' } ) . strip ( ) . lower ( ) if prompt != "yes" : print ( "Deletion aborted.\n" ) return print ( f"Deleting {obj_count} " f"object{'s' if obj_count > 1 else ''}." ) import threading thread_count = NTHREAD if obj_count > NTHREAD else obj_count ths = [ threading . Thread ( target = delete_file_from_list_from_bucket , args = ( i , os_client , objects , namespace_name , bucket . name , thread_count ) ) for i in range ( thread_count ) ] for th in ths : th . daemon = True th . start ( ) for th in ths : th . join ( ) if interactive : print ( f"Bucket object{'s' if '*' in name else ''} " f"deleted successfully." ) elif name : os_client . delete_object ( namespace_name = namespace_name , bucket_name = bucket . name , object_name = name ) print ( f"Bucket object '{name}' deleted successfully." ) elif interactive : bucket_objects = oci . pagination . list_call_get_all_results ( os_client . list_objects , namespace_name = namespace_name , bucket_name = bucket . name , limit = 1000 ) . data . objects print ( format_bucket_objects_listing ( bucket_objects = bucket_objects ) ) obj_summary = core . prompt_for_list_item ( item_list = bucket_objects , prompt_caption = "Please enter the index or name of an object: " , item_name_property = "name" ) if obj_summary is None : print ( "Operation cancelled." ) return name = obj_summary . name os_client . delete_object ( namespace_name = namespace_name , bucket_name = bucket . name , object_name = name ) print ( f"Bucket object '{name}' deleted successfully." ) else : print ( 'No Object name given.' ) if not interactive : return True except oci . exceptions . ServiceError as e : print ( f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})' ) return except Exception as e : print ( f'ERROR: {e}' ) return
Deletes an object store bucket objects
Deletes an object store bucket objects
"""Deletes an object store bucket objects

    Args:
        name (str): The name of the object, can include * to match multiple 
            objects
        **kwargs: Additional options

    Keyword Args:
        bucket_name (str): The name of the bucket.
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): If set to false, function returns true on success
    Returns:
         None or True
    """ # Get the active config and compartment
 # Initialize the  Object Store client
 # Get Object Store namespace
 # If the user specified * as name, delete all
 # Get object list
 # Filter list
 # Filter list if PARs
 # Get object count
 # Prompt the user for confirmation
 # Delete all objects
 # Get object list

None or True
None or True
name
The name of the object, can include * to match multiple
objects
The name of the object can include * to match multiple objects
**kwargs
None