mds_plugin/network.py
def list_subnets(**kwargs):
    """Lists all subnets of the given network

    Args:
        **kwargs: Additional options

    Keyword Args:
        network_id (str): The OCID of the parent network_id
        public_subnet (bool): Whether only public subnets should be considered
        availability_domain (str): The name if the availability_domain
        ignore_current_network (bool): Whether to ignore the current network
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): Whether to query the user for input
        return_formatted (bool): If set to true, a list object is returned.

    Returns:
        A list of subnets
    """

    network_id = kwargs.get("network_id")
    public_subnet = kwargs.get("public_subnet")
    # availability_domain = kwargs.get("availability_domain")
    ignore_current_network = kwargs.get("ignore_current_network")
    compartment_id = kwargs.get("compartment_id")
    config = kwargs.get("config")
    interactive = kwargs.get("interactive", True)
    return_formatted = kwargs.get("return_formatted", 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)
        if not ignore_current_network:
            network_id = configuration.get_current_network_id(
                network_id=network_id, config=config)

        import oci.exceptions
        from mds_plugin import compartment

        # Create VirtualNetworkClient
        virtual_network = core.get_oci_virtual_network_client(
            config=config)

        # If a subnet_id was given, return the subnet of that subnet_id
        # if subnet_id is not None:
        #     try:
        #         return virtual_network.get_subnet(subnet_id=subnet_id).data
        #     except oci.exceptions.ServiceError as e:
        #         print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        #         return
        #     except (ValueError, oci.exceptions.ClientError) as e:
        #         print(f'ERROR: {e}')
        #         return

        network = get_network(network_id=network_id,
                              compartment_id=compartment_id, config=config,
                              public_subnet=public_subnet, interactive=interactive)
        if network is None:
            return
        network_name = network.display_name if network.display_name else \
            network.id
        network_compartment = network.compartment_id

        # Get the compartment
        compartment = compartment.get_compartment_by_id(
            compartment_id=network_compartment, config=config)
        if compartment is None:
            return

        # If no availability_domain was specified, use a random one
        # if availability_domain is None:
        #     availability_domain = compartment.get_availability_domain(
        #         compartment_id=compartment_id,
        #         availability_domain=availability_domain, config=config)

        subnets = virtual_network.list_subnets(
            compartment_id=network_compartment, vcn_id=network.id).data

        # Filter subnets by Availability Domain, None means the subnet
        # spans across all Availability Domains
        # subnets = [s for s in subnets
        #            if s.availability_domain == availability_domain or
        #            s.availability_domain is None]

        # Filter out all sub-nets that are not conforming to the
        # public_subnet options
        if public_subnet is not None and public_subnet:
            out = "All public "
            subnets = [s for s in subnets
                       if subnet_is_public(subnet=s, config=config)]
        elif public_subnet is not None and not public_subnet:
            out = "All private "
            subnets = [s for s in subnets
                       if not subnet_is_public(subnet=s, config=config)]
        else:
            out = "All "

        out += f"subnets of Network '{network_name}' in compartment " + \
            f"'{compartment.name}':\n\n"

        if return_formatted:
            return out + format_subnet_listing(subnets)
        else:
            return oci.util.to_dict(subnets)

    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except (ValueError, oci.exceptions.ClientError) as e:
        print(f'ERROR: {e}')
        return
Lists all subnets of the given network

    Args:
        **kwargs: Additional options

    Keyword Args:
        network_id (str): The OCID of the parent network_id
        public_subnet (bool): Whether only public subnets should be considered
        availability_domain (str): The name if the availability_domain
        ignore_current_network (bool): Whether to ignore the current network
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): Whether to query the user for input
        return_formatted (bool): If set to true, a list object is returned.

    Returns:
        A list of subnets
    
