mds_plugin/compute.py
def add_ingress_port_to_security_lists(**kwargs):
    """Checks if the given ingress port already is a security list,
    if not it gets added.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        security_lists (list): A list of security_lists.
        port (int): The port to check
        description (str): A description for the ingress rule
        compartment_id (str): The OCID of the compartment
        config (object): An OCI config object or None.
        config_profile (str): The name of an OCI config profile
        interactive (bool): Indicates whether to execute in interactive mode
        raise_exceptions (bool): If true exceptions are raised

    Returns:
       True on success
    """

    security_lists = kwargs.get("security_lists")
    port = kwargs.get("port")
    description = kwargs.get("description")

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

    if security_lists is None:
        raise ValueError("No security_lists given.")

    try:
        # Get the active config and compartment
        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)

        for sec_list in security_lists:
            for rule in sec_list.ingress_security_rules:
                if rule.tcp_options is not None and \
                        port >= rule.tcp_options.destination_port_range.min and \
                        port <= rule.tcp_options.destination_port_range.max and \
                        rule.protocol == "6" and \
                        rule.source == "0.0.0.0/0":
                    return True

        if len(security_lists) == 0:
            raise Exception("No security list available for this network.")
        sec_list = security_lists[0]

        import oci.exceptions

        try:
            network_client = core.get_oci_virtual_network_client(
                config=config)

            sec_list.ingress_security_rules.append(
                oci.core.models.IngressSecurityRule(
                    protocol="6",
                    source="0.0.0.0/0",
                    is_stateless=False,
                    source_type="CIDR_BLOCK",
                    tcp_options=oci.core.models.TcpOptions(
                        destination_port_range=oci.core.models.PortRange(
                            max=port,
                            min=port),
                        source_port_range=None),
                    udp_options=None,
                    description=description
                )
            )

            details = oci.core.models.UpdateSecurityListDetails(
                defined_tags=sec_list.defined_tags,
                display_name=sec_list.display_name,
                egress_security_rules=sec_list.egress_security_rules,
                freeform_tags=sec_list.freeform_tags,
                ingress_security_rules=sec_list.ingress_security_rules
            )

            network_client.update_security_list(
                security_list_id=sec_list.id,
                update_security_list_details=details)

            return True

        except oci.exceptions.ServiceError as e:
            if raise_exceptions:
                raise
            print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
    except Exception as e:
        if raise_exceptions:
            raise
        print(f'Could not list the availability domains for this '
              f'compartment.\nERROR: {str(e)}')
Checks if the given ingress port already is a security list,
    if not it gets added.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        security_lists (list): A list of security_lists.
        port (int): The port to check
        description (str): A description for the ingress rule
        compartment_id (str): The OCID of the compartment
        config (object): An OCI config object or None.
        config_profile (str): The name of an OCI config profile
        interactive (bool): Indicates whether to execute in interactive mode
        raise_exceptions (bool): If true exceptions are raised

    Returns:
       True on success
    
Checks if the given ingress port already is a security list,
if not it gets added.
Checks if the given ingress port already is a security list if not it gets added .
def add_ingress_port_to_security_lists(**kwargs):
    security_lists = kwargs.get("security_lists")
    port = kwargs.get("port")
    description = kwargs.get("description")
    compartment_id = kwargs.get("compartment_id")
    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)
    if security_lists is None:
        raise ValueError("No security_lists given.")
    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)
        for sec_list in security_lists:
            for rule in sec_list.ingress_security_rules:
                if rule.tcp_options is not None and \
                        port >= rule.tcp_options.destination_port_range.min and \
                        port <= rule.tcp_options.destination_port_range.max and \
                        rule.protocol == "6" and \
                        rule.source == "0.0.0.0/0":
                    return True
        if len(security_lists) == 0:
            raise Exception("No security list available for this network.")
        sec_list = security_lists[0]
        import oci.exceptions
        try:
            network_client = core.get_oci_virtual_network_client(
                config=config)
            sec_list.ingress_security_rules.append(
                oci.core.models.IngressSecurityRule(
                    protocol="6",
                    source="0.0.0.0/0",
                    is_stateless=False,
                    source_type="CIDR_BLOCK",
                    tcp_options=oci.core.models.TcpOptions(
                        destination_port_range=oci.core.models.PortRange(
                            max=port,
                            min=port),
                        source_port_range=None),
                    udp_options=None,
                    description=description
                )
            )
            details = oci.core.models.UpdateSecurityListDetails(
                defined_tags=sec_list.defined_tags,
                display_name=sec_list.display_name,
                egress_security_rules=sec_list.egress_security_rules,
                freeform_tags=sec_list.freeform_tags,
                ingress_security_rules=sec_list.ingress_security_rules
            )
            network_client.update_security_list(
                security_list_id=sec_list.id,
                update_security_list_details=details)
            return True
        except oci.exceptions.ServiceError as e:
            if raise_exceptions:
                raise
            print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
    except Exception as e:
        if raise_exceptions:
            raise
        print(f'Could not list the availability domains for this '
              f'compartment.\nERROR: {str(e)}')
def add_ingress_port_to_security_lists ( ** kwargs ) : security_lists = kwargs . get ( "security_lists" ) port = kwargs . get ( "port" ) description = kwargs . get ( "description" ) compartment_id = kwargs . get ( "compartment_id" ) 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 ) if security_lists is None : raise ValueError ( "No security_lists given." ) 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 ) for sec_list in security_lists : for rule in sec_list . ingress_security_rules : if rule . tcp_options is not None and port >= rule . tcp_options . destination_port_range . min and port <= rule . tcp_options . destination_port_range . max and rule . protocol == "6" and rule . source == "0.0.0.0/0" : return True if len ( security_lists ) == 0 : raise Exception ( "No security list available for this network." ) sec_list = security_lists [ 0 ] import oci . exceptions try : network_client = core . get_oci_virtual_network_client ( config = config ) sec_list . ingress_security_rules . append ( oci . core . models . IngressSecurityRule ( protocol = "6" , source = "0.0.0.0/0" , is_stateless = False , source_type = "CIDR_BLOCK" , tcp_options = oci . core . models . TcpOptions ( destination_port_range = oci . core . models . PortRange ( max = port , min = port ) , source_port_range = None ) , udp_options = None , description = description ) ) details = oci . core . models . UpdateSecurityListDetails ( defined_tags = sec_list . defined_tags , display_name = sec_list . display_name , egress_security_rules = sec_list . egress_security_rules , freeform_tags = sec_list . freeform_tags , ingress_security_rules = sec_list . ingress_security_rules ) network_client . update_security_list ( security_list_id = sec_list . id , update_security_list_details = details ) return True except oci . exceptions . ServiceError as e : if raise_exceptions : raise print ( f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})' ) except Exception as e : if raise_exceptions : raise print ( f'Could not list the availability domains for this ' f'compartment.\nERROR: {str(e)}' )
Checks if the given ingress port already is a security list,
if not it gets added.
Checks if the given ingress port already is a security list if not it gets added .
"""Checks if the given ingress port already is a security list,
    if not it gets added.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        security_lists (list): A list of security_lists.
        port (int): The port to check
        description (str): A description for the ingress rule
        compartment_id (str): The OCID of the compartment
        config (object): An OCI config object or None.
        config_profile (str): The name of an OCI config profile
        interactive (bool): Indicates whether to execute in interactive mode
        raise_exceptions (bool): If true exceptions are raised

    Returns:
       True on success
    """ # Get the active config and compartment

True on success
True on success
**kwargs
None