mds_plugin/object_store.py
def create_bucket_object(file_name=None, name=None,
                         bucket_name=None, file_content=None,
                         compartment_id=None, config=None,
                         interactive=True):
    """Creates a new object store bucket object

    Args:
        file_name (str): The name of the file to upload
        name (str): The name of the object bucket to create
        bucket_name (str): The name of the new bucket.
        file_content (str): The contents of the file
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): Whether exceptions should be raised

    Returns:
        None
    """

    # 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)
    except ValueError as e:
        print(f"ERROR: {str(e)}")
        return

    import oci.object_storage
    import mysqlsh
    import os.path
    import io

    if interactive and file_name is None and file_content is None:
        print("Creating a new bucket object ...\n")

    # Get a name (if no file_content was given)
    if file_name is None and file_content is None:
        file_name = mysqlsh.globals.shell.prompt(
            "Please enter the path to a local file to upload: ",
            {'defaultValue': ''}).strip()
        if file_name == "":
            print("Operation cancelled.")
            return
    if file_content is None:
        file_name = os.path.abspath(
            os.path.expanduser(file_name))
        if not os.path.exists(file_name):
            print(f"Cannot find the file {file_name}.")
            return

    if name is None and file_name:
        name = os.path.basename(file_name)

    if name is None:
        print(f"No name for the bucked file specified.")
        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)

    try:
        # If the file content was given as string
        if file_content is not None:
            with io.StringIO() as f:
                f.write(file_content)
                f.seek(0)
                # put_object returns a response object with data None
                os_client.put_object(
                    namespace_name=namespace_name, bucket_name=bucket_name,
                    object_name=name, put_object_body=f)
        else:
            # upload manager will automatically use singlepart uploads if the
            # part size (in bytes) is less than the file size
            part_size = oci.object_storage.transfer.constants.DEFAULT_PART_SIZE

            upload_manager = oci.object_storage.UploadManager(
                object_storage_client=os_client,
                allow_parallel_uploads=True, parallel_process_count=5)

            upload_manager.upload_file(
                namespace_name=namespace_name, bucket_name=bucket_name,
                object_name=name,
                file_path=file_name,
                part_size=part_size,
                progress_callback=bucket_object_upload_progress_callback)
    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

    if interactive:
        print("Bucket object created successfully.")
    else:
        return True
Creates a new object store bucket object

    Args:
        file_name (str): The name of the file to upload
        name (str): The name of the object bucket to create
        bucket_name (str): The name of the new bucket.
        file_content (str): The contents of the file
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): Whether exceptions should be raised

    Returns:
        None
    
Creates a new object store bucket object
Creates a new object store bucket object
def create_bucket_object(file_name=None, name=None,
                         bucket_name=None, file_content=None,
                         compartment_id=None, config=None,
                         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)
    except ValueError as e:
        print(f"ERROR: {str(e)}")
        return
    import oci.object_storage
    import mysqlsh
    import os.path
    import io
    if interactive and file_name is None and file_content is None:
        print("Creating a new bucket object ...\n")
    if file_name is None and file_content is None:
        file_name = mysqlsh.globals.shell.prompt(
            "Please enter the path to a local file to upload: ",
            {'defaultValue': ''}).strip()
        if file_name == "":
            print("Operation cancelled.")
            return
    if file_content is None:
        file_name = os.path.abspath(
            os.path.expanduser(file_name))
        if not os.path.exists(file_name):
            print(f"Cannot find the file {file_name}.")
            return
    if name is None and file_name:
        name = os.path.basename(file_name)
    if name is None:
        print(f"No name for the bucked file specified.")
        return
    os_client = core.get_oci_object_storage_client(config=config)
    namespace_name = get_object_store_namespace(config)
    try:
        if file_content is not None:
            with io.StringIO() as f:
                f.write(file_content)
                f.seek(0)
                os_client.put_object(
                    namespace_name=namespace_name, bucket_name=bucket_name,
                    object_name=name, put_object_body=f)
        else:
            part_size = oci.object_storage.transfer.constants.DEFAULT_PART_SIZE
            upload_manager = oci.object_storage.UploadManager(
                object_storage_client=os_client,
                allow_parallel_uploads=True, parallel_process_count=5)
            upload_manager.upload_file(
                namespace_name=namespace_name, bucket_name=bucket_name,
                object_name=name,
                file_path=file_name,
                part_size=part_size,
                progress_callback=bucket_object_upload_progress_callback)
    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
    if interactive:
        print("Bucket object created successfully.")
    else:
        return True
def create_bucket_object ( file_name = None , name = None , bucket_name = None , file_content = None , compartment_id = None , config = None , 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 ) except ValueError as e : print ( f"ERROR: {str(e)}" ) return import oci . object_storage import mysqlsh import os . path import io if interactive and file_name is None and file_content is None : print ( "Creating a new bucket object ...\n" ) if file_name is None and file_content is None : file_name = mysqlsh . globals . shell . prompt ( "Please enter the path to a local file to upload: " , { 'defaultValue' : '' } ) . strip ( ) if file_name == "" : print ( "Operation cancelled." ) return if file_content is None : file_name = os . path . abspath ( os . path . expanduser ( file_name ) ) if not os . path . exists ( file_name ) : print ( f"Cannot find the file {file_name}." ) return if name is None and file_name : name = os . path . basename ( file_name ) if name is None : print ( f"No name for the bucked file specified." ) return os_client = core . get_oci_object_storage_client ( config = config ) namespace_name = get_object_store_namespace ( config ) try : if file_content is not None : with io . StringIO ( ) as f : f . write ( file_content ) f . seek ( 0 ) os_client . put_object ( namespace_name = namespace_name , bucket_name = bucket_name , object_name = name , put_object_body = f ) else : part_size = oci . object_storage . transfer . constants . DEFAULT_PART_SIZE upload_manager = oci . object_storage . UploadManager ( object_storage_client = os_client , allow_parallel_uploads = True , parallel_process_count = 5 ) upload_manager . upload_file ( namespace_name = namespace_name , bucket_name = bucket_name , object_name = name , file_path = file_name , part_size = part_size , progress_callback = bucket_object_upload_progress_callback ) 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 if interactive : print ( "Bucket object created successfully." ) else : return True
Creates a new object store bucket object
Creates a new object store bucket object
"""Creates a new object store bucket object

    Args:
        file_name (str): The name of the file to upload
        name (str): The name of the object bucket to create
        bucket_name (str): The name of the new bucket.
        file_content (str): The contents of the file
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): Whether exceptions should be raised

    Returns:
        None
    """ # Get the active config and compartment
 # Get a name (if no file_content was given)
 # Initialize the  Object Store client
 # Get Object Store namespace
 # If the file content was given as string
 # put_object returns a response object with data None
 # upload manager will automatically use singlepart uploads if the
 # part size (in bytes) is less than the file size

None
file_name
The name of the file to upload
The name of the file to upload
name
The name of the object bucket to create
The name of the object bucket to create
bucket_name
The name of the new bucket.
The name of the new bucket .
file_content
The contents of the file
The contents of the file
compartment_id
OCID of the parent compartment.
OCID of the parent compartment .
config
An OCI config object or None.
An OCI config object or None .
interactive
Whether exceptions should be raised
Whether exceptions should be raised