You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by se...@apache.org on 2014/08/09 10:23:30 UTC

git commit: Cloudstack - create_node: add param to specify specific ip_address for default nic plus flake8 & docstring fix

Repository: libcloud
Updated Branches:
  refs/heads/trunk 6deb49e08 -> 529a9cf59


Cloudstack - create_node: add param to specify specific ip_address for default nic plus flake8 & docstring fix

closes #346

Signed-off-by: Sebastien Goasguen <ru...@gmail.com>


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

Branch: refs/heads/trunk
Commit: 529a9cf59395e005cbd7c2d9383ce69a369306d3
Parents: 6deb49e
Author: Roeland Kuipers <rk...@schubergphilis.com>
Authored: Fri Aug 8 13:03:00 2014 +0200
Committer: Sebastien Goasguen <ru...@gmail.com>
Committed: Sat Aug 9 04:23:15 2014 -0400

----------------------------------------------------------------------
 CHANGES.rst                                     |  4 ++++
 libcloud/compute/drivers/cloudstack.py          |  7 +++++++
 .../deployVirtualMachine_deployip.json          |  1 +
 .../cloudstack/listNetworks_deployip.json       |  1 +
 .../listServiceOfferings_deployip.json          |  1 +
 .../cloudstack/listTemplates_deployip.json      |  1 +
 .../fixtures/cloudstack/listZones_deployip.json |  1 +
 .../queryAsyncJobResult_deployvmwithid.json     |  1 +
 libcloud/test/compute/test_cloudstack.py        | 22 ++++++++++++++++++++
 9 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 4ac10f0..6588b72 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -44,6 +44,10 @@ Compute
   Reported by Chris DeRamus.
   [Tomaz Muraus]
 
+- Add ip_address parameter in CloudStack driver ``create_node`` method. 
+  (GITHUB-346)
+  [Roeland Kuipers]
+
 Loadbalancer
 ~~~~~~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index 81b8cb4..21d2fef 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -810,6 +810,9 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         :keyword    ex_displayname: String containing instance display name
         :type       ex_displayname: ``str``
 
