Repository: libcloud
Updated Branches:
refs/heads/trunk a39fe0e3e -> 735a786e0
adding tests for #783
Signed-off-by: Eric Johnson <erjohnso@google.com>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/735a786e
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/735a786e
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/735a786e
Branch: refs/heads/trunk
Commit: 735a786e05590a6a1425bff042e8cd35206579b2
Parents: 9639726
Author: Eric Johnson <erjohnso@google.com>
Authored: Tue May 10 17:13:14 2016 +0000
Committer: Eric Johnson <erjohnso@google.com>
Committed: Tue May 17 14:58:09 2016 +0000
----------------------------------------------------------------------
CHANGES.rst | 4 ++
demos/gce_demo.py | 14 ++++++
.../gce/global_networks_custom_network.json | 14 ++++++
...es_us-central1-a_instances_sn-node-name.json | 49 ++++++++++++++++++++
libcloud/test/compute/test_gce.py | 49 ++++++++++++++++++++
5 files changed, 130 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/735a786e/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index f08fb3d..df2538b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -24,6 +24,10 @@ General
Compute
~~~~~~~
+- GCE nodes can be launched in a subnetwork
+ (GITHUB-783)
+ [Lars Larsson]
+
- Add Subnetworks to GCE driver
(GITHUB-780)
[Eric Johnson]
http://git-wip-us.apache.org/repos/asf/libcloud/blob/735a786e/demos/gce_demo.py
----------------------------------------------------------------------
diff --git a/demos/gce_demo.py b/demos/gce_demo.py
index 696ebae..b3caf75 100755
--- a/demos/gce_demo.py
+++ b/demos/gce_demo.py
@@ -375,6 +375,20 @@ def main_compute():
subnets.append(gce.ex_get_subnetwork(sn))
display('Display custom subnetworks:', subnets)
+ # == Launch instance in custom subnetwork ==
+ display('Creating Node in custom subnetwork:')
+ name = '%s-subnet-node' % DEMO_BASE_NAME
+ node_1 = gce.create_node(name, 'g1-small', 'debian-8',
+ ex_disk_auto_delete=True,
+ ex_network=network_custom,
+ ex_subnetwork=subnet)
+ display(' Node %s created' % name)
+
+ # == Destroy instance in custom subnetwork ==
+ display('Destroying Node in custom subnetwork:')
+ node_1.destroy()
+ display(' Node %s destroyed' % name)
+
# == Delete an subnetwork ==
display('Delete Custom Subnetwork:')
subnet.destroy()
http://git-wip-us.apache.org/repos/asf/libcloud/blob/735a786e/libcloud/test/compute/fixtures/gce/global_networks_custom_network.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/global_networks_custom_network.json b/libcloud/test/compute/fixtures/gce/global_networks_custom_network.json
new file mode 100644
index 0000000..9ac4a16
--- /dev/null
+++ b/libcloud/test/compute/fixtures/gce/global_networks_custom_network.json
@@ -0,0 +1,14 @@
+{
+ "kind": "compute#network",
+ "id": "5125152985904090792",
+ "creationTimestamp": "2016-03-25T05:34:15.077-07:00",
+ "name": "custom-network",
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/global/networks/custom-network",
+ "autoCreateSubnetworks": false,
+ "subnetworks": [
+ "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1/subnetworks/cf-972cf02e6ad49112",
+ "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-east1/subnetworks/cf-daf1e2124a902a47",
+ "https://www.googleapis.com/compute/v1/projects/project_name/regions/asia-east1/subnetworks/cf-4c2da366a0381eb9",
+ "https://www.googleapis.com/compute/v1/projects/project_name/regions/europe-west1/subnetworks/cf-df1837b06a6f927b"
+ ]
+}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/735a786e/libcloud/test/compute/fixtures/gce/zones_us-central1-a_instances_sn-node-name.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/zones_us-central1-a_instances_sn-node-name.json
b/libcloud/test/compute/fixtures/gce/zones_us-central1-a_instances_sn-node-name.json
new file mode 100644
index 0000000..302e85a
--- /dev/null
+++ b/libcloud/test/compute/fixtures/gce/zones_us-central1-a_instances_sn-node-name.json
@@ -0,0 +1,49 @@
+{
+ "canIpForward": false,
+ "creationTimestamp": "2013-12-13T10:45:23.351-08:00",
+ "disks": [
+ {
+ "boot": true,
+ "deviceName": "persistent-disk-0",
+ "index": 0,
+ "kind": "compute#attachedDisk",
+ "mode": "READ_WRITE",
+ "source": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/disks/node-name",
+ "type": "PERSISTENT"
+ }
+ ],
+ "id": "4006034190819017667",
+ "kind": "compute#instance",
+ "machineType": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/machineTypes/n1-standard-1",
+ "metadata": {
+ "fingerprint": "42WmSpB8rSM=",
+ "kind": "compute#metadata"
+ },
+ "name": "sn-node-name",
+ "networkInterfaces": [
+ {
+ "accessConfigs": [
+ {
+ "kind": "compute#accessConfig",
+ "name": "External NAT",
+ "natIP": "23.236.58.15",
+ "type": "ONE_TO_ONE_NAT"
+ }
+ ],
+ "name": "nic0",
+ "network": "https://www.googleapis.com/compute/v1/projects/project_name/global/networks/default",
+ "subnetwork": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1/subnetworks/cf-972cf02e6ad49112",
+ "networkIP": "10.240.72.75"
+ }
+ ],
+ "scheduling": {
+ "automaticRestart": true,
+ "onHostMaintenance": "MIGRATE"
+ },
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instances/sn-node-name",
+ "status": "RUNNING",
+ "tags": {
+ "fingerprint": "42WmSpB8rSM="
+ },
+ "zone": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a"
+}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/735a786e/libcloud/test/compute/test_gce.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py
index 77e3775..88ca644 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -655,6 +655,46 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
size, image, location=zone, ex_network=network,
ex_nic_gce_struct=ex_nic_gce_struct)
+ def test_create_node_subnetwork_opts(self):
+ node_name = 'sn-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('custom-network')
+ subnetwork = self.driver.ex_get_subnetwork('cf-972cf02e6ad49112')
+
+ ex_nic_gce_struct = [
+ {
+ "network": "global/networks/custom-network",
+ "subnetwork": "projects/project_name/regions/us-central1/subnetworks/cf-972cf02e6ad49112",
+ "accessConfigs": [
+ {
+ "name": "External NAT",
+ "type": "ONE_TO_ONE_NAT"
+ }
+ ]
+ }
+ ]
+ # Test using just the network and subnetwork
+ node = self.driver.create_node(node_name, size, image, location=zone,
+ ex_network=network,
+ ex_subnetwork=subnetwork)
+ self.assertEqual(node.extra['networkInterfaces'][0]["name"], 'nic0')
+ self.assertEqual(node.extra['networkInterfaces'][0]["subnetwork"].split('/')[-1],
'cf-972cf02e6ad49112')
+
+ # 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')
+ self.assertEqual(node.extra['networkInterfaces'][0]["subnetwork"].split('/')[-1],
'cf-972cf02e6ad49112')
+
+ # Test using subnetwork selfLink
+ node = self.driver.create_node(node_name, size, image, location=zone,
+ ex_network=network,
+ ex_subnetwork=subnetwork.extra['selfLink'])
+ self.assertEqual(node.extra['networkInterfaces'][0]["name"], 'nic0')
+ self.assertEqual(node.extra['networkInterfaces'][0]["subnetwork"].split('/')[-1],
'cf-972cf02e6ad49112')
+
def test_create_node_disk_opts(self):
node_name = 'node-name'
size = self.driver.ex_get_size('n1-standard-1')
@@ -1810,6 +1850,10 @@ class GCEMockHttp(MockHttpTestCase):
body = self.fixtures.load('global_networks.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+ def _global_networks_custom_network(self, method, url, body, headers):
+ body = self.fixtures.load('global_networks_custom_network.json')
+ return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+
def _global_networks_cf(self, method, url, body, headers):
body = self.fixtures.load('global_networks_cf.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
@@ -2632,6 +2676,11 @@ class GCEMockHttp(MockHttpTestCase):
body = self.fixtures.load('zones_us-central1-a_instances.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+ def _zones_us_central1_a_instances_sn_node_name(self, method, url, body,
+ headers):
+ body = self.fixtures.load('zones_us-central1-a_instances_sn-node-name.json')
+ return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+
def _zones_us_central1_a_instances_node_name(self, method, url, body,
headers):
if method == 'DELETE':
|