libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [2/3] libcloud git commit: more user friendly kwargs for creating nodes. Allow str to be passed for vlan, network or network domain, as well as the auth (password) arg.
Date Mon, 21 Dec 2015 23:05:03 GMT
more user friendly kwargs for creating nodes. Allow str to be passed for vlan, network or network
domain, as well as the auth (password) arg.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6add1ee9
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6add1ee9
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6add1ee9

Branch: refs/heads/trunk
Commit: 6add1ee9ef3b991115d67796e49b165cc18ab378
Parents: f856da9
Author: anthony-shaw <anthony.p.shaw@gmail.com>
Authored: Tue Dec 15 20:35:45 2015 +1100
Committer: anthony-shaw <anthony.p.shaw@gmail.com>
Committed: Tue Dec 22 10:04:28 2015 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py | 51 ++++++++++++++++++--------
 1 file changed, 35 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/6add1ee9/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 9f22e31..fa6ee4e 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -21,7 +21,7 @@ try:
 except ImportError:
     from xml.etree import ElementTree as ET
 
-from libcloud.compute.base import NodeDriver, Node
+from libcloud.compute.base import NodeDriver, Node, NodeAuthPassword
 from libcloud.compute.base import NodeSize, NodeImage, NodeLocation
 from libcloud.common.dimensiondata import (DimensionDataConnection,
                                            DimensionDataStatus)
@@ -97,22 +97,22 @@ class DimensionDataNodeDriver(NodeDriver):
 
         :keyword    auth:   Initial authentication information for the
                             node (required)
-        :type       auth:   :class:`NodeAuthPassword`
+        :type       auth:   :class:`NodeAuthPassword` or ``str``
 
         :keyword    ex_description:  description for this node (required)
         :type       ex_description:  ``str``
 
         :keyword    ex_network:  Network to create the node within (required,
                                 unless using Network Domain)
-        :type       ex_network: :class:`DimensionDataNetwork`
+        :type       ex_network: :class:`DimensionDataNetwork` or ``str``
 
         :keyword    ex_network_domain:  Network Domain to create the node
                                         (required unless using network)
-        :type       ex_network_domain: :class:`DimensionDataNetworkDomain`
+        :type       ex_network_domain: :class:`DimensionDataNetworkDomain` or ``str``
 
         :keyword    ex_vlan:  VLAN to create the node within
                                         (required unless using network)
-        :type       ex_vlan: :class:`DimensionDataVlan`
+        :type       ex_vlan: :class:`DimensionDataVlan` or ``str``
 
         :keyword    ex_memory_gb:  The amount of memory in GB for the server
         :type       ex_memory_gb: ``int``
@@ -128,16 +128,22 @@ class DimensionDataNodeDriver(NodeDriver):
         :return: The newly created :class:`Node`.
         :rtype: :class:`Node`
         """
-
         password = None
-        auth_obj = self._get_and_check_auth(auth)
-        password = auth_obj.password
-
-        if not isinstance(ex_network, DimensionDataNetwork):
-            if not isinstance(ex_network_domain, DimensionDataNetworkDomain):
-                raise ValueError('ex_network must be of DimensionDataNetwork '
+        if isinstance(auth, str):
+            auth_obj = NodeAuthPassword(password=auth)
+            password = auth
+        else:
+            auth_obj = self._get_and_check_auth(auth)
+            password = auth_obj.password
+
+        if not isinstance(ex_network, DimensionDataNetwork) \
+        and not isinstance(ex_network, str):
+            if not isinstance(ex_network_domain, DimensionDataNetworkDomain) \
+            and not isinstance(ex_network_domain, str):
+                raise ValueError('ex_network must be of DimensionDataNetwork'
+                                 ' or str '
                                  'type or ex_network_domain must be of '
-                                 'DimensionDataNetworkDomain type')
+                                 'DimensionDataNetworkDomain type or str')
 
         server_elm = ET.Element('deployServer', {'xmlns': TYPES_URN})
         ET.SubElement(server_elm, "name").text = name
@@ -158,13 +164,26 @@ class DimensionDataNodeDriver(NodeDriver):
 
         if ex_network is not None:
             network_elm = ET.SubElement(server_elm, "network")
-            ET.SubElement(network_elm, "networkId").text = ex_network.id
+            if isinstance(ex_network, DimensionDataNetwork):
+                ET.SubElement(network_elm, "networkId").text = ex_network.id
+            else:
+                ET.SubElement(network_elm, "networkId").text = ex_network
         if ex_network_domain is not None:
+            network_domain_id = None
+            if isinstance(ex_network_domain, DimensionDataNetworkDomain):
+                network_domain_id = ex_network_domain.id
+            else:
+                network_domain_id = ex_network_domain
             network_inf_elm = ET.SubElement(server_elm, "networkInfo",
                                             {'networkDomainId':
-                                             ex_network_domain.id})
+                                             network_domain_id})
+            vlan_id = None
+            if isinstance(ex_vlan, DimensionDataVlan):
+                vlan_id = ex_vlan.id
+            else:
+                vlan_id = ex_vlan
             pri_nic = ET.SubElement(network_inf_elm, "primaryNic")
-            ET.SubElement(pri_nic, "vlanId").text = ex_vlan.id
+            ET.SubElement(pri_nic, "vlanId").text = vlan_id
 
         response = self.connection.request_with_orgId_api_2(
             'server/deployServer',


Mime
View raw message