You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by er...@apache.org on 2015/05/13 21:29:43 UTC
libcloud git commit: [google compute] fix network options for
create_node
Repository: libcloud
Updated Branches:
refs/heads/trunk 1ed502045 -> 5c1a95bf1
[google compute] fix network options for create_node
Signed-off-by: Eric Johnson <er...@google.com>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/5c1a95bf
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/5c1a95bf
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/5c1a95bf
Branch: refs/heads/trunk
Commit: 5c1a95bf199094008c682d3cffab560095668ceb
Parents: 1ed5020
Author: Eric Johnson <er...@google.com>
Authored: Wed May 13 18:22:03 2015 +0000
Committer: Eric Johnson <er...@google.com>
Committed: Wed May 13 19:29:26 2015 +0000
----------------------------------------------------------------------
libcloud/compute/drivers/gce.py | 22 ++++++++++++++----
libcloud/test/compute/test_gce.py | 42 ++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/5c1a95bf/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index e1e7549..22f3f9a 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -4561,7 +4561,9 @@ n
(default), a new non-static address will be
used. If 'None', then no external address will
be used. To use an existing static IP address,
- a GCEAddress object should be passed in.
+ a GCEAddress object should be passed in. This
+ param will be ignored if also using the
+ ex_nic_gce_struct param.
:type external_ip: :class:`GCEAddress` or ``str`` or None
:keyword ex_disk_type: Specify a pd-standard (default) disk or pd-ssd
@@ -4698,9 +4700,21 @@ n
if ex_disks_gce_struct:
node_data['disks'] = ex_disks_gce_struct
- if network and ex_nic_gce_struct:
- raise ValueError("Cannot specify both 'network' and "
- "'ex_nic_gce_struct'. Use one or the other.")
+ if ex_nic_gce_struct is not None:
+ if hasattr(external_ip, 'address'):
+ raise ValueError("Cannot specify both a static IP address "
+ "and 'ex_nic_gce_struct'. Use one or the "
+ "other.")
+ if hasattr(network, 'name'):
+ if network.name == 'default':
+ # assume this is just the default value from create_node()
+ # and since the user specified ex_nic_gce_struct, the
+ # struct should take precedence
+ network = None
+ else:
+ raise ValueError("Cannot specify both 'network' and "
+ "'ex_nic_gce_struct'. Use one or the "
+ "other.")
if network:
ni = [{'kind': 'compute#instanceNetworkInterface',
http://git-wip-us.apache.org/repos/asf/libcloud/blob/5c1a95bf/libcloud/test/compute/test_gce.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py
index 09466c9..8e1866f 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -521,6 +521,48 @@ class GCENodeDriverTest(LibcloudTestCase, TestCaseMixin):
self.assertIsInstance(node_data['serviceAccounts'][0]['scopes'], list)
self.assertEqual(len(node_data['serviceAccounts'][0]['scopes']), 1)
+ def test_create_node_network_opts(self):
+ node_name = 'node-name'
+ size = self.driver.ex_get_size('n1-standard-1')
+ image = self.driver.ex_get_image('debian-7')
+ zone = self.driver.ex_get_zone('us-central1-a')
+ network = self.driver.ex_get_network('lcnetwork')
+ address = self.driver.ex_get_address('lcaddress')
+ ex_nic_gce_struct = [
+ {
+ "network": "global/networks/lcnetwork",
+ "accessConfigs": [
+ {
+ "name": "lcnetwork-test",
+ "type": "ONE_TO_ONE_NAT"
+ }
+ ]
+ }
+ ]
+ # Test using default
+ node = self.driver.create_node(node_name, size, image)
+ self.assertEqual(node.extra['networkInterfaces'][0]["name"], 'nic0')
+
+ # Test using just the network
+ node = self.driver.create_node(node_name, size, image, location=zone,
+ ex_network=network)
+ self.assertEqual(node.extra['networkInterfaces'][0]["name"], 'nic0')
+
+ # Test using just the struct
+ node = self.driver.create_node(node_name, size, image, location=zone,
+ ex_nic_gce_struct=ex_nic_gce_struct)
+ self.assertEqual(node.extra['networkInterfaces'][0]["name"], 'nic0')
+
+ # Test both address and struct, should fail
+ self.assertRaises(ValueError, self.driver.create_node, node_name,
+ size, image, location=zone, external_ip=address,
+ ex_nic_gce_struct=ex_nic_gce_struct)
+
+ # Test both ex_network and struct, should fail
+ self.assertRaises(ValueError, self.driver.create_node, node_name,
+ size, image, location=zone, ex_network=network,
+ ex_nic_gce_struct=ex_nic_gce_struct)
+
def test_create_node_disk_opts(self):
node_name = 'node-name'
size = self.driver.ex_get_size('n1-standard-1')