libcloud/compute/drivers/dimensiondata.py [1252:1535]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        return response_code in ["IN_PROGRESS", "SUCCESS"]

    def ex_list_anti_affinity_rules(
        self,
        network=None,
        network_domain=None,
        node=None,
        filter_id=None,
        filter_state=None,
    ):
        """
        List anti affinity rules for a network, network domain, or node

        :param network: The network to list anti affinity rules for
                        One of network, network_domain, or node is required
        :type  network: :class:`DimensionDataNetwork` or ``str``

        :param network_domain: The network domain to list anti affinity rules
                               One of network, network_domain,
                               or node is required
        :type  network_domain: :class:`DimensionDataNetworkDomain` or ``str``

        :param node: The node to list anti affinity rules for
                     One of network, netwok_domain, or node is required
        :type  node: :class:`Node` or ``str``

        :param filter_id: This will allow you to filter the rules
                          by this node id
        :type  filter_id: ``str``

        :type  filter_state: This will allow you to filter rules by
                             node state (i.e. NORMAL)
        :type  filter_state: ``str``

        :rtype: ``list`` of :class:`DimensionDataAntiAffinityRule`
        """
        not_none_arguments = [key for key in (network, network_domain, node) if key is not None]
        if len(not_none_arguments) != 1:
            raise ValueError("One and ONLY one of network, " "network_domain, or node must be set")

        params = {}
        if network_domain is not None:
            params["networkDomainId"] = self._network_domain_to_network_domain_id(network_domain)
        if network is not None:
            params["networkId"] = self._network_to_network_id(network)
        if node is not None:
            params["serverId"] = self._node_to_node_id(node)
        if filter_id is not None:
            params["id"] = filter_id
        if filter_state is not None:
            params["state"] = filter_state

        paged_result = self.connection.paginated_request_with_orgId_api_2(
            "server/antiAffinityRule", method="GET", params=params
        )

        rules = []
        for result in paged_result:
            rules.extend(self._to_anti_affinity_rules(result))
        return rules

    def ex_attach_node_to_vlan(self, node, vlan=None, private_ipv4=None):
        """
        Attach a node to a VLAN by adding an additional NIC to
        the node on the target VLAN. The IP will be automatically
        assigned based on the VLAN IP network space. Alternatively, provide
        a private IPv4 address instead of VLAN information, and this will
        be assigned to the node on corresponding NIC.

        :param      node: Node which should be used
        :type       node: :class:`Node`

        :param      vlan: VLAN to attach the node to
                          (required unless private_ipv4)
        :type       vlan: :class:`DimensionDataVlan`

        :keyword    private_ipv4: Private nic IPv4 Address
                                  (required unless vlan)
        :type       private_ipv4: ``str``

        :rtype: ``bool``
        """
        request = ET.Element("addNic", {"xmlns": TYPES_URN})
        ET.SubElement(request, "serverId").text = node.id
        nic = ET.SubElement(request, "nic")

        if vlan is not None:
            ET.SubElement(nic, "vlanId").text = vlan.id
        elif private_ipv4 is not None:
            ET.SubElement(nic, "privateIpv4").text = private_ipv4
        else:
            raise ValueError("One of vlan or primary_ipv4 " "must be specified")

        response = self.connection.request_with_orgId_api_2(
            "server/addNic", method="POST", data=ET.tostring(request)
        ).object
        response_code = findtext(response, "responseCode", TYPES_URN)
        return response_code in ["IN_PROGRESS", "OK"]

    def ex_destroy_nic(self, nic_id):
        """
        Remove a NIC on a node, removing the node from a VLAN

        :param      nic_id: The identifier of the NIC to remove
        :type       nic_id: ``str``

        :rtype: ``bool``
        """
        request = ET.Element("removeNic", {"xmlns": TYPES_URN, "id": nic_id})

        response = self.connection.request_with_orgId_api_2(
            "server/removeNic", method="POST", data=ET.tostring(request)
        ).object
        response_code = findtext(response, "responseCode", TYPES_URN)
        return response_code in ["IN_PROGRESS", "OK"]

    def ex_list_networks(self, location=None):
        """
        List networks deployed across all data center locations for your
        organization.  The response includes the location of each network.

        :param location: The target location
        :type  location: :class:`NodeLocation` or ``str``

        :return: a list of DimensionDataNetwork objects
        :rtype: ``list`` of :class:`DimensionDataNetwork`
        """
        return self.list_networks(location=location)

    def ex_create_network(self, location, name, description=None):
        """
        Create a new network in an MCP 1.0 location

        :param   location: The target location (MCP1)
        :type    location: :class:`NodeLocation` or ``str``

        :param   name: The name of the network
        :type    name: ``str``

        :param   description: Additional description of the network
        :type    description: ``str``

        :return: A new instance of `DimensionDataNetwork`
        :rtype:  Instance of :class:`DimensionDataNetwork`
        """
        network_location = self._location_to_location_id(location)

        create_node = ET.Element("NewNetworkWithLocation", {"xmlns": NETWORK_NS})
        ET.SubElement(create_node, "name").text = name
        if description is not None:
            ET.SubElement(create_node, "description").text = description
        ET.SubElement(create_node, "location").text = network_location

        self.connection.request_with_orgId_api_1(
            "networkWithLocation", method="POST", data=ET.tostring(create_node)
        )

        # MCP1 API does not return the ID, but name is unique for location
        network = list(filter(lambda x: x.name == name, self.ex_list_networks(location)))[0]

        return network

    def ex_delete_network(self, network):
        """
        Delete a network from an MCP 1 data center

        :param  network: The network to delete
        :type   network: :class:`DimensionDataNetwork`

        :rtype: ``bool``
        """
        response = self.connection.request_with_orgId_api_1(
            "network/%s?delete" % network.id, method="GET"
        ).object
        response_code = findtext(response, "result", GENERAL_NS)
        return response_code == "SUCCESS"

    def ex_rename_network(self, network, new_name):
        """
        Rename a network in MCP 1 data center

        :param  network: The network to rename
        :type   network: :class:`DimensionDataNetwork`

        :param  new_name: The new name of the network
        :type   new_name: ``str``

        :rtype: ``bool``
        """
        response = self.connection.request_with_orgId_api_1(
            "network/%s" % network.id, method="POST", data="name=%s" % new_name
        ).object
        response_code = findtext(response, "result", GENERAL_NS)
        return response_code == "SUCCESS"

    def ex_get_network_domain(self, network_domain_id):
        """
        Get an individual Network Domain, by identifier

        :param      network_domain_id: The identifier of the network domain
        :type       network_domain_id: ``str``

        :rtype: :class:`DimensionDataNetworkDomain`
        """
        locations = self.list_locations()
        net = self.connection.request_with_orgId_api_2(
            "network/networkDomain/%s" % network_domain_id
        ).object
        return self._to_network_domain(net, locations)

    def ex_list_network_domains(self, location=None, name=None, service_plan=None, state=None):
        """
        List networks domains deployed across all data center locations domain.

        for your organization.
        The response includes the location of each network
        :param      location: Only network domains in the location (optional)
        :type       location: :class:`NodeLocation` or ``str``

        :param      name: Only network domains of this name (optional)
        :type       name: ``str``

        :param      service_plan: Only network domains of this type (optional)
        :type       service_plan: ``str``

        :param      state: Only network domains in this state (optional)
        :type       state: ``str``

        :return: a list of `DimensionDataNetwork` objects
        :rtype: ``list`` of :class:`DimensionDataNetwork`
        """
        params = {}
        if location is not None:
            params["datacenterId"] = self._location_to_location_id(location)
        if name is not None:
            params["name"] = name
        if service_plan is not None:
            params["type"] = service_plan
        if state is not None:
            params["state"] = state

        response = self.connection.request_with_orgId_api_2(
            "network/networkDomain", params=params
        ).object
        return self._to_network_domains(response)

    def ex_create_network_domain(self, location, name, service_plan, description=None):
        """
        Deploy a new network domain to a data center

        :param      location: The data center to list
        :type       location: :class:`NodeLocation` or ``str``

        :param      name: The name of the network domain to create
        :type       name: ``str``

        :param      service_plan: The service plan, either "ESSENTIALS"
            or "ADVANCED"
        :type       service_plan: ``str``

        :param      description: An additional description of
                                 the network domain
        :type       description: ``str``

        :return: an instance of `DimensionDataNetworkDomain`
        :rtype: :class:`DimensionDataNetworkDomain`
        """
        create_node = ET.Element("deployNetworkDomain", {"xmlns": TYPES_URN})
        ET.SubElement(create_node, "datacenterId").text = self._location_to_location_id(location)

        ET.SubElement(create_node, "name").text = name
        if description is not None:
            ET.SubElement(create_node, "description").text = description
        ET.SubElement(create_node, "type").text = service_plan

        response = self.connection.request_with_orgId_api_2(
            "network/deployNetworkDomain", method="POST", data=ET.tostring(create_node)
        ).object

        network_domain_id = None

        for info in findall(response, "info", TYPES_URN):
            if info.get("name") == "networkDomainId":
                network_domain_id = info.get("value")
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



