libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [1/2] libcloud git commit: [LIBCLOUD-985] Add coverage for newer GCE network and subnet creation options.
Date Fri, 30 Mar 2018 06:03:53 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk ed0406043 -> 4faa332c7


[LIBCLOUD-985] Add coverage for newer GCE network and subnet creation options.

Signed-off-by: Quentin Pradet <quentinp@apache.org>


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

Branch: refs/heads/trunk
Commit: 9702f72b57f9b1372c289146a20cf201a0d6ea5d
Parents: ed04060
Author: Max <maxlip@gmail.com>
Authored: Tue Mar 13 12:12:56 2018 -0700
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Fri Mar 30 10:01:47 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/gce.py                 | 40 ++++++++++++++++++--
 .../fixtures/gce/global_networks_lcnetwork.json |  3 ++
 ...entral1_subnetworks_cf_972cf02e6ad49112.json | 28 +++++++++-----
 libcloud/test/compute/test_gce.py               | 24 ++++++++++--
 4 files changed, 78 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/9702f72b/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index 311997f..80b6aa1 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -3770,7 +3770,8 @@ class GCENodeDriver(NodeDriver):
         return self.ex_get_sslcertificate(name)
 
     def ex_create_subnetwork(self, name, cidr=None, network=None, region=None,
-                             description=None):
+                             description=None, privateipgoogleaccess=None,
+                             secondaryipranges=None):
         """
         Create a subnetwork.
 
@@ -3789,6 +3790,17 @@ class GCENodeDriver(NodeDriver):
         :param  description: Custom description for the network.
         :type   description: ``str`` or ``None``
 
+        :param  privateipgoogleaccess: Allow access to Google services without
+                                       assigned external IP addresses.
+        :type   privateipgoogleaccess: ``bool` or ``None``
+
+        :param  secondaryipranges: List of dicts of secondary or "alias" IP
+                                   ranges for this subnetwork in
+                                   [{"rangeName": "second1",
+                                   "ipCidrRange": "192.168.168.0/24"},
+                                   {k:v, k:v}] format.
+        :type   secondaryipranges: ``list`` of ``dict`` or ``None``
+
         :return:  Subnetwork object
         :rtype:   :class:`GCESubnetwork`
         """
@@ -3825,6 +3837,8 @@ class GCENodeDriver(NodeDriver):
         subnet_data['ipCidrRange'] = cidr
         subnet_data['network'] = network_url
         subnet_data['region'] = region_url
+        subnet_data['privateIpGoogleAccess'] = privateipgoogleaccess
+        subnet_data['secondaryIpRanges'] = secondaryipranges
         region_name = region_url.split('/')[-1]
 
         request = '/regions/%s/subnetworks' % (region_name)
@@ -3832,7 +3846,8 @@ class GCENodeDriver(NodeDriver):
 
         return self.ex_get_subnetwork(name, region_name)
 
-    def ex_create_network(self, name, cidr, description=None, mode="legacy"):
+    def ex_create_network(self, name, cidr, description=None,
+                          mode="legacy", routing_mode=None):
         """
         Create a network. In November 2015, Google introduced Subnetworks and
         suggests using networks with 'auto' generated subnetworks. See, the
@@ -3853,6 +3868,11 @@ class GCENodeDriver(NodeDriver):
         :param  mode: Create a 'auto', 'custom', or 'legacy' network.
         :type   mode: ``str``
 
+        :param  routing_mode: Create network with 'Global' or 'Regional'
+                              routing mode for BGP advertisements.
+                              Defaults to 'Regional'
+        :type   routing_mode: ``str`` or ``None``
+
         :return:  Network object
         :rtype:   :class:`GCENetwork`
         """
@@ -3865,8 +3885,6 @@ class GCENodeDriver(NodeDriver):
         if cidr and mode in ['auto', 'custom']:
             raise ValueError("Can only specify IPv4Range with 'legacy' mode.")
 
