libcloud/compute/drivers/dimensiondata.py [1538:1804]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            id=network_domain_id,
            name=name,
            description=description,
            location=location,
            status=NodeState.RUNNING,
            plan=service_plan,
        )

    def ex_update_network_domain(self, network_domain):
        """
        Update the properties of a network domain

        :param      network_domain: The network domain with updated properties
        :type       network_domain: :class:`DimensionDataNetworkDomain`

        :return: an instance of `DimensionDataNetworkDomain`
        :rtype: :class:`DimensionDataNetworkDomain`
        """
        edit_node = ET.Element("editNetworkDomain", {"xmlns": TYPES_URN})
        edit_node.set("id", network_domain.id)
        ET.SubElement(edit_node, "name").text = network_domain.name
        if network_domain.description is not None:
            ET.SubElement(edit_node, "description").text = network_domain.description
        ET.SubElement(edit_node, "type").text = network_domain.plan

        self.connection.request_with_orgId_api_2(
            "network/editNetworkDomain", method="POST", data=ET.tostring(edit_node)
        ).object

        return network_domain

    def ex_delete_network_domain(self, network_domain):
        """
        Delete a network domain

        :param      network_domain: The network domain to delete
        :type       network_domain: :class:`DimensionDataNetworkDomain`

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

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

    def ex_create_vlan(
        self,
        network_domain,
        name,
        private_ipv4_base_address,
        description=None,
        private_ipv4_prefix_size=24,
    ):
        """
        Deploy a new VLAN to a network domain

        :param      network_domain: The network domain to add the VLAN to
        :type       network_domain: :class:`DimensionDataNetworkDomain`

        :param      name: The name of the VLAN to create
        :type       name: ``str``

        :param      private_ipv4_base_address: The base IPv4 address
            e.g. 192.168.1.0
        :type       private_ipv4_base_address: ``str``

        :param      description: An additional description of the VLAN
        :type       description: ``str``

        :param      private_ipv4_prefix_size: The size of the IPv4
            address space, e.g 24
        :type       private_ipv4_prefix_size: ``int``

        :return: an instance of `DimensionDataVlan`
        :rtype: :class:`DimensionDataVlan`
        """
        create_node = ET.Element("deployVlan", {"xmlns": TYPES_URN})
        ET.SubElement(create_node, "networkDomainId").text = network_domain.id
        ET.SubElement(create_node, "name").text = name
        if description is not None:
            ET.SubElement(create_node, "description").text = description
        ET.SubElement(create_node, "privateIpv4BaseAddress").text = private_ipv4_base_address
        ET.SubElement(create_node, "privateIpv4PrefixSize").text = str(private_ipv4_prefix_size)

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

        vlan_id = None

        for info in findall(response, "info", TYPES_URN):
            if info.get("name") == "vlanId":
                vlan_id = info.get("value")

        return self.ex_get_vlan(vlan_id)

    def ex_get_vlan(self, vlan_id):
        """
        Get a single VLAN, by it's identifier

        :param   vlan_id: The identifier of the VLAN
        :type    vlan_id: ``str``

        :return: an instance of `DimensionDataVlan`
        :rtype: :class:`DimensionDataVlan`
        """
        locations = self.list_locations()
        vlan = self.connection.request_with_orgId_api_2("network/vlan/%s" % vlan_id).object
        return self._to_vlan(vlan, locations)

    def ex_update_vlan(self, vlan):
        """
        Updates the properties of the given VLAN
        Only name and description are updated

        :param      vlan: The VLAN to update
        :type       vlan: :class:`DimensionDataNetworkDomain`

        :return: an instance of `DimensionDataVlan`
        :rtype: :class:`DimensionDataVlan`
        """
        edit_node = ET.Element("editVlan", {"xmlns": TYPES_URN})
        edit_node.set("id", vlan.id)
        ET.SubElement(edit_node, "name").text = vlan.name
        if vlan.description is not None:
            ET.SubElement(edit_node, "description").text = vlan.description

        self.connection.request_with_orgId_api_2(
            "network/editVlan", method="POST", data=ET.tostring(edit_node)
        ).object

        return vlan

    def ex_expand_vlan(self, vlan):
        """
        Expands the VLAN to the prefix size in private_ipv4_range_size
        The expansion will
        not be permitted if the proposed IP space overlaps with an
        already deployed VLANs IP space.

        :param      vlan: The VLAN to update
        :type       vlan: :class:`DimensionDataNetworkDomain`

        :return: an instance of `DimensionDataVlan`
        :rtype: :class:`DimensionDataVlan`
        """
        edit_node = ET.Element("expandVlan", {"xmlns": TYPES_URN})
        edit_node.set("id", vlan.id)
        ET.SubElement(edit_node, "privateIpv4PrefixSize").text = vlan.private_ipv4_range_size

        self.connection.request_with_orgId_api_2(
            "network/expandVlan", method="POST", data=ET.tostring(edit_node)
        ).object

        return vlan

    def ex_delete_vlan(self, vlan):
        """
        Deletes an existing VLAN

        :param      vlan: The VLAN to delete
        :type       vlan: :class:`DimensionDataNetworkDomain`

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

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

    def ex_list_vlans(
        self,
        location=None,
        network_domain=None,
        name=None,
        ipv4_address=None,
        ipv6_address=None,
        state=None,
    ):
        """
        List VLANs available, can filter by location and/or network domain

        :param      location: Only VLANs in this location (optional)
        :type       location: :class:`NodeLocation` or ``str``

        :param      network_domain: Only VLANs in this domain (optional)
        :type       network_domain: :class:`DimensionDataNetworkDomain`

        :param      name: Only VLANs with this name (optional)
        :type       name: ``str``

        :param      ipv4_address: Only VLANs with this ipv4 address (optional)
        :type       ipv4_address: ``str``

        :param      ipv6_address: Only VLANs with this ipv6 address  (optional)
        :type       ipv6_address: ``str``

        :param      state: Only VLANs with this state (optional)
        :type       state: ``str``

        :return: a list of DimensionDataVlan objects
        :rtype: ``list`` of :class:`DimensionDataVlan`
        """
        params = {}
        if location is not None:
            params["datacenterId"] = self._location_to_location_id(location)
        if network_domain is not None:
            params["networkDomainId"] = self._network_domain_to_network_domain_id(network_domain)
        if name is not None:
            params["name"] = name
        if ipv4_address is not None:
            params["privateIpv4Address"] = ipv4_address
        if ipv6_address is not None:
            params["ipv6Address"] = ipv6_address
        if state is not None:
            params["state"] = state
        response = self.connection.request_with_orgId_api_2("network/vlan", params=params).object
        return self._to_vlans(response)

    def ex_add_public_ip_block_to_network_domain(self, network_domain):
        add_node = ET.Element("addPublicIpBlock", {"xmlns": TYPES_URN})
        ET.SubElement(add_node, "networkDomainId").text = network_domain.id

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

        block_id = None

        for info in findall(response, "info", TYPES_URN):
            if info.get("name") == "ipBlockId":
                block_id = info.get("value")
        return self.ex_get_public_ip_block(block_id)

    def ex_list_public_ip_blocks(self, network_domain):
        params = {}
        params["networkDomainId"] = network_domain.id

        response = self.connection.request_with_orgId_api_2(
            "network/publicIpBlock", params=params
        ).object
        return self._to_ip_blocks(response)

    def ex_get_public_ip_block(self, block_id):
        locations = self.list_locations()
        block = self.connection.request_with_orgId_api_2(
            "network/publicIpBlock/%s" % block_id
        ).object
        return self._to_ip_block(block, locations)

    def ex_delete_public_ip_block(self, block):
        delete_node = ET.Element("removePublicIpBlock", {"xmlns": TYPES_URN})
        delete_node.set("id", block.id)
        result = self.connection.request_with_orgId_api_2(
            "network/removePublicIpBlock", method="POST", data=ET.tostring(delete_node)
        ).object

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



