You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2019/07/18 08:57:01 UTC

[libcloud] 02/03: Add "ex_" prefix to the argument since it's not part of the standard API, update affected tests, add new ones and revert NodeImage name change - we want to use "name" value as returned by the provided.

This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit e589bd55e2493253d8f628558364729dd6e585c7
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Thu Jul 18 10:47:24 2019 +0200

    Add "ex_" prefix to the argument since it's not part of the standard
    API, update affected tests, add new ones and revert NodeImage name
    change - we want to use "name" value as returned by the provided.
    
    Also remove "ex_start_node" since there already is "ex_power_on_node"
    method.
---
 libcloud/compute/drivers/digitalocean.py                 | 16 +++++-----------
 .../compute/fixtures/digitalocean_v2/list_locations.json |  4 ++--
 libcloud/test/compute/test_digitalocean_v2.py            |  8 +++++++-
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py
index 441c24c..c6a414a 100644
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@ -112,16 +112,17 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver,
         data = self._paginated_request('/v2/account/keys', 'ssh_keys')
         return list(map(self._to_key_pair, data))
 
-    def list_locations(self, available=True):
+    def list_locations(self, ex_available=True):
         """
         List locations
 
-        If available is True, show only locations which are available
+        :param ex_available: Only return locations which are available.
+        :type ex_evailable: ``bool``
         """
         locations = []
         data = self._paginated_request('/v2/regions', 'regions')
         for location in data:
-            if available:
+            if ex_available:
                 if location.get('available'):
                     locations.append(self._to_location(location))
             else:
@@ -199,12 +200,6 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver,
 
         return self._to_node(data=data)
 
-    def ex_start_node(self, node):
-        params = {"type": "power_on"}
-        res = self.connection.request('/v2/droplets/%s/actions/' % node.id,
-                                      params=params, method='POST')
-        return res.status in [httplib.OK, httplib.CREATED, httplib.ACCEPTED]
-
     def destroy_node(self, node):
         res = self.connection.request('/v2/droplets/%s' % (node.id),
                                       method='DELETE')
@@ -669,8 +664,7 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver,
                  'regions': data['regions'],
                  'min_disk_size': data['min_disk_size'],
                  'created_at': data['created_at']}
-        name = "%s %s" % (data.get('distribution'), data.get('name'))
-        return NodeImage(id=data['id'], name=name, driver=self,
+        return NodeImage(id=data['id'], name=data['name'], driver=self,
                          extra=extra)
 
     def _to_volume(self, data):
diff --git a/libcloud/test/compute/fixtures/digitalocean_v2/list_locations.json b/libcloud/test/compute/fixtures/digitalocean_v2/list_locations.json
index 50a4831..afd2555 100644
--- a/libcloud/test/compute/fixtures/digitalocean_v2/list_locations.json
+++ b/libcloud/test/compute/fixtures/digitalocean_v2/list_locations.json
@@ -7,7 +7,7 @@
         "1gb",
         "512mb"
       ],
-      "available": false,
+      "available": true,
       "features": [
         "virtio",
         "private_networking",
@@ -35,7 +35,7 @@
         "1gb",
         "512mb"
       ],
-      "available": true,
+      "available": false,
       "features": [
         "virtio",
         "backups"
diff --git a/libcloud/test/compute/test_digitalocean_v2.py b/libcloud/test/compute/test_digitalocean_v2.py
index dc77520..a98d601 100644
--- a/libcloud/test/compute/test_digitalocean_v2.py
+++ b/libcloud/test/compute/test_digitalocean_v2.py
@@ -82,12 +82,18 @@ class DigitalOcean_v2_Tests(LibcloudTestCase):
 
     def test_list_locations_success(self):
         locations = self.driver.list_locations()
-        self.assertTrue(len(locations) >= 1)
+        self.assertTrue(len(locations) == 2)
 
         location = locations[0]
         self.assertEqual(location.id, 'nyc1')
         self.assertEqual(location.name, 'New York 1')
 
+        locations = self.driver.list_locations(ex_available=True)
+        self.assertTrue(len(locations) == 2)
+
+        locations = self.driver.list_locations(ex_available=False)
+        self.assertTrue(len(locations) == 3)
+
     def test_list_nodes_success(self):
         nodes = self.driver.list_nodes()
         self.assertEqual(len(nodes), 1)