-        request = '/global/networks'
-
         if mode == 'legacy':
             if not cidr:
                 raise ValueError("Must specify IPv4Range with 'legacy' mode.")
@@ -3874,6 +3892,16 @@ class GCENodeDriver(NodeDriver):
         else:
             network_data['autoCreateSubnetworks'] = (mode.lower() == 'auto')
 
+        if routing_mode.lower() not in ['regional', 'global']:
+            raise ValueError("Invalid Routing Mode: '%s'. Must be 'REGIONAL', "
+                             "or 'GLOBAL'." % routing_mode)
+        else:
+            network_data['routingConfig'] = {
+                'routingMode': routing_mode.upper()
+            }
+
+        request = '/global/networks'
+
         self.connection.async_request(request, method='POST',
                                       data=network_data)
 
@@ -8570,6 +8598,9 @@ class GCENodeDriver(NodeDriver):
         extra['network'] = subnetwork.get('network')
         extra['region'] = subnetwork.get('region')
         extra['selfLink'] = subnetwork.get('selfLink')
+        extra['privateIpGoogleAccess'] = \
+            subnetwork.get('privateIpGoogleAccess')
+        extra['secondaryIpRanges'] = subnetwork.get('secondaryIpRanges')
         network = self._get_object_by_kind(subnetwork.get('network'))
         region = self._get_object_by_kind(subnetwork.get('region'))
 
@@ -8599,6 +8630,7 @@ class GCENodeDriver(NodeDriver):
         # 'auto' or 'custom'
         extra['autoCreateSubnetworks'] = network.get('autoCreateSubnetworks')
         extra['subnetworks'] = network.get('subnetworks')
+        extra['routingConfig'] = network.get('routingConfig')
 
         # match Cloud SDK 'gcloud'
         if 'autoCreateSubnetworks' in network:

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9702f72b/libcloud/test/compute/fixtures/gce/global_networks_lcnetwork.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/global_networks_lcnetwork.json b/libcloud/test/compute/fixtures/gce/global_networks_lcnetwork.json
index 8e2da6c..76a26a2 100644
--- a/libcloud/test/compute/fixtures/gce/global_networks_lcnetwork.json
+++ b/libcloud/test/compute/fixtures/gce/global_networks_lcnetwork.json
@@ -6,5 +6,8 @@
   "id": "16211908079305042870",
   "kind": "compute#network",
   "name": "lcnetwork",
+  "routingConfig": {
+    "routingMode": "REGIONAL"
+  },
   "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/global/networks/lcnetwork"
 }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9702f72b/libcloud/test/compute/fixtures/gce/regions_us-central1_subnetworks_cf_972cf02e6ad49112.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/regions_us-central1_subnetworks_cf_972cf02e6ad49112.json
b/libcloud/test/compute/fixtures/gce/regions_us-central1_subnetworks_cf_972cf02e6ad49112.json
index 1b19b3d..ddaa8de 100644
--- a/libcloud/test/compute/fixtures/gce/regions_us-central1_subnetworks_cf_972cf02e6ad49112.json
+++ b/libcloud/test/compute/fixtures/gce/regions_us-central1_subnetworks_cf_972cf02e6ad49112.json
@@ -1,12 +1,20 @@
 {
- "status": "DONE",
- "kind": "compute#subnetwork",
- "id": "4297043163355844284",
- "creationTimestamp": "2016-03-25T05:34:27.209-07:00",
- "gatewayAddress": "10.128.0.1",
- "name": "cf-972cf02e6ad49112",
- "network": "https://www.googleapis.com/compute/v1/projects/project_name/global/networks/cf",
- "ipCidrRange": "10.128.0.0/20",
- "region": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1",
- "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1/subnetworks/cf-972cf02e6ad49112"
+  "status": "DONE",
+  "kind": "compute#subnetwork",
+  "id": "4297043163355844284",
+  "creationTimestamp": "2016-03-25T05:34:27.209-07:00",
+  "description": "LCTestSubnet",
+  "gatewayAddress": "10.128.0.1",
+  "name": "cf-972cf02e6ad49112",
+  "network": "https://www.googleapis.com/compute/v1/projects/project_name/global/networks/cf",
+  "ipCidrRange": "10.128.0.0/20",
+  "privateIpGoogleAccess": true,
+  "region": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1",
+  "secondaryIpRanges": [
+    {
+      "ipCidrRange": "192.168.168.0/24",
+      "rangeName": "secondary"
+    }
+  ],
+  "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1/subnetworks/cf-972cf02e6ad49112"
 }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9702f72b/libcloud/test/compute/test_gce.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py