libcloud/compute/drivers/nttcis.py [1933:2224]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            id=network_domain_id,
            name=name,
            description=description,
            location=location,
            status=NodeState.RUNNING,
            plan=service_plan,
        )

    def ex_update_network_domain(self, network_domain):
        """
        Update the properties of a network domain

        :param      network_domain: The network domain with updated properties
        :type       network_domain: :class:`NttCisNetworkDomain`

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

        edit_node = ET.Element("editNetworkDomain", {"xmlns": TYPES_URN})
        edit_node.set("id", network_domain.id)
        ET.SubElement(edit_node, "name").text = network_domain.name

        if network_domain.description is not None:
            ET.SubElement(edit_node, "description").text = network_domain.description
        ET.SubElement(edit_node, "type").text = network_domain.plan

        self.connection.request_with_orgId_api_2(
            "network/editNetworkDomain", method="POST", data=ET.tostring(edit_node)
        ).object

        return network_domain

    def ex_delete_network_domain(self, network_domain):
        """
        Delete a network domain

        :param      network_domain: The network domain to delete
        :type       network_domain: :class:`NttCisNetworkDomain`

        :rtype: ``bool``
        """

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

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

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

    def ex_create_vlan(
        self,
        network_domain,
        name,
        private_ipv4_base_address,
        description=None,
        private_ipv4_prefix_size=24,
    ):
        """
        Deploy a new VLAN to a network domain

        :param      network_domain: The network domain to add the VLAN to
        :type       network_domain: :class:`NttCisNetworkDomain`

        :param      name: The name of the VLAN to create
        :type       name: ``str``

        :param      private_ipv4_base_address: The base IPv4 address
            e.g. 192.168.1.0
        :type       private_ipv4_base_address: ``str``

        :param      description: An additional description of the VLAN
        :type       description: ``str``

        :param      private_ipv4_prefix_size: The size of the IPv4
            address space, e.g 24
        :type       private_ipv4_prefix_size: ``int``

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

        create_node = ET.Element("deployVlan", {"xmlns": TYPES_URN})
        ET.SubElement(create_node, "networkDomainId").text = network_domain.id
        ET.SubElement(create_node, "name").text = name

        if description is not None:
            ET.SubElement(create_node, "description").text = description
        ET.SubElement(create_node, "privateIpv4BaseAddress").text = private_ipv4_base_address
        ET.SubElement(create_node, "privateIpv4PrefixSize").text = str(private_ipv4_prefix_size)

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

        vlan_id = None

        for info in findall(response, "info", TYPES_URN):
            if info.get("name") == "vlanId":
                vlan_id = info.get("value")

        return self.ex_get_vlan(vlan_id)

    def ex_get_vlan(self, vlan_id):
        """
        Get a single VLAN, by it's identifier

        :param   vlan_id: The identifier of the VLAN
        :type    vlan_id: ``str``

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

        locations = self.list_locations()
        vlan = self.connection.request_with_orgId_api_2("network/vlan/%s" % vlan_id).object

        return self._to_vlan(vlan, locations)

    def ex_update_vlan(self, vlan):
        """
        Updates the properties of the given VLAN
        Only name and description are updated

        :param      vlan: The VLAN to update
        :type       vlan: :class:`NttCisetworkDomain`

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

        edit_node = ET.Element("editVlan", {"xmlns": TYPES_URN})
        edit_node.set("id", vlan.id)
        ET.SubElement(edit_node, "name").text = vlan.name

        if vlan.description is not None:
            ET.SubElement(edit_node, "description").text = vlan.description

        self.connection.request_with_orgId_api_2(
            "network/editVlan", method="POST", data=ET.tostring(edit_node)
        ).object

        return vlan

    def ex_expand_vlan(self, vlan):
        """
        Expands the VLAN to the prefix size in private_ipv4_range_size
        The expansion will
        not be permitted if the proposed IP space overlaps with an
        already deployed VLANs IP space.

        :param      vlan: The VLAN to update
        :type       vlan: :class:`NttCisNetworkDomain`

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

        edit_node = ET.Element("expandVlan", {"xmlns": TYPES_URN})
        edit_node.set("id", vlan.id)
        ET.SubElement(edit_node, "privateIpv4PrefixSize").text = vlan.private_ipv4_range_size

        self.connection.request_with_orgId_api_2(
            "network/expandVlan", method="POST", data=ET.tostring(edit_node)
        ).object

        return vlan

    def ex_delete_vlan(self, vlan):
        """
        Deletes an existing VLAN

        :param      vlan: The VLAN to delete
        :type       vlan: :class:`DNttCisNetworkDomain`

        :rtype: ``bool``
        """

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

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

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

    def ex_list_vlans(
        self,
        location=None,
        network_domain=None,
        name=None,
        ipv4_address=None,
        ipv6_address=None,
        state=None,
    ):
        """
        List VLANs available, can filter by location and/or network domain

        :param      location: Only VLANs in this location (optional)
        :type       location: :class:`NodeLocation` or ``str``

        :param      network_domain: Only VLANs in this domain (optional)
        :type       network_domain: :class:`NttCisNetworkDomain`

        :param      name: Only VLANs with this name (optional)
        :type       name: ``str``

        :param      ipv4_address: Only VLANs with this ipv4 address (optional)
        :type       ipv4_address: ``str``

        :param      ipv6_address: Only VLANs with this ipv6 address  (optional)
        :type       ipv6_address: ``str``

        :param      state: Only VLANs with this state (optional)
        :type       state: ``str``

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

        params = {}

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

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

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

        if ipv4_address is not None:
            params["privateIpv4Address"] = ipv4_address

        if ipv6_address is not None:
            params["ipv6Address"] = ipv6_address

        if state is not None:
            params["state"] = state
        response = self.connection.request_with_orgId_api_2("network/vlan", params=params).object

        return self._to_vlans(response)

    def ex_add_public_ip_block_to_network_domain(self, network_domain):
        add_node = ET.Element("addPublicIpBlock", {"xmlns": TYPES_URN})
        ET.SubElement(add_node, "networkDomainId").text = network_domain.id

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

        block_id = None

        for info in findall(response, "info", TYPES_URN):
            if info.get("name") == "ipBlockId":
                block_id = info.get("value")

        return self.ex_get_public_ip_block(block_id)

    def ex_list_public_ip_blocks(self, network_domain):
        params = {}
        params["networkDomainId"] = network_domain.id

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

        return self._to_ip_blocks(response)

    def ex_get_public_ip_block(self, block_id):
        locations = self.list_locations()
        block = self.connection.request_with_orgId_api_2(
            "network/publicIpBlock/%s" % block_id
        ).object

        return self._to_ip_block(block, locations)

    def ex_delete_public_ip_block(self, block):
        delete_node = ET.Element("removePublicIpBlock", {"xmlns": TYPES_URN})
        delete_node.set("id", block.id)
        result = self.connection.request_with_orgId_api_2(
            "network/removePublicIpBlock", method="POST", data=ET.tostring(delete_node)
        ).object

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

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