Lists all subnets of the given network
Lists all subnets of the given network
def list_subnets(**kwargs):
    network_id = kwargs.get("network_id")
    public_subnet = kwargs.get("public_subnet")
    ignore_current_network = kwargs.get("ignore_current_network")
    compartment_id = kwargs.get("compartment_id")
    config = kwargs.get("config")
    interactive = kwargs.get("interactive", True)
    return_formatted = kwargs.get("return_formatted", True)
    try:
        config = configuration.get_current_config(config=config)
        if not ignore_current_network:
            network_id = configuration.get_current_network_id(
                network_id=network_id, config=config)
        import oci.exceptions
        from mds_plugin import compartment
        virtual_network = core.get_oci_virtual_network_client(
            config=config)
        network = get_network(network_id=network_id,
                              compartment_id=compartment_id, config=config,
                              public_subnet=public_subnet, interactive=interactive)
        if network is None:
            return
        network_name = network.display_name if network.display_name else \
            network.id
        network_compartment = network.compartment_id
        compartment = compartment.get_compartment_by_id(
            compartment_id=network_compartment, config=config)
        if compartment is None:
            return
        subnets = virtual_network.list_subnets(
            compartment_id=network_compartment, vcn_id=network.id).data
        if public_subnet is not None and public_subnet:
            out = "All public "
            subnets = [s for s in subnets
                       if subnet_is_public(subnet=s, config=config)]
        elif public_subnet is not None and not public_subnet:
            out = "All private "
            subnets = [s for s in subnets
                       if not subnet_is_public(subnet=s, config=config)]
        else:
            out = "All "
        out += f"subnets of Network '{network_name}' in compartment " + \
            f"'{compartment.name}':\n\n"
        if return_formatted:
            return out + format_subnet_listing(subnets)
        else:
            return oci.util.to_dict(subnets)
    except oci.exceptions.ServiceError as e:
        print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
        return
    except (ValueError, oci.exceptions.ClientError) as e:
        print(f'ERROR: {e}')
        return
def list_subnets ( ** kwargs ) : network_id = kwargs . get ( "network_id" ) public_subnet = kwargs . get ( "public_subnet" ) ignore_current_network = kwargs . get ( "ignore_current_network" ) compartment_id = kwargs . get ( "compartment_id" ) config = kwargs . get ( "config" ) interactive = kwargs . get ( "interactive" , True ) return_formatted = kwargs . get ( "return_formatted" , True ) try : config = configuration . get_current_config ( config = config ) if not ignore_current_network : network_id = configuration . get_current_network_id ( network_id = network_id , config = config ) import oci . exceptions from mds_plugin import compartment virtual_network = core . get_oci_virtual_network_client ( config = config ) network = get_network ( network_id = network_id , compartment_id = compartment_id , config = config , public_subnet = public_subnet , interactive = interactive ) if network is None : return network_name = network . display_name if network . display_name else network . id network_compartment = network . compartment_id compartment = compartment . get_compartment_by_id ( compartment_id = network_compartment , config = config ) if compartment is None : return subnets = virtual_network . list_subnets ( compartment_id = network_compartment , vcn_id = network . id ) . data if public_subnet is not None and public_subnet : out = "All public " subnets = [ s for s in subnets if subnet_is_public ( subnet = s , config = config ) ] elif public_subnet is not None and not public_subnet : out = "All private " subnets = [ s for s in subnets if not subnet_is_public ( subnet = s , config = config ) ] else : out = "All " out += f"subnets of Network '{network_name}' in compartment " + f"'{compartment.name}':\n\n" if return_formatted : return out + format_subnet_listing ( subnets ) else : return oci . util . to_dict ( subnets ) except oci . exceptions . ServiceError as e : print ( f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})' ) return except ( ValueError , oci . exceptions . ClientError ) as e : print ( f'ERROR: {e}' ) return
Lists all subnets of the given network
Lists all subnets of the given network
"""Lists all subnets of the given network

    Args:
        **kwargs: Additional options

    Keyword Args:
        network_id (str): The OCID of the parent network_id
        public_subnet (bool): Whether only public subnets should be considered
        availability_domain (str): The name if the availability_domain
        ignore_current_network (bool): Whether to ignore the current network
        compartment_id (str): OCID of the parent compartment.
        config (object): An OCI config object or None.
        interactive (bool): Whether to query the user for input
        return_formatted (bool): If set to true, a list object is returned.

    Returns:
        A list of subnets
    """ # availability_domain = kwargs.get("availability_domain")
 # Get the active config and compartment
 # compartment_id = configuration.get_current_compartment_id(
 #     compartment_id=compartment_id, config=config)
 # Create VirtualNetworkClient
 # If a subnet_id was given, return the subnet of that subnet_id
 # if subnet_id is not None:
 #     try:
 #         return virtual_network.get_subnet(subnet_id=subnet_id).data
 #     except oci.exceptions.ServiceError as e:
 #         print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
 #         return
 #     except (ValueError, oci.exceptions.ClientError) as e:
 #         print(f'ERROR: {e}')
 #         return
 # Get the compartment
 # If no availability_domain was specified, use a random one
 # if availability_domain is None:
 #     availability_domain = compartment.get_availability_domain(
 #         compartment_id=compartment_id,
 #         availability_domain=availability_domain, config=config)
 # Filter subnets by Availability Domain, None means the subnet
 # spans across all Availability Domains
 # subnets = [s for s in subnets
 #            if s.availability_domain == availability_domain or
 #            s.availability_domain is None]
 # Filter out all sub-nets that are not conforming to the
 # public_subnet options

A list of subnets
A list of subnets
**kwargs
None