index cd211a0..d727c15 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -522,14 +522,20 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
         network = self.driver.ex_get_network(network_name)
         region_name = 'us-central1'
         region = self.driver.ex_get_region(region_name)
+        description = 'LCTestSubnet'
+        privateipgoogleaccess = True
+        secondaryipranges = [{"rangeName": "secondary", "ipCidrRange": "192.168.168.0/24"}]
         # test by network/region name
-        subnet = self.driver.ex_create_subnetwork(name, cidr, network_name,
-                                                  region_name)
+        subnet = self.driver.ex_create_subnetwork(
+            name, cidr, network_name, region_name, description=description,
+            privateipgoogleaccess=privateipgoogleaccess, secondaryipranges=secondaryipranges)
         self.assertTrue(isinstance(subnet, GCESubnetwork))
         self.assertTrue(isinstance(subnet.region, GCERegion))
         self.assertTrue(isinstance(subnet.network, GCENetwork))
         self.assertEqual(subnet.name, name)
         self.assertEqual(subnet.cidr, cidr)
+        self.assertEqual(subnet.extra['privateIpGoogleAccess'], privateipgoogleaccess)
+        self.assertEqual(subnet.extra['secondaryIpRanges'], secondaryipranges)
         # test by network/region object
         subnet = self.driver.ex_create_subnetwork(name, cidr, network, region)
         self.assertTrue(isinstance(subnet, GCESubnetwork))
@@ -537,6 +543,8 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
         self.assertTrue(isinstance(subnet.network, GCENetwork))
         self.assertEqual(subnet.name, name)
         self.assertEqual(subnet.cidr, cidr)
+        self.assertEqual(subnet.extra['privateIpGoogleAccess'], privateipgoogleaccess)
+        self.assertEqual(subnet.extra['secondaryIpRanges'], secondaryipranges)
 
     def test_ex_destroy_subnetwork(self):
         name = 'cf-972cf02e6ad49112'
@@ -983,11 +991,19 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
     def test_ex_create_network(self):
         network_name = 'lcnetwork'
         cidr = '10.11.0.0/16'
-        network = self.driver.ex_create_network(network_name, cidr)
+        routing_mode = 'REGIONAL'
+        network = self.driver.ex_create_network(network_name, cidr, routing_mode='regional')
         self.assertTrue(isinstance(network, GCENetwork))
         self.assertEqual(network.name, network_name)
         self.assertEqual(network.cidr, cidr)
 
+        # Test using more options
+        network = self.driver.ex_create_network(network_name, cidr,
+                                                description=description,
+                                                routing_mode=routing_mode)
+        self.assertEqual(network.extra['description'], description)
+        self.assertEqual(network.extra['routingConfig']['routingMode'], routing_mode)
+
     def test_ex_create_network_bad_options(self):
         network_name = 'lcnetwork'
         cidr = '10.11.0.0/16'
@@ -997,6 +1013,8 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
                           network_name, cidr, mode='foobar')
         self.assertRaises(ValueError, self.driver.ex_create_network,
                           network_name, None, mode='legacy')
+        self.assertRaises(ValueError, self.driver.ex_create_network,
+                          network_name, cidr, routing_mode='universal')
 
     def test_ex_set_machine_type_notstopped(self):
         # get running node, change machine type


Mime
View raw message