libcloud/compute/drivers/dimensiondata.py [2150:2314]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            id=rule_id,
            network_domain=network_domain,
            internal_ip=internal_ip,
            external_ip=external_ip,
            status=NodeState.RUNNING,
        )

    def ex_list_nat_rules(self, network_domain):
        """
        Get NAT rules for the network domain

        :param  network_domain: The network domain the rules belongs to
        :type   network_domain: :class:`DimensionDataNetworkDomain`

        :rtype: ``list`` of :class:`DimensionDataNatRule`
        """
        params = {}
        params["networkDomainId"] = network_domain.id

        response = self.connection.request_with_orgId_api_2("network/natRule", params=params).object
        return self._to_nat_rules(response, network_domain)

    def ex_get_nat_rule(self, network_domain, rule_id):
        """
        Get a NAT rule by ID

        :param  network_domain: The network domain the rule belongs to
        :type   network_domain: :class:`DimensionDataNetworkDomain`

        :param  rule_id: The ID of the NAT rule to fetch
        :type   rule_id: ``str``

        :rtype: :class:`DimensionDataNatRule`
        """
        rule = self.connection.request_with_orgId_api_2("network/natRule/%s" % rule_id).object
        return self._to_nat_rule(rule, network_domain)

    def ex_delete_nat_rule(self, rule):
        """
        Delete an existing NAT rule

        :param  rule: The rule to delete
        :type   rule: :class:`DimensionDataNatRule`

        :rtype: ``bool``
        """
        update_node = ET.Element("deleteNatRule", {"xmlns": TYPES_URN})
        update_node.set("id", rule.id)
        result = self.connection.request_with_orgId_api_2(
            "network/deleteNatRule", method="POST", data=ET.tostring(update_node)
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)
        return response_code in ["IN_PROGRESS", "OK"]

    def ex_get_location_by_id(self, id):
        """
        Get location by ID.

        :param  id: ID of the node location which should be used
        :type   id: ``str``

        :rtype: :class:`NodeLocation`
        """
        location = None
        if id is not None:
            location = self.list_locations(ex_id=id)[0]
        return location

    def ex_wait_for_state(self, state, func, poll_interval=2, timeout=60, *args, **kwargs):
        """
        Wait for the function which returns a instance
        with field status to match

        Keep polling func until one of the desired states is matched

        :param state: Either the desired state (`str`) or a `list` of states
        :type  state: ``str`` or ``list``

        :param  func: The function to call, e.g. ex_get_vlan
        :type   func: ``function``

        :param  poll_interval: The number of seconds to wait between checks
        :type   poll_interval: `int`

        :param  timeout: The total number of seconds to wait to reach a state
        :type   timeout: `int`

        :param  args: The arguments for func
        :type   args: Positional arguments

        :param  kwargs: The arguments for func
        :type   kwargs: Keyword arguments
        """
        return self.connection.wait_for_state(state, func, poll_interval, timeout, *args, **kwargs)

    def ex_enable_monitoring(self, node, service_plan="ESSENTIALS"):
        """
        Enables cloud monitoring on a node

        :param   node: The node to monitor
        :type    node: :class:`Node`

        :param   service_plan: The service plan, one of ESSENTIALS or
                               ADVANCED
        :type    service_plan: ``str``

        :rtype: ``bool``
        """
        update_node = ET.Element("enableServerMonitoring", {"xmlns": TYPES_URN})
        update_node.set("id", node.id)
        ET.SubElement(update_node, "servicePlan").text = service_plan
        result = self.connection.request_with_orgId_api_2(
            "server/enableServerMonitoring",
            method="POST",
            data=ET.tostring(update_node),
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)
        return response_code in ["IN_PROGRESS", "OK"]

    def ex_update_monitoring_plan(self, node, service_plan="ESSENTIALS"):
        """
        Updates the service plan on a node with monitoring

        :param   node: The node to monitor
        :type    node: :class:`Node`

        :param   service_plan: The service plan, one of ESSENTIALS or
                               ADVANCED
        :type    service_plan: ``str``

        :rtype: ``bool``
        """
        update_node = ET.Element("changeServerMonitoringPlan", {"xmlns": TYPES_URN})
        update_node.set("id", node.id)
        ET.SubElement(update_node, "servicePlan").text = service_plan
        result = self.connection.request_with_orgId_api_2(
            "server/changeServerMonitoringPlan",
            method="POST",
            data=ET.tostring(update_node),
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)
        return response_code in ["IN_PROGRESS", "OK"]

    def ex_disable_monitoring(self, node):
        """
        Disables cloud monitoring for a node

        :param   node: The node to stop monitoring
        :type    node: :class:`Node`

        :rtype: ``bool``
        """
        update_node = ET.Element("disableServerMonitoring", {"xmlns": TYPES_URN})
        update_node.set("id", node.id)
        result = self.connection.request_with_orgId_api_2(
            "server/disableServerMonitoring",
            method="POST",
            data=ET.tostring(update_node),
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)
        return response_code in ["IN_PROGRESS", "OK"]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



