mds_plugin/bastion.py
def delete_bastion(**kwargs):
    """Deletes a Bastion with the given id

    If no id is given, it will prompt the user for the id.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        bastion_name (str): The new name bastion
        bastion_id (str): OCID of the bastion.
        await_deletion (bool): Whether to wait till the bastion reaches
            lifecycle state DELETED
        compartment_id (str): OCID of the compartment.
        config (dict): An OCI config object or None.
        config_profile (str): The name of an OCI config profile
        ignore_current (bool): Whether the current bastion should be ignored
        interactive (bool): Indicates whether to execute in interactive mode
        raise_exceptions (bool): If set to true exceptions are raised

    Returns:
       None
    """

    bastion_name = kwargs.get("bastion_name")
    bastion_id = kwargs.get("bastion_id")
    await_deletion = kwargs.get("await_deletion")

    compartment_id = kwargs.get("compartment_id")
    ignore_current = kwargs.get("ignore_current", True)
    config = kwargs.get("config")
    config_profile = kwargs.get("config_profile")

    interactive = kwargs.get("interactive", core.get_interactive_default())
    raise_exceptions = kwargs.get("raise_exceptions", not interactive)

    import mysqlsh

    # Get the active config and compartment
    try:
        config = configuration.get_current_config(
            config=config, config_profile=config_profile,
            interactive=interactive)
        compartment_id = configuration.get_current_compartment_id(
            compartment_id=compartment_id, config=config)
        if not ignore_current and bastion_name is None:
            bastion_id = configuration.get_current_bastion_id(
                bastion_id=bastion_id, config=config)

        import oci.identity
        import oci.mysql
        try:
            bastion = get_bastion(
                bastion_name=bastion_name,
                bastion_id=bastion_id, compartment_id=compartment_id,
                config=config, ignore_current=ignore_current,
                interactive=interactive, return_type=core.RETURN_OBJ)
            if not bastion:
                raise ValueError(
                    "No bastion given or found. "
                    "Operation cancelled.")
            bastion_id = bastion.id

            if interactive:
                # Prompt the user for specifying a compartment
                prompt = mysqlsh.globals.shell.prompt(
                    f"Are you sure you want to delete the Bastion "
                    f"{bastion.name} [yes/NO]: ",
                    {'defaultValue': 'no'}).strip().lower()
                if prompt != "yes":
                    raise Exception("Deletion aborted.\n")

            # Initialize the Bastion client
            bastion_client = core.get_oci_bastion_client(config=config)

            bastion_client.delete_bastion(bastion_id=bastion_id)

            # Get db_system client
            db_system_client = core.get_oci_db_system_client(config=config)

            # Update db_systems in the compartment and remove the bastion_id
            # db_systems = mysql_database_service.list_db_systems(
            #     compartment_id=bastion.compartment_id,
            #     config=config, interactive=False)
            # for db_system in db_systems:
            #     if "bastion_id" in db_system.get("freeform_tags"):
            #         if db_system.get("freeform_tags").get("bastion_id") == \
            #                 bastion_id:
            #             # Remove the "bastion_id" key from the dict
            #             db_system.get("freeform_tags").pop("bastion_id")

            #             # Update the db_system
            #             update_details = oci.mysql.models.UpdateDbSystemDetails(
            #                 freeform_tags=db_system.get("freeform_tags"))
            #             db_system_client.update_db_system(
            #                 db_system.get("id"), update_details)

            # If the current bastion has been deleted, clear it
            if configuration.get_current_bastion_id(
                    config=config) == bastion_id:
                configuration.set_current_bastion(bastion_id='')

            # If the function should wait till the bastion reaches the DELETED
            # lifecycle state
            if await_deletion:
                import time
                if interactive:
                    print('Waiting for Bastion to be deleted...')

                # Wait for the Bastion Session to be ACTIVE
                cycles = 0
                while cycles < 48:
                    bastion = bastion_client.get_bastion(
                        bastion_id=bastion_id).data
                    if bastion.lifecycle_state == "DELETED":
                        break
                    else:
                        time.sleep(5)
                        s = "." * (cycles + 1)
                        if interactive:
                            print(f'Waiting for Bastion to be deleted...{s}')
                    cycles += 1

                if bastion.lifecycle_state != "DELETED":
                    raise Exception("Bastion did not reach the DELETED "
                                    "state within 4 minutes.")
                if interactive:
                    print(
                        f"Bastion '{bastion.name}' was deleted successfully.")
            elif interactive:
                print(f"Bastion '{bastion.name}' is being deleted.")

        except oci.exceptions.ServiceError as e:
            if interactive:
                raise
            print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
    except (Exception) as e:
        if raise_exceptions:
            raise
        print(f'ERROR: {e}')