libcloud/compute/drivers/nttcis.py [1617:1930]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        return response_code in ["IN_PROGRESS", "SUCCESS"]

    def ex_list_anti_affinity_rules(
        self,
        network=None,
        network_domain=None,
        node=None,
        filter_id=None,
        filter_state=None,
    ):
        """
        List anti affinity rules for a network, network domain, or node

        :param network: The network to list anti affinity rules for
                        One of network, network_domain, or node is required
        :type  network: :class:`NttCisNetwork` or ``str``

        :param network_domain: The network domain to list anti affinity rules
                               One of network, network_domain,
                               or node is required
        :type  network_domain: :class:`NttCisNetworkDomain` or ``str``

        :param node: The node to list anti affinity rules for
                     One of network, netwok_domain, or node is required
        :type  node: :class:`Node` or ``str``

        :param filter_id: This will allow you to filter the rules
                          by this node id
        :type  filter_id: ``str``

        :type  filter_state: This will allow you to filter rules by
                             node state (i.e. NORMAL)
        :type  filter_state: ``str``

        :rtype: ``list`` of :class:NttCisAntiAffinityRule`
        """

        not_none_arguments = [key for key in (network, network_domain, node) if key is not None]

        if len(not_none_arguments) != 1:
            raise ValueError("One and ONLY one of network, " "network_domain, or node must be set")

        params = {}

        if network_domain is not None:
            params["networkDomainId"] = self._network_domain_to_network_domain_id(network_domain)

        if network is not None:
            params["networkId"] = self._network_to_network_id(network)

        if node is not None:
            params["serverId"] = self._node_to_node_id(node)

        if filter_id is not None:
            params["id"] = filter_id

        if filter_state is not None:
            params["state"] = filter_state

        paged_result = self.connection.paginated_request_with_orgId_api_2(
            "server/antiAffinityRule", method="GET", params=params
        )

        rules = []

        for result in paged_result:
            rules.extend(self._to_anti_affinity_rules(result))

        return rules

    def ex_attach_node_to_vlan(self, node, vlan=None, private_ipv4=None):
        """
        Attach a node to a VLAN by adding an additional NIC to
        the node on the target VLAN. The IP will be automatically
        assigned based on the VLAN IP network space. Alternatively, provide
        a private IPv4 address instead of VLAN information, and this will
        be assigned to the node on corresponding NIC.

        :param      node: Node which should be used
        :type       node: :class:`Node`

        :param      vlan: VLAN to attach the node to
                          (required unless private_ipv4)
        :type       vlan: :class:`NttCisVlan`

        :keyword    private_ipv4: Private nic IPv4 Address
                                  (required unless vlan)
        :type       private_ipv4: ``str``

        :rtype: ``bool``
        """

        request = ET.Element("addNic", {"xmlns": TYPES_URN})
        ET.SubElement(request, "serverId").text = node.id
        nic = ET.SubElement(request, "nic")

        if vlan is not None:
            ET.SubElement(nic, "vlanId").text = vlan.id
        elif private_ipv4 is not None:
            ET.SubElement(nic, "privateIpv4").text = private_ipv4
        else:
            raise ValueError("One of vlan or primary_ipv4 " "must be specified")

        response = self.connection.request_with_orgId_api_2(
            "server/addNic", method="POST", data=ET.tostring(request)
        ).object
        response_code = findtext(response, "responseCode", TYPES_URN)

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

    def ex_destroy_nic(self, nic_id):
        """
        Remove a NIC on a node, removing the node from a VLAN

        :param      nic_id: The identifier of the NIC to remove
        :type       nic_id: ``str``

        :rtype: ``bool``
        """

        request = ET.Element("removeNic", {"xmlns": TYPES_URN, "id": nic_id})

        response = self.connection.request_with_orgId_api_2(
            "server/removeNic", method="POST", data=ET.tostring(request)
        ).object
        response_code = findtext(response, "responseCode", TYPES_URN)

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

    def ex_list_networks(self, location=None):
        """
        List networks deployed across all data center locations for your
        organization.  The response includes the location of each network.

        :param location: The target location
        :type  location: :class:`NodeLocation` or ``str``

        :return: a list of NttCisNetwork objects
        :rtype: ``list`` of :class:`NttCisNetwork`
        """

        return self.list_networks(location=location)

    def ex_create_network(self, location, name, description=None):
        """
        Create a new network in an MCP 1.0 location

        :param   location: The target location (MCP1)
        :type    location: :class:`NodeLocation` or ``str``

        :param   name: The name of the network
        :type    name: ``str``

        :param   description: Additional description of the network
        :type    description: ``str``

        :return: A new instance of `NttCisNetwork`
        :rtype:  Instance of :class:`NttCisNetwork`
        """

        network_location = self._location_to_location_id(location)

        create_node = ET.Element("NewNetworkWithLocation", {"xmlns": NETWORK_NS})
        ET.SubElement(create_node, "name").text = name

        if description is not None:
            ET.SubElement(create_node, "description").text = description
        ET.SubElement(create_node, "location").text = network_location

        self.connection.request_with_orgId_api_1(
            "networkWithLocation", method="POST", data=ET.tostring(create_node)
        )

        # MCP1 API does not return the ID, but name is unique for location
        network = list(filter(lambda x: x.name == name, self.ex_list_networks(location)))[0]

        return network

    def ex_delete_network(self, network):
        """
        Delete a network from an MCP 1 data center

        :param  network: The network to delete
        :type   network: :class:`NttCisNetwork`

        :rtype: ``bool``
        """

        response = self.connection.request_with_orgId_api_1(
            "network/%s?delete" % network.id, method="GET"
        ).object
        response_code = findtext(response, "result", GENERAL_NS)

        return response_code == "SUCCESS"

    def ex_rename_network(self, network, new_name):
        """
        Rename a network in MCP 1 data center

        :param  network: The network to rename
        :type   network: :class:`NttCisNetwork`

        :param  new_name: The new name of the network
        :type   new_name: ``str``

        :rtype: ``bool``
        """

        response = self.connection.request_with_orgId_api_1(
            "network/%s" % network.id, method="POST", data="name=%s" % new_name
        ).object
        response_code = findtext(response, "result", GENERAL_NS)

        return response_code == "SUCCESS"

    def ex_get_network_domain(self, network_domain_id):
        """
        Get an individual Network Domain, by identifier

        :param      network_domain_id: The identifier of the network domain
        :type       network_domain_id: ``str``

        :rtype: :class:`NttCisNetworkDomain`
        """

        locations = self.list_locations()
        net = self.connection.request_with_orgId_api_2(
            "network/networkDomain/%s" % network_domain_id
        ).object

        return self._to_network_domain(net, locations)

    def ex_list_network_domains(self, location=None, name=None, service_plan=None, state=None):
        """
        List networks domains deployed across all data center locations domain.

        for your organization.
        The response includes the location of each network
        :param      location: Only network domains in the location (optional)
        :type       location: :class:`NodeLocation` or ``str``

        :param      name: Only network domains of this name (optional)
        :type       name: ``str``

        :param      service_plan: Only network domains of this type (optional)
        :type       service_plan: ``str``

        :param      state: Only network domains in this state (optional)
        :type       state: ``str``

        :return: a list of `NttCisNetwork` objects
        :rtype: ``list`` of :class:`NttCisNetwork`
        """

        params = {}

        if location is not None:
            params["datacenterId"] = self._location_to_location_id(location)

        if name is not None:
            params["name"] = name

        if service_plan is not None:
            params["type"] = service_plan

        if state is not None:
            params["state"] = state

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

        return self._to_network_domains(response)

    def ex_create_network_domain(self, location, name, service_plan, description=None):
        """
        Deploy a new network domain to a data center

        :param      location: The data center to list
        :type       location: :class:`NodeLocation` or ``str``

        :param      name: The name of the network domain to create
        :type       name: ``str``

        :param      service_plan: The service plan, either "ESSENTIALS"
            or "ADVANCED"
        :type       service_plan: ``str``

        :param      description: An additional description of
                                 the network domain
        :type       description: ``str``

        :return: an instance of `NttCisNetworkDomain`
        :rtype: :class:`NttCisNetworkDomain`
        """

        create_node = ET.Element("deployNetworkDomain", {"xmlns": TYPES_URN})
        ET.SubElement(create_node, "datacenterId").text = self._location_to_location_id(location)

        ET.SubElement(create_node, "name").text = name

        if description is not None:
            ET.SubElement(create_node, "description").text = description
        ET.SubElement(create_node, "type").text = service_plan

        response = self.connection.request_with_orgId_api_2(
            "network/deployNetworkDomain", method="POST", data=ET.tostring(create_node)
        ).object

        network_domain_id = None

        for info in findall(response, "info", TYPES_URN):
            if info.get("name") == "networkDomainId":
                network_domain_id = info.get("value")
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



