mds_plugin/compute.py
def format_instance_listing(items, current=None, vnics=None,
                            config=None):
    """Returns a formated list of instances.

    If compartment_id is given, the current and parent compartment
    will be listed as well.

    Args:
        data (list): A list of instance objects.
        config (object): An OCI config object or None.
        compartment_id (str): The OCID of the current compartment.

    Returns:
        The formated list as string
    """
    import re
    import oci.core.models

    # If a single item was given, wrap it in a list
    if not type(items) is list:
        items = [items]

    out = ""

    # return compartments in READABLE text output
    i = 1
    for c in items:
        # Shorten to 24 chars max, remove linebreaks
        name = re.sub(r'[\n\r]', ' ',
                      c.display_name[:22] + '..'
                      if len(c.display_name) > 24
                      else c.display_name)
        # Get public IP
        public_ip = ""
        private_ip = ""
        if vnics and c.lifecycle_state in [
                oci.core.models.Instance.LIFECYCLE_STATE_RUNNING,
                oci.core.models.Instance.LIFECYCLE_STATE_STARTING,
                oci.core.models.Instance.LIFECYCLE_STATE_STOPPED,
                oci.core.models.Instance.LIFECYCLE_STATE_STOPPING]:

            instance_vnics = [v for v in vnics if v.instance_id == c.id]
            if len(instance_vnics) > 0:
                virtual_network = core.get_oci_virtual_network_client(
                    config=config)
                try:
                    vnic = virtual_network.get_vnic(
                        instance_vnics[0].vnic_id).data
                    public_ip = vnic.public_ip \
                        if vnic.public_ip else ''
                    private_ip = vnic.private_ip \
                        if vnic.private_ip else ''
                except oci.exceptions.ServiceError as e:
                    # Ignore NotFound error
                    if e.code == "NotAuthorizedOrNotFound":
                        pass

        index = f"*{i:>3}" if current == c.id else f"{i:>4}"
        out += (f"{index} {name:24} {c.shape[:22]:22} {c.fault_domain[:15]:15} "
                f"{public_ip if public_ip != '' else private_ip:15} "
                f"{c.lifecycle_state}\n")
        i += 1

    return out
Returns a formated list of instances.

    If compartment_id is given, the current and parent compartment
    will be listed as well.

    Args:
        data (list): A list of instance objects.
        config (object): An OCI config object or None.
        compartment_id (str): The OCID of the current compartment.

    Returns:
        The formated list as string
    
Returns a formated list of instances.
If compartment_id is given, the current and parent compartment
will be listed as well.
Returns a formated list of instances . If compartment_id is given the current and parent compartment will be listed as well .
def format_instance_listing(items, current=None, vnics=None,
                            config=None):
    import re
    import oci.core.models
    if not type(items) is list:
        items = [items]
    out = ""
    i = 1
    for c in items:
        name = re.sub(r'[\n\r]', ' ',
                      c.display_name[:22] + '..'
                      if len(c.display_name) > 24
                      else c.display_name)
        public_ip = ""
        private_ip = ""
        if vnics and c.lifecycle_state in [
                oci.core.models.Instance.LIFECYCLE_STATE_RUNNING,
                oci.core.models.Instance.LIFECYCLE_STATE_STARTING,
                oci.core.models.Instance.LIFECYCLE_STATE_STOPPED,
                oci.core.models.Instance.LIFECYCLE_STATE_STOPPING]:
            instance_vnics = [v for v in vnics if v.instance_id == c.id]
            if len(instance_vnics) > 0:
                virtual_network = core.get_oci_virtual_network_client(
                    config=config)
                try:
                    vnic = virtual_network.get_vnic(
                        instance_vnics[0].vnic_id).data
                    public_ip = vnic.public_ip \
                        if vnic.public_ip else ''
                    private_ip = vnic.private_ip \
                        if vnic.private_ip else ''
                except oci.exceptions.ServiceError as e:
                    if e.code == "NotAuthorizedOrNotFound":
                        pass
        index = f"*{i:>3}" if current == c.id else f"{i:>4}"
        out += (f"{index} {name:24} {c.shape[:22]:22} {c.fault_domain[:15]:15} "
                f"{public_ip if public_ip != '' else private_ip:15} "
                f"{c.lifecycle_state}\n")
        i += 1
    return out
def format_instance_listing ( items , current = None , vnics = None , config = None ) : import re import oci . core . models if not type ( items ) is list : items = [ items ] out = "" i = 1 for c in items : name = re . sub ( r'[\n\r]' , ' ' , c . display_name [ : 22 ] + '..' if len ( c . display_name ) > 24 else c . display_name ) public_ip = "" private_ip = "" if vnics and c . lifecycle_state in [ oci . core . models . Instance . LIFECYCLE_STATE_RUNNING , oci . core . models . Instance . LIFECYCLE_STATE_STARTING , oci . core . models . Instance . LIFECYCLE_STATE_STOPPED , oci . core . models . Instance . LIFECYCLE_STATE_STOPPING ] : instance_vnics = [ v for v in vnics if v . instance_id == c . id ] if len ( instance_vnics ) > 0 : virtual_network = core . get_oci_virtual_network_client ( config = config ) try : vnic = virtual_network . get_vnic ( instance_vnics [ 0 ] . vnic_id ) . data public_ip = vnic . public_ip if vnic . public_ip else '' private_ip = vnic . private_ip if vnic . private_ip else '' except oci . exceptions . ServiceError as e : if e . code == "NotAuthorizedOrNotFound" : pass index = f"*{i:>3}" if current == c . id else f"{i:>4}" out += ( f"{index} {name:24} {c.shape[:22]:22} {c.fault_domain[:15]:15} " f"{public_ip if public_ip != '' else private_ip:15} " f"{c.lifecycle_state}\n" ) i += 1 return out
Returns a formated list of instances.
Returns a formated list of instances .
"""Returns a formated list of instances.

    If compartment_id is given, the current and parent compartment
    will be listed as well.

    Args:
        data (list): A list of instance objects.
        config (object): An OCI config object or None.
        compartment_id (str): The OCID of the current compartment.

    Returns:
        The formated list as string
    """ # If a single item was given, wrap it in a list
 # return compartments in READABLE text output
 # Shorten to 24 chars max, remove linebreaks
 # Get public IP
 # Ignore NotFound error

The formated list as string
The formated list as string
items
current
vnics
config
An OCI config object or None.
An OCI config object or None .
data
A list of instance objects.
A list of instance objects .
compartment_id
The OCID of the current compartment.
The OCID of the current compartment .