mds_plugin/compute.py
def delete_instance(**kwargs):
    """Deletes the compute instance with the given name

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

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        instance_name (str): The name of the instance.
        instance_id (str): The OCID of the instance
        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 instance should be ignored
        interactive (bool): Indicates whether to execute in interactive mode
        raise_exceptions (bool): If set to true exceptions are raised

    Returns:
       None
    """

    instance_name = kwargs.get("instance_name")
    instance_id = kwargs.get("instance_id")
    await_deletion = kwargs.get("await_deletion")

    compartment_id = kwargs.get("compartment_id")
    ignore_current = kwargs.get("ignore_current", False)
    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)

    # 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 instance_name is None:
            instance_id = configuration.get_current_instance_id(
                instance_id=instance_id, config=config)

        import oci.exceptions

        try:
            # Initialize the compute client
            compute_client = core.get_oci_compute_client(config=config)

            if not instance_id:
                instance = get_instance(
                    instance_name=instance_name, compartment_id=compartment_id,
                    config=config, interactive=interactive,
                    raise_exceptions=raise_exceptions,
                    return_python_object=True)
            else:
                instance = get_instance_by_id(
                    instance_id=instance_id, config=config,
                    interactive=interactive,
                    raise_exceptions=raise_exceptions,
                    return_python_object=True)

            if interactive:
                # Prompt the user for confirmation
                prompt = core.prompt(
                    "Are you sure you want to delete the instance "
                    f"{instance.display_name} [yes/NO]: ",
                    {'defaultValue': 'no'}).strip().lower()

                if prompt != "yes":
                    raise Exception("Deletion aborted.")

            compute_client.terminate_instance(instance.id)

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

                # Wait for the instance to be TERMINATED
                cycles = 0
                while cycles < 48:
                    instance = compute_client.get_instance(
                        instance_id=instance_id).data
                    if instance.lifecycle_state == "TERMINATED":
                        break
                    else:
                        time.sleep(5)
                        # s = "." * (cycles + 1)
                        if interactive:
                            print('.', end="")
                    cycles += 1

                if interactive:
                    print("")

                if instance.lifecycle_state != "TERMINATED":
                    raise Exception("Instance did not reach the TERMINATED "
                                    "state within 4 minutes.")
                if interactive:
                    print(f"Instance '{instance.display_name}' "
                          "was deleted successfully.")
            elif interactive:
                print(f"Instance '{instance.display_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 the compute instance with the given name

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

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        instance_name (str): The name of the instance.
        instance_id (str): The OCID of the instance
        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 instance 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 the compute instance with the given name
If no name is given, it will prompt the user for the name.
Deletes the compute instance with the given name If no name is given it will prompt the user for the name .
def delete_instance(**kwargs):
    instance_name = kwargs.get("instance_name")
    instance_id = kwargs.get("instance_id")
    await_deletion = kwargs.get("await_deletion")
    compartment_id = kwargs.get("compartment_id")
    ignore_current = kwargs.get("ignore_current", False)
    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)
    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 instance_name is None:
            instance_id = configuration.get_current_instance_id(
                instance_id=instance_id, config=config)
        import oci.exceptions
        try:
            compute_client = core.get_oci_compute_client(config=config)
            if not instance_id:
                instance = get_instance(
                    instance_name=instance_name, compartment_id=compartment_id,
                    config=config, interactive=interactive,
                    raise_exceptions=raise_exceptions,
                    return_python_object=True)
            else:
                instance = get_instance_by_id(
                    instance_id=instance_id, config=config,
                    interactive=interactive,
                    raise_exceptions=raise_exceptions,
                    return_python_object=True)
            if interactive:
                prompt = core.prompt(
                    "Are you sure you want to delete the instance "
                    f"{instance.display_name} [yes/NO]: ",
                    {'defaultValue': 'no'}).strip().lower()
                if prompt != "yes":
                    raise Exception("Deletion aborted.")
            compute_client.terminate_instance(instance.id)
            if await_deletion:
                import time
                if interactive:
                    print('Waiting for instance to be deleted...', end="")
                cycles = 0
                while cycles < 48:
                    instance = compute_client.get_instance(
                        instance_id=instance_id).data
                    if instance.lifecycle_state == "TERMINATED":
                        break
                    else:
                        time.sleep(5)
                        if interactive:
                            print('.', end="")
                    cycles += 1
                if interactive:
                    print("")
                if instance.lifecycle_state != "TERMINATED":
                    raise Exception("Instance did not reach the TERMINATED "
                                    "state within 4 minutes.")
                if interactive:
                    print(f"Instance '{instance.display_name}' "
                          "was deleted successfully.")
            elif interactive:
                print(f"Instance '{instance.display_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_instance ( ** kwargs ) : instance_name = kwargs . get ( "instance_name" ) instance_id = kwargs . get ( "instance_id" ) await_deletion = kwargs . get ( "await_deletion" ) compartment_id = kwargs . get ( "compartment_id" ) ignore_current = kwargs . get ( "ignore_current" , False ) 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 ) 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 instance_name is None : instance_id = configuration . get_current_instance_id ( instance_id = instance_id , config = config ) import oci . exceptions try : compute_client = core . get_oci_compute_client ( config = config ) if not instance_id : instance = get_instance ( instance_name = instance_name , compartment_id = compartment_id , config = config , interactive = interactive , raise_exceptions = raise_exceptions , return_python_object = True ) else : instance = get_instance_by_id ( instance_id = instance_id , config = config , interactive = interactive , raise_exceptions = raise_exceptions , return_python_object = True ) if interactive : prompt = core . prompt ( "Are you sure you want to delete the instance " f"{instance.display_name} [yes/NO]: " , { 'defaultValue' : 'no' } ) . strip ( ) . lower ( ) if prompt != "yes" : raise Exception ( "Deletion aborted." ) compute_client . terminate_instance ( instance . id ) if await_deletion : import time if interactive : print ( 'Waiting for instance to be deleted...' , end = "" ) cycles = 0 while cycles < 48 : instance = compute_client . get_instance ( instance_id = instance_id ) . data if instance . lifecycle_state == "TERMINATED" : break else : time . sleep ( 5 ) if interactive : print ( '.' , end = "" ) cycles += 1 if interactive : print ( "" ) if instance . lifecycle_state != "TERMINATED" : raise Exception ( "Instance did not reach the TERMINATED " "state within 4 minutes." ) if interactive : print ( f"Instance '{instance.display_name}' " "was deleted successfully." ) elif interactive : print ( f"Instance '{instance.display_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 the compute instance with the given name
If no name is given, it will prompt the user for the name.
Deletes the compute instance with the given name If no name is given it will prompt the user for the name .
"""Deletes the compute instance with the given name

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

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        instance_name (str): The name of the instance.
        instance_id (str): The OCID of the instance
        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 instance 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
 # Initialize the compute client
 # Prompt the user for confirmation
 # If the function should wait till the bastion reaches the DELETED
 # lifecycle state
 # Wait for the instance to be TERMINATED
 # s = "." * (cycles + 1)

None
**kwargs
None