+        :keyword    ex_ip_address: String with ipaddress for the default nic
+        :type       ex_ip_address: ``str``
+
         :rtype:     :class:`.CloudStackNode`
         """
 
@@ -836,6 +839,7 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         ex_user_data = kwargs.get('ex_userdata', None)
         ex_security_groups = kwargs.get('ex_security_groups', None)
         ex_displayname = kwargs.get('ex_displayname', None)
+        ex_ip_address = kwargs.get('ex_ip_address', None)
 
         if name:
             server_params['name'] = name
@@ -876,6 +880,9 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
             ex_security_groups = ','.join(ex_security_groups)
             server_params['securitygroupnames'] = ex_security_groups
 
+        if ex_ip_address:
+            server_params['ipaddress'] = ex_ip_address
+
         return server_params
 
     def destroy_node(self, node):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/test/compute/fixtures/cloudstack/deployVirtualMachine_deployip.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/deployVirtualMachine_deployip.json b/libcloud/test/compute/fixtures/cloudstack/deployVirtualMachine_deployip.json
new file mode 100644
index 0000000..b099e8f
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/deployVirtualMachine_deployip.json
@@ -0,0 +1 @@
+{ "deployvirtualmachineresponse" : {"jobid":"deployvmwithid","id":65385} }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/test/compute/fixtures/cloudstack/listNetworks_deployip.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/listNetworks_deployip.json b/libcloud/test/compute/fixtures/cloudstack/listNetworks_deployip.json
new file mode 100644
index 0000000..ad0bb80
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/listNetworks_deployip.json
@@ -0,0 +1 @@
+{"listnetworksresponse": { "count": 3, "network": [ { "broadcastdomaintype": "Vlan", "broadcasturi": "vlan://1002", "displaytext": "network:192.168.2.0/24", "dns1": "8.8.8.8", "dns2": "8.8.8.8", "domain": "ROOT", "domainid": 1623, "endip": "192.168.2.233", "gateway": "192.168.2.254", "id": 1823, "isdefault": false, "isshared": true, "issystem": false, "name": "ROOT", "netmask": "255.255.255.0", "networkdomain": "cs1cloud.internal", "networkofferingavailability": "Optional", "networkofferingdisplaytext": "Direct", "networkofferingid": 7, "networkofferingname": "DefaultDirectNetworkOffering", "related": 1823, "securitygroupenabled": false, "service": [ { "name": "UserData" }, { "capability": [ { "name": "AllowDnsSuffixModification", "value": "true" } ], "name": "Dns" }, { "capability": [ { "name": "SupportedProtocols", "value": "tcp, udp" }, { "name": "SupportedLbAlgorithms", "value": "roundrobin,leastconn,source" } ], "name": "Lb" }, { "name": "Dhcp" } ], "startip": "192.168.2.1", "s
 tate": "Setup", "traffictype": "Guest", "type": "Direct", "vlan": "1002", "zoneid": 1 }, { "account": "testuser", "broadcastdomaintype": "Vlan", "broadcasturi": "vlan://2909", "displaytext": "testuser-network", "dns1": "8.8.8.8", "dns2": "8.8.8.8", "domain": "ROOT", "domainid": 1623, "id": 1547, "isdefault": true, "isshared": false, "issystem": false, "name": "testuser-network", "networkdomain": "cs586cloud.internal", "networkofferingavailability": "Optional", "networkofferingdisplaytext": "Virtual Vlan", "networkofferingid": 6, "networkofferingname": "DefaultVirtualizedNetworkOffering", "related": 1547, "securitygroupenabled": false, "service": [ { "name": "UserData" }, { "capability": [ { "name": "AllowDnsSuffixModification", "value": "true" } ], "name": "Dns" }, { "capability": [ { "name": "SupportedProtocols", "value": "tcp, udp" }, { "name": "SupportedLbAlgorithms", "value": "roundrobin,leastconn,source" } ], "name": "Lb" }, { "name": "Gateway" }, { "name": "Dhcp" }, { "capabil
 ity": [ { "name": "SupportedVpnTypes", "value": "pptp,l2tp,ipsec" } ], "name": "Vpn" }, { "capability": [ { "name": "MultipleIps", "value": "true" }, { "name": "SupportedSourceNatTypes", "value": "per account" }, { "name": "SupportedProtocols", "value": "tcp,udp,icmp" }, { "name": "TrafficStatistics", "value": "per public ip" }, { "name": "PortForwarding", "value": "true" }, { "name": "StaticNat", "value": "true" } ], "name": "Firewall" } ], "state": "Implemented", "traffictype": "Guest", "type": "Virtual", "zoneid": 2 }, { "account": "testuser", "broadcastdomaintype": "Vlan", "broadcasturi": "vlan://3564", "displaytext": "testuser-network", "dns1": "8.8.8.8", "dns2": "8.8.8.8", "domain": "ROOT", "domainid": 1623, "id": 1374, "isdefault": true, "isshared": false, "issystem": false, "name": "testuser-network", "networkdomain": "cs586cloud.internal", "networkofferingavailability": "Optional", "networkofferingdisplaytext": "Virtual Vlan", "networkofferingid": 6, "networkofferingname": 
 "DefaultVirtualizedNetworkOffering", "related": 1374, "securitygroupenabled": false, "service": [ { "name": "UserData" }, { "capability": [ { "name": "AllowDnsSuffixModification", "value": "true" } ], "name": "Dns" }, { "capability": [ { "name": "SupportedProtocols", "value": "tcp, udp" }, { "name": "SupportedLbAlgorithms", "value": "roundrobin,leastconn,source" } ], "name": "Lb" }, { "name": "Gateway" }, { "name": "Dhcp" }, { "capability": [ { "name": "SupportedVpnTypes", "value": "pptp,l2tp,ipsec" } ], "name": "Vpn" }, { "capability": [ { "name": "MultipleIps", "value": "true" }, { "name": "SupportedSourceNatTypes", "value": "per account" }, { "name": "SupportedProtocols", "value": "tcp,udp,icmp" }, { "name": "TrafficStatistics", "value": "per public ip" }, { "name": "PortForwarding", "value": "true" }, { "name": "StaticNat", "value": "true" } ], "name": "Firewall" } ], "state": "Implemented", "traffictype": "Guest", "type": "Virtual", "zoneid": 1 } ] } }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/test/compute/fixtures/cloudstack/listServiceOfferings_deployip.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/listServiceOfferings_deployip.json b/libcloud/test/compute/fixtures/cloudstack/listServiceOfferings_deployip.json
new file mode 100644
index 0000000..944a6f2
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/listServiceOfferings_deployip.json
@@ -0,0 +1 @@
+{ "listserviceofferingsresponse" : {"count": 3, "serviceoffering": [ {"cpunumber": 2, "cpuspeed": 1600, "created": "2011-09-09T13:14:19+0900", "defaultuse": false, "displaytext": "M4", "id": 21, "issystem": false, "limitcpuuse": true, "memory": 4096, "name": "M4", "networkrate": 500, "offerha": false, "storagetype": "shared", "tags": "Shared.auto"}, {"cpunumber": 1, "cpuspeed": 800, "created": "2011-09-09T13:17:52+0900", "defaultuse": false, "displaytext": "XS", "id": 24, "issystem": false, "limitcpuuse": true, "memory": 512, "name": "XS", "networkrate": 100, "offerha": false, "storagetype": "shared", "tags": "Shared.auto"}, {"cpunumber": 1, "cpuspeed": 1600, "created": "2011-09-14T22:51:23+0900", "defaultuse": false, "displaytext": "S2", "id": 30, "issystem": false, "limitcpuuse": true, "memory": 2048, "name": "S2", "networkrate": 500, "offerha": false, "storagetype": "shared", "tags": "Shared.auto"}]}}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/test/compute/fixtures/cloudstack/listTemplates_deployip.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/listTemplates_deployip.json b/libcloud/test/compute/fixtures/cloudstack/listTemplates_deployip.json
new file mode 100644
index 0000000..a9c778c
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/listTemplates_deployip.json
@@ -0,0 +1 @@
+{ "listtemplatesresponse" : {"count": 2, "template": [ {"account": "admin", "created": "2014-06-06T20:08:49+0900", "crossZones": false, "displaytext": "CentOS 6.5", "domain": "ROOT", "domainid": 1, "format": "OVA", "hypervisor": "VMware", "id": 8028, "isextractable": true, "isfeatured": true, "ispublic": true, "isready": true, "name": "CentOS 6.5 64-bit", "ostypeid": 112, "ostypename": "CentOS 5.5 (64-bit)", "passwordenabled": true, "size": 16106127360, "status": "Download Complete", "templatetype": "USER", "zoneid": 2, "zonename": "zone2"}, {"account": "admin", "created": "2014-06-06T20:08:48+0900", "crossZones": false, "displaytext": "CentOS 6.5", "domain": "ROOT", "domainid": 1, "format": "OVA", "hypervisor": "VMware", "id": 8028, "isextractable": true, "isfeatured": true, "ispublic": true, "isready": true, "name": "CentOS 6.5 64-bit", "ostypeid": 112, "ostypename": "CentOS 5.5 (64-bit)", "passwordenabled": true, "size": 16106127360, "status": "Download Complete", "templatetype":
  "USER", "zoneid": 1, "zonename": "zone1"} ]} }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/test/compute/fixtures/cloudstack/listZones_deployip.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/listZones_deployip.json b/libcloud/test/compute/fixtures/cloudstack/listZones_deployip.json
new file mode 100644
index 0000000..b072749
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/listZones_deployip.json
@@ -0,0 +1 @@
+{ "listzonesresponse" : { "count":2 ,"zone" : [  {"id":1,"name":"zone1","networktype":"Advanced","securitygroupsenabled":false,"allocationstate":"Enabled","zonetoken":"6a3bfa26-67cd-3ff2-867e-20e86b211bb1","dhcpprovider":"VirtualRouter"}, {"id":2,"name":"zone2","networktype":"Advanced","securitygroupsenabled":false,"allocationstate":"Enabled","zonetoken":"8366e550-542d-373d-88e3-ca7c90bc8e6c","dhcpprovider":"VirtualRouter"} ] } }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deployvmwithid.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deployvmwithid.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deployvmwithid.json
new file mode 100644
index 0000000..6b6409e
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_deployvmwithid.json
@@ -0,0 +1 @@
+{ "queryasyncjobresultresponse" : {"jobid":"deployvmwithip", "jobprocstatus": 0, "jobresult": {"virtualmachine": {"account": "testuser", "cpunumber": 2, "cpuspeed": 1600, "created": "2014-07-06T16:40:39+0900", "displayname": "deployip", "domain": "ROOT", "domainid": 1623, "guestosid": 112, "haenable": false, "hypervisor": "VMware", "id": 65385, "memory": 4096, "name": "deployip", "nic": [{"gateway": "10.1.0.1", "id": 87320, "ipaddress": "10.1.0.128", "isdefault": true, "macaddress": "02:00:78:4a:01:9e", "netmask": "255.255.252.0", "networkid": 1374, "traffictype": "Guest", "type": "Virtual"}, {"gateway": "192.168.2.254", "id": 87319, "ipaddress": "192.168.2.55", "isdefault": false, "macaddress": "06:e6:50:00:70:0e", "netmask": "255.255.255.0", "networkid": 1823, "traffictype": "Guest", "type": "Direct"}], "password": "password", "passwordenabled": true, "rootdeviceid": 0, "rootdevicetype": "VMFS", "securitygroup": [], "serviceofferingid": 21, "serviceofferingname": "M4", "state": "R
 unning" , "templatedisplaytext": "CentOS 6.5", "templateid": 8028, "templatename": "CentOS 6.5 64-bit", "zoneid": 1, "zonename": "zone1"}}, "jobresultcode": 0, "jobresulttype": "object", "jobstatus": 1} }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/529a9cf5/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index aade378..3393c0c 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -127,6 +127,28 @@ class CloudStackCommonTestCase(TestCaseMixin):
         self.assertEqual(node.extra['image_id'], image.id)
         self.assertEqual(len(node.private_ips), 2)
 
+    def test_create_node_ex_ipaddress(self):
+        CloudStackMockHttp.fixture_tag = 'deployip'
+        size = self.driver.list_sizes()[0]
+        image = self.driver.list_images()[0]
+        location = self.driver.list_locations()[0]
+        ipaddress = '10.1.0.128'
+
+        networks = [nw for nw in self.driver.ex_list_networks()
+                    if str(nw.zoneid) == str(location.id)]
+
+        node = self.driver.create_node(name='deployip',
+                                       location=location,
+                                       image=image,
+                                       size=size,
+                                       networks=networks,
+                                       ex_ip_address=ipaddress)
+        self.assertEqual(node.name, 'deployip')
+        self.assertEqual(node.extra['size_id'], size.id)
+        self.assertEqual(node.extra['zone_id'], location.id)
+        self.assertEqual(node.extra['image_id'], image.id)
+        self.assertEqual(node.private_ips[0], ipaddress)
+
     def test_create_node_ex_security_groups(self):
         size = self.driver.list_sizes()[0]
         image = self.driver.list_images()[0]