Deletes a Bastion with the given id

    If no id is given, it will prompt the user for the id.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        bastion_name (str): The new name bastion
        bastion_id (str): OCID of the bastion.
        await_deletion (bool): Whether to wait till the bastion reaches
            lifecycle state DELETED
        compartment_id (str): OCID of the compartment.
        config (dict): An OCI config object or None.
        config_profile (str): The name of an OCI config profile
        ignore_current (bool): Whether the current bastion should be ignored
        interactive (bool): Indicates whether to execute in interactive mode
        raise_exceptions (bool): If set to true exceptions are raised

    Returns:
       None
    
Deletes a Bastion with the given id
If no id is given, it will prompt the user for the id.
Deletes a Bastion with the given id If no id is given it will prompt the user for the id .
def delete_bastion(**kwargs):
    bastion_name = kwargs.get("bastion_name")
    bastion_id = kwargs.get("bastion_id")
    await_deletion = kwargs.get("await_deletion")
    compartment_id = kwargs.get("compartment_id")
    ignore_current = kwargs.get("ignore_current", True)
    config = kwargs.get("config")
    config_profile = kwargs.get("config_profile")
    interactive = kwargs.get("interactive", core.get_interactive_default())
    raise_exceptions = kwargs.get("raise_exceptions", not interactive)
    import mysqlsh
    try:
        config = configuration.get_current_config(
            config=config, config_profile=config_profile,
            interactive=interactive)
        compartment_id = configuration.get_current_compartment_id(
            compartment_id=compartment_id, config=config)
        if not ignore_current and bastion_name is None:
            bastion_id = configuration.get_current_bastion_id(
                bastion_id=bastion_id, config=config)
        import oci.identity
        import oci.mysql
        try:
            bastion = get_bastion(
                bastion_name=bastion_name,
                bastion_id=bastion_id, compartment_id=compartment_id,
                config=config, ignore_current=ignore_current,
                interactive=interactive, return_type=core.RETURN_OBJ)
            if not bastion:
                raise ValueError(
                    "No bastion given or found. "
                    "Operation cancelled.")
            bastion_id = bastion.id
            if interactive:
                prompt = mysqlsh.globals.shell.prompt(
                    f"Are you sure you want to delete the Bastion "
                    f"{bastion.name} [yes/NO]: ",
                    {'defaultValue': 'no'}).strip().lower()
                if prompt != "yes":
                    raise Exception("Deletion aborted.\n")
            bastion_client = core.get_oci_bastion_client(config=config)
            bastion_client.delete_bastion(bastion_id=bastion_id)
            db_system_client = core.get_oci_db_system_client(config=config)
            if configuration.get_current_bastion_id(
                    config=config) == bastion_id:
                configuration.set_current_bastion(bastion_id='')
            if await_deletion:
                import time
                if interactive:
                    print('Waiting for Bastion to be deleted...')
                cycles = 0
                while cycles < 48:
                    bastion = bastion_client.get_bastion(
                        bastion_id=bastion_id).data
                    if bastion.lifecycle_state == "DELETED":
                        break
                    else:
                        time.sleep(5)
                        s = "." * (cycles + 1)
                        if interactive:
                            print(f'Waiting for Bastion to be deleted...{s}')
                    cycles += 1
                if bastion.lifecycle_state != "DELETED":
                    raise Exception("Bastion did not reach the DELETED "
                                    "state within 4 minutes.")
                if interactive:
                    print(
                        f"Bastion '{bastion.name}' was deleted successfully.")
            elif interactive:
                print(f"Bastion '{bastion.name}' is being deleted.")
        except oci.exceptions.ServiceError as e:
            if interactive:
                raise
            print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
    except (Exception) as e:
        if raise_exceptions:
            raise
        print(f'ERROR: {e}')