libcloud/compute/drivers/nttcis.py [2728:2908]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            id=rule_id,
            network_domain=network_domain,
            internal_ip=internal_ip,
            external_ip=external_ip,
            status=NodeState.RUNNING,
        )

    def ex_list_nat_rules(self, network_domain):
        """
        Get NAT rules for the network domain

        :param  network_domain: The network domain the rules belongs to
        :type   network_domain: :class:`NttCisNetworkDomain`

        :rtype: ``list`` of :class:`NttCisNatRule`
        """

        params = {}
        params["networkDomainId"] = network_domain.id

        response = self.connection.request_with_orgId_api_2("network/natRule", params=params).object

        return self._to_nat_rules(response, network_domain)

    def ex_get_nat_rule(self, network_domain, rule_id):
        """
        Get a NAT rule by ID

        :param  network_domain: The network domain the rule belongs to
        :type   network_domain: :class:`NttCisNetworkDomain`

        :param  rule_id: The ID of the NAT rule to fetch
        :type   rule_id: ``str``

        :rtype: :class:`NttCisNatRule`
        """

        rule = self.connection.request_with_orgId_api_2("network/natRule/%s" % rule_id).object

        return self._to_nat_rule(rule, network_domain)

    def ex_delete_nat_rule(self, rule):
        """
        Delete an existing NAT rule

        :param  rule: The rule to delete
        :type   rule: :class:`NttCisNatRule`

        :rtype: ``bool``
        """

        update_node = ET.Element("deleteNatRule", {"xmlns": TYPES_URN})
        update_node.set("id", rule.id)
        result = self.connection.request_with_orgId_api_2(
            "network/deleteNatRule", method="POST", data=ET.tostring(update_node)
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)

        return response_code in ["IN_PROGRESS", "OK"]

    def ex_get_location_by_id(self, id):
        """
        Get location by ID.

        :param  id: ID of the node location which should be used
        :type   id: ``str``

        :rtype: :class:`NodeLocation`
        """

        location = None

        if id is not None:
            location = self.list_locations(ex_id=id)[0]

        return location

    def ex_wait_for_state(self, state, func, poll_interval=2, timeout=60, *args, **kwargs):
        """
        Wait for the function which returns a instance
        with field status to match

        Keep polling func until one of the desired states is matched

        :param state: Either the desired state (`str`) or a `list` of states
        :type  state: ``str`` or ``list``

        :param  func: The function to call, e.g. ex_get_vlan
        :type   func: ``function``

        :param  poll_interval: The number of seconds to wait between checks
        :type   poll_interval: `int`

        :param  timeout: The total number of seconds to wait to reach a state
        :type   timeout: `int`

        :param  args: The arguments for func
        :type   args: Positional arguments

        :param  kwargs: The arguments for func
        :type   kwargs: Keyword arguments
        """

        return self.connection.wait_for_state(state, func, poll_interval, timeout, *args, **kwargs)

    def ex_enable_monitoring(self, node, service_plan="ESSENTIALS"):
        """
        Enables cloud monitoring on a node

        :param   node: The node to monitor
        :type    node: :class:`Node`

        :param   service_plan: The service plan, one of ESSENTIALS or
                               ADVANCED
        :type    service_plan: ``str``

        :rtype: ``bool``
        """

        update_node = ET.Element("enableServerMonitoring", {"xmlns": TYPES_URN})
        update_node.set("id", node.id)
        ET.SubElement(update_node, "servicePlan").text = service_plan
        result = self.connection.request_with_orgId_api_2(
            "server/enableServerMonitoring",
            method="POST",
            data=ET.tostring(update_node),
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)

        return response_code in ["IN_PROGRESS", "OK"]

    def ex_update_monitoring_plan(self, node, service_plan="ESSENTIALS"):
        """
        Updates the service plan on a node with monitoring

        :param   node: The node to monitor
        :type    node: :class:`Node`

        :param   service_plan: The service plan, one of ESSENTIALS or
                               ADVANCED
        :type    service_plan: ``str``

        :rtype: ``bool``
        """

        update_node = ET.Element("changeServerMonitoringPlan", {"xmlns": TYPES_URN})
        update_node.set("id", node.id)
        ET.SubElement(update_node, "servicePlan").text = service_plan
        result = self.connection.request_with_orgId_api_2(
            "server/changeServerMonitoringPlan",
            method="POST",
            data=ET.tostring(update_node),
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)

        return response_code in ["IN_PROGRESS", "OK"]

    def ex_disable_monitoring(self, node):
        """
        Disables cloud monitoring for a node

        :param   node: The node to stop monitoring
        :type    node: :class:`Node`

        :rtype: ``bool``
        """

        update_node = ET.Element("disableServerMonitoring", {"xmlns": TYPES_URN})
        update_node.set("id", node.id)
        result = self.connection.request_with_orgId_api_2(
            "server/disableServerMonitoring",
            method="POST",
            data=ET.tostring(update_node),
        ).object

        response_code = findtext(result, "responseCode", TYPES_URN)

        return response_code in ["IN_PROGRESS", "OK"]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