def delete_bastion ( ** kwargs ) : bastion_name = kwargs . get ( "bastion_name" ) bastion_id = kwargs . get ( "bastion_id" ) await_deletion = kwargs . get ( "await_deletion" ) compartment_id = kwargs . get ( "compartment_id" ) ignore_current = kwargs . get ( "ignore_current" , True ) config = kwargs . get ( "config" ) config_profile = kwargs . get ( "config_profile" ) interactive = kwargs . get ( "interactive" , core . get_interactive_default ( ) ) raise_exceptions = kwargs . get ( "raise_exceptions" , not interactive ) import mysqlsh try : config = configuration . get_current_config ( config = config , config_profile = config_profile , interactive = interactive ) compartment_id = configuration . get_current_compartment_id ( compartment_id = compartment_id , config = config ) if not ignore_current and bastion_name is None : bastion_id = configuration . get_current_bastion_id ( bastion_id = bastion_id , config = config ) import oci . identity import oci . mysql try : bastion = get_bastion ( bastion_name = bastion_name , bastion_id = bastion_id , compartment_id = compartment_id , config = config , ignore_current = ignore_current , interactive = interactive , return_type = core . RETURN_OBJ ) if not bastion : raise ValueError ( "No bastion given or found. " "Operation cancelled." ) bastion_id = bastion . id if interactive : prompt = mysqlsh . globals . shell . prompt ( f"Are you sure you want to delete the Bastion " f"{bastion.name} [yes/NO]: " , { 'defaultValue' : 'no' } ) . strip ( ) . lower ( ) if prompt != "yes" : raise Exception ( "Deletion aborted.\n" ) bastion_client = core . get_oci_bastion_client ( config = config ) bastion_client . delete_bastion ( bastion_id = bastion_id ) db_system_client = core . get_oci_db_system_client ( config = config ) if configuration . get_current_bastion_id ( config = config ) == bastion_id : configuration . set_current_bastion ( bastion_id = '' ) if await_deletion : import time if interactive : print ( 'Waiting for Bastion to be deleted...' ) cycles = 0 while cycles < 48 : bastion = bastion_client . get_bastion ( bastion_id = bastion_id ) . data if bastion . lifecycle_state == "DELETED" : break else : time . sleep ( 5 ) s = "." * ( cycles + 1 ) if interactive : print ( f'Waiting for Bastion to be deleted...{s}' ) cycles += 1 if bastion . lifecycle_state != "DELETED" : raise Exception ( "Bastion did not reach the DELETED " "state within 4 minutes." ) if interactive : print ( f"Bastion '{bastion.name}' was deleted successfully." ) elif interactive : print ( f"Bastion '{bastion.name}' is being deleted." ) except oci . exceptions . ServiceError as e : if interactive : raise print ( f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})' ) except ( Exception ) as e : if raise_exceptions : raise print ( f'ERROR: {e}' )
Deletes a Bastion with the given id
If no id is given, it will prompt the user for the id.
Deletes a Bastion with the given id If no id is given it will prompt the user for the id .
"""Deletes a Bastion with the given id

    If no id is given, it will prompt the user for the id.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        bastion_name (str): The new name bastion
        bastion_id (str): OCID of the bastion.
        await_deletion (bool): Whether to wait till the bastion reaches
            lifecycle state DELETED
        compartment_id (str): OCID of the compartment.
        config (dict): An OCI config object or None.
        config_profile (str): The name of an OCI config profile
        ignore_current (bool): Whether the current bastion should be ignored
        interactive (bool): Indicates whether to execute in interactive mode
        raise_exceptions (bool): If set to true exceptions are raised

    Returns:
       None
    """ # Get the active config and compartment # Prompt the user for specifying a compartment # Initialize the Bastion client # Get db_system client # Update db_systems in the compartment and remove the bastion_id # db_systems = mysql_database_service.list_db_systems( #     compartment_id=bastion.compartment_id, #     config=config, interactive=False) # for db_system in db_systems: #     if "bastion_id" in db_system.get("freeform_tags"): #         if db_system.get("freeform_tags").get("bastion_id") == \ #                 bastion_id: #             # Remove the "bastion_id" key from the dict #             db_system.get("freeform_tags").pop("bastion_id") #             # Update the db_system #             update_details = oci.mysql.models.UpdateDbSystemDetails( #                 freeform_tags=db_system.get("freeform_tags")) #             db_system_client.update_db_system( #                 db_system.get("id"), update_details) # If the current bastion has been deleted, clear it # If the function should wait till the bastion reaches the DELETED # lifecycle state # Wait for the Bastion Session to be ACTIVE
None
**kwargs
None