You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by vd...@apache.org on 2018/12/04 08:54:16 UTC

[01/23] libcloud git commit: Fix OpenStackException issue

Repository: libcloud
Updated Branches:
  refs/heads/trunk cd2faa7f9 -> a4d0081b2


Fix OpenStackException issue


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

Branch: refs/heads/trunk
Commit: 85b6f4a29c91dca6631dbff7cc25225f60cb70ba
Parents: 6df2a52
Author: micafer <mi...@upv.es>
Authored: Thu Nov 29 08:16:38 2018 +0100
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/85b6f4a2/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 71bef6a..5a64f26 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1168,7 +1168,8 @@ class OpenStackSecurityGroupRule(object):
                 self.direction = direction
             else:
                 raise OpenStackException("Security group direction incorrect "
-                                         "value: ingress or egress.")
+                                         "value: ingress or egress.", 500,
+                                         driver)
 
         self.tenant_id = tenant_id
         self.extra = extra or {}


[23/23] libcloud git commit: Add changes for #1241

Posted by vd...@apache.org.
Add changes for #1241

Closes #1242


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

Branch: refs/heads/trunk
Commit: a4d0081b2a6a79917d493fcfd52eb6497635a1f8
Parents: 23e8d08
Author: Rick van de Loo <ri...@gmail.com>
Authored: Tue Dec 4 09:49:19 2018 +0100
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:49:19 2018 +0100

----------------------------------------------------------------------
 CHANGES.rst | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a4d0081b/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index de08d85..904dc9b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -25,6 +25,57 @@ Compute
 - [OpenStack] Implement OpenStack_1_1_NodeDriver ex_get_snapshot (GITHUB-1257)
   [Rick van de Loo]
 
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_create_subnet (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_delete_subnet (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver list_volumes (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_get_volume (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver create_volume (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver destroy_volume (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_list_snapshots (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver create_volume_snapshot (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver destroy_volume_snapshot (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_list_security_groups (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_create_security_group (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_delete_security_group (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_create_security_group_rule (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_delete_security_group_rule (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Implement OpenStack_2_NodeDriver ex_list_floating_ip_pools (LIBCLOUD-874, GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Fix parse_error if 'code' not in API response message (GITHUB-1242)
+  [Miguel Caballer]
+
+- [OpenStack] Adapt _to_port function to work with old OpenStack versions (GITHUB-1242)
+  [Miguel Caballer]
+
 - [UpCloud] Update documentation for UpCloud driver (LIBCLOUD-1026, GITHUB-1259)
   [Ilari Mäkelä]
 


[19/23] libcloud git commit: Improve comment

Posted by vd...@apache.org.
Improve comment


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

Branch: refs/heads/trunk
Commit: 6df2a52572b27d7efb1d8ae85220cc8ca46ccf88
Parents: e5a6986
Author: micafer <mi...@upv.es>
Authored: Wed Nov 28 16:37:19 2018 +0100
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/6df2a525/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 3aebda3..71bef6a 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2600,10 +2600,9 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
     network_connectionCls = OpenStack_2_NetworkConnection
     network_connection = None
 
-    # Similarly not all node-related operations are exposed through the
-    # compute API
-    # See https://developer.openstack.org/api-ref/compute/
-    # For example, volume management are made in the cinder service
+    # Similarly all image operations are noe exposed through the block-storage
+    # API of the cinde service:
+    # https://developer.openstack.org/api-ref/block-storage/
     volumev2_connectionCls = OpenStack_2_VolumeV2Connection
     volumev2_connection = None
 


[13/23] libcloud git commit: Update comment

Posted by vd...@apache.org.
Update comment


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

Branch: refs/heads/trunk
Commit: 830a0f83742b40226790f021cd15b8e19893b75f
Parents: 119cfa8
Author: micafer <mi...@upv.es>
Authored: Tue Sep 25 16:54:01 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/830a0f83/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index ebcefc2..7e78d42 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -3273,7 +3273,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         """
         List available floating IP pools
 
-        :rtype: ``list`` of :class:`OpenStack_1_1_FloatingIpPool`
+        :rtype: ``list`` of :class:`OpenStack_2_FloatingIpPool`
         """
         return self._to_floating_ip_pools(
             self.network_connection.request('/v2.0/networks?router:external'


[17/23] libcloud git commit: Remove prints

Posted by vd...@apache.org.
Remove prints


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

Branch: refs/heads/trunk
Commit: a2faa5566af5e1fb896c09271c69ec6ce7eef68d
Parents: ca5430d
Author: micafer <mi...@upv.es>
Authored: Tue Oct 23 12:20:16 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/a2faa556/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index ec71091..b5914ff 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1853,8 +1853,6 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         :rtype: ``list`` of :class:`OpenStackSecurityGroup`
         """
-        print(vars(self.connection.request(
-            '/servers/%s/os-security-groups' % (node.id))))
         return self._to_security_groups(
             self.connection.request('/servers/%s/os-security-groups' %
                                     (node.id)).object)
@@ -3442,7 +3440,6 @@ class OpenStack_2_FloatingIpPool(OpenStack_1_1_FloatingIpPool):
     def _to_floating_ip(self, obj):
         instance_id = None
 
-        print(obj)
         # In neutron version prior to 13.0.0 port_details does not exists
         if 'port_details' not in obj and 'port_id' in obj and obj['port_id']:
             port = self.connection.driver.ex_get_port(obj['port_id'])


[02/23] libcloud git commit: Change order in gets

Posted by vd...@apache.org.
Change order in gets


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

Branch: refs/heads/trunk
Commit: 33728b26d4937ba9bd4336ead1ea8d077a0af660
Parents: 8b19d31
Author: micafer <mi...@upv.es>
Authored: Wed Nov 28 12:10:50 2018 +0100
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/33728b26/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index da17e6c..f244f91 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2220,14 +2220,13 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         return StorageVolume(
             id=api_node['id'],
-            name=api_node.get('name', api_node.get('displayName')),
+            name=api_node.get('displayName', api_node.get('name')),
             size=api_node['size'],
             state=state,
             driver=self,
             extra={
-                'description': api_node.get('description',
-                                            api_node.get('displayDescription')
-                                            ),
+                'description': api_node.get('displayDescription',
+                                            api_node.get('description')),
                 'attachments': [att for att in api_node['attachments'] if att],
                 # TODO: remove in 1.18.0
                 'state': api_node.get('status', None),


[10/23] libcloud git commit: Add cinder support LIBCLOUD-874

Posted by vd...@apache.org.
Add cinder support LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: d66638a0db0549353ff7c2856458127283ca5529
Parents: c8d253f
Author: micafer <mi...@upv.es>
Authored: Mon Sep 24 16:32:58 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py                     | 2 +-
 libcloud/test/common/test_openstack_identity.py           | 2 +-
 libcloud/test/compute/fixtures/openstack/_v2_0__auth.json | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/d66638a0/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 4fcdda6..df42acd 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -91,7 +91,7 @@ class OpenStackNetworkConnection(OpenStackBaseConnection):
 
 class OpenStackVolumeV2Connection(OpenStackBaseConnection):
     service_type = 'volumev2'
-    service_name = 'cinder'
+    service_name = 'cinderv2'
     service_region = 'RegionOne'
 
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d66638a0/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py
index c93cee3..3d7d074 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -626,7 +626,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
                                           auth_version='2.0')
 
         service_names = catalog.get_service_names()
-        self.assertEqual(service_names, ['cinder', 'cloudFiles',
+        self.assertEqual(service_names, ['cinderv2', 'cloudFiles',
                                          'cloudFilesCDN', 'cloudServers',
                                          'cloudServersOpenStack',
                                          'cloudServersPreprod',

http://git-wip-us.apache.org/repos/asf/libcloud/blob/d66638a0/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
index d2bd3c3..3727df8 100644
--- a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
+++ b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
@@ -139,7 +139,7 @@
                         "versionId": "2"
                     }
                 ],
-                "name": "cinder",
+                "name": "cinderv2",
                 "type": "volumev2"
             },
             {


[07/23] libcloud git commit: Add cinder support LIBCLOUD-874

Posted by vd...@apache.org.
Add cinder support LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: 3c93d267e055c04f7a5f7274358fa64bcf5e5313
Parents: c4b5cfa
Author: micafer <mi...@upv.es>
Authored: Mon Sep 24 15:19:43 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 docs/compute/drivers/openstack.rst | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/3c93d267/docs/compute/drivers/openstack.rst
----------------------------------------------------------------------
diff --git a/docs/compute/drivers/openstack.rst b/docs/compute/drivers/openstack.rst
index 887057a..24dd839 100644
--- a/docs/compute/drivers/openstack.rst
+++ b/docs/compute/drivers/openstack.rst
@@ -99,6 +99,10 @@ Available arguments:
   driver obtains API endpoint URL from the server catalog, but if this argument
   is provided, this step is skipped and the provided value is used directly. Only valid 
   in case of api_version >= 2.0.
+  * ``ex_force_volume_url`` - Base URL to the OpenStack cinder API endpoint. By default,
+  driver obtains API endpoint URL from the server catalog, but if this argument
+  is provided, this step is skipped and the provided value is used directly. Only valid 
+  in case of api_version >= 2.0.
 
 Some examples which show how to use this arguments can be found in the section
 below.


[03/23] libcloud git commit: Fix conn issues

Posted by vd...@apache.org.
Fix conn issues


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

Branch: refs/heads/trunk
Commit: 8b19d31ab53595014c0791b85663478767ad0f82
Parents: 9c0da3d
Author: micafer <mi...@upv.es>
Authored: Tue Oct 23 16:34:43 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/8b19d31a/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 868ae09..da17e6c 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2931,8 +2931,8 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         """
         data = {'subnet': {'cidr': cidr, 'network_id': network.id,
                            'ip_version': ip_version, 'name': name}}
-        response = self.connection.request(self._subnets_url_prefix,
-                                           method='POST', data=data).object
+        response = self.network_connection.request(
+            self._subnets_url_prefix, method='POST', data=data).object
         return self._to_subnet(response['subnet'])
 
     def ex_delete_subnet(self, subnet):
@@ -2944,9 +2944,8 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
 
         :rtype: ``bool``
         """
-        resp = self.connection.request('%s/%s' % (self._subnets_url_prefix,
-                                                  subnet.id),
-                                       method='DELETE')
+        resp = self.network_connection.request('%s/%s' % (
+            self._subnets_url_prefix, subnet.id), method='DELETE')
         return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
 
     def ex_list_ports(self):


[14/23] libcloud git commit: Remove print

Posted by vd...@apache.org.
Remove print


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

Branch: refs/heads/trunk
Commit: 119cfa83f61419da5cade80ec9f63fb9f54601b6
Parents: d34b3f0
Author: micafer <mi...@upv.es>
Authored: Tue Sep 25 16:38:45 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/common/openstack.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/119cfa83/libcloud/common/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack.py b/libcloud/common/openstack.py
index db9f43f..6e7d5b5 100644
--- a/libcloud/common/openstack.py
+++ b/libcloud/common/openstack.py
@@ -390,7 +390,7 @@ class OpenStackResponse(Response):
             context = self.connection.context
             driver = self.connection.driver
             key_pair_name = context.get('key_pair_name', None)
-            print(values)
+
             if len(values) > 0 and 'code' in values[0] and \
                     values[0]['code'] == 404 and key_pair_name:
                 raise KeyPairDoesNotExistError(name=key_pair_name,


[22/23] libcloud git commit: Fix error in ex_list_ports if created_at is not in result

Posted by vd...@apache.org.
Fix error in ex_list_ports if created_at is not in result

Signed-off-by: Rick van de Loo <ri...@gmail.com>


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

Branch: refs/heads/trunk
Commit: 23e8d08439f430d74524fdafd4a67f5fff84f339
Parents: 85b6f4a
Author: micafer <mi...@upv.es>
Authored: Thu Nov 29 16:47:54 2018 +0100
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:47:53 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/23e8d084/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 5a64f26..5affde6 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2668,7 +2668,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
 
     def _to_port(self, element):
-        created = element['created_at']
+        created = element.get('created_at')
         updated = element.get('updated_at')
         return OpenStack_2_PortInterface(
             id=element['id'],


[18/23] libcloud git commit: Move sec groups to neutron api LIBCLOUD-874

Posted by vd...@apache.org.
Move sec groups to neutron api LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: 2b2e1f1a4570b2e36f621062389f1cc521dd4ea3
Parents: f05ff35
Author: micafer <mi...@upv.es>
Authored: Tue Sep 25 08:57:05 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 114 +++++++++++++++++--
 .../openstack_v1.1/_v2_0__security_group.json   |  18 +--
 .../_v2_0__security_group_rule.json             |  13 +++
 .../openstack_v1.1/_v2_0__security_groups.json  |   2 +-
 libcloud/test/compute/test_openstack.py         |  24 +++-
 5 files changed, 146 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2b2e1f1a/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 20826dc..de6d445 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1112,7 +1112,7 @@ class OpenStackSecurityGroupRule(object):
 
     def __init__(self, id, parent_group_id, ip_protocol, from_port, to_port,
                  driver, ip_range=None, group=None, tenant_id=None,
-                 extra=None):
+                 direction=None, extra=None):
         """
         Constructor.
 
@@ -1140,6 +1140,9 @@ class OpenStackSecurityGroupRule(object):
         :keyword    tenant_id: Owner of the security group.
         :type       tenant_id: ``str``
 
+        :keyword    direction: Security group Direction (ingress or egress).
+        :type       direction: ``str``
+
         :keyword    extra: Extra attributes associated with this rule.
         :type       extra: ``dict``
         """
@@ -1151,12 +1154,21 @@ class OpenStackSecurityGroupRule(object):
         self.driver = driver
         self.ip_range = ''
         self.group = {}
+        self.direction = 'ingress'
 
         if group is None:
             self.ip_range = ip_range
         else:
             self.group = {'name': group, 'tenant_id': tenant_id}
 
+        # by default in old versions only ingress was used
+        if direction is not None:
+            if direction in ['ingress', 'egress']:
+                self.direction = direction
+            else:
+                raise OpenStackException("Security group direction incorrect "
+                                         "value: ingress or egress.")
+
         self.tenant_id = tenant_id
         self.extra = extra or {}
 
@@ -1678,7 +1690,7 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
         resp = self.connection.request('%s/%s' % (self._networks_url_prefix,
                                                   network.id),
                                        method='DELETE')
-        return resp.status == httplib.ACCEPTED
+        return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
 
     def ex_get_console_output(self, node, length=None):
         """
@@ -1840,6 +1852,8 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         :rtype: ``list`` of :class:`OpenStackSecurityGroup`
         """
+        print(vars(self.connection.request(
+            '/servers/%s/os-security-groups' % (node.id))))
         return self._to_security_groups(
             self.connection.request('/servers/%s/os-security-groups' %
                                     (node.id)).object)
@@ -3116,8 +3130,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
     def destroy_volume_snapshot(self, snapshot):
         resp = self.volumev2_connection.request('/snapshots/%s' % snapshot.id,
                                                 method='DELETE')
-        return resp.status == httplib.ACCEPTED
-
+        return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
 
     def ex_list_security_groups(self):
         """
@@ -3155,9 +3168,96 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         :rtype: ``bool``
         """
         resp = self.network_connection.request('/v2.0/security-groups/%s' %
-                                       (security_group.id),
-                                       method='DELETE')
-        return resp.status==httplib.NO_CONTENT
+                                               (security_group.id),
+                                               method='DELETE')
+        return resp.status == httplib.NO_CONTENT
+
+    def _to_security_group_rule(self, obj):
+        ip_range = group = tenant_id = parent_id = None
+        protocol = from_port = to_port = direction = None
+
+        if 'parent_group_id' in obj:
+            if obj['group'] == {}:
+                ip_range = obj['ip_range'].get('cidr', None)
+            else:
+                group = obj['group'].get('name', None)
+                tenant_id = obj['group'].get('tenant_id', None)
+
+            parent_id = obj['parent_group_id']
+            from_port = obj['from_port']
+            to_port = obj['to_port']
+            protocol = obj['ip_protocol']
+        else:
+            ip_range = obj.get('remote_ip_prefix', None)
+            group = obj.get('remote_group_id', None)
+            tenant_id = obj.get('tenant_id', None)
+
+            parent_id = obj['security_group_id']
+            from_port = obj['port_range_min']
+            to_port = obj['port_range_max']
+            protocol = obj['protocol']
+
+        return OpenStackSecurityGroupRule(
+            id=obj['id'], parent_group_id=parent_id,
+            ip_protocol=protocol, from_port=from_port,
+            to_port=to_port, driver=self, ip_range=ip_range,
+            group=group, tenant_id=tenant_id, direction=direction)
+
+    def ex_create_security_group_rule(self, security_group, ip_protocol,
+                                      from_port, to_port, cidr=None,
+                                      source_security_group=None):
+        """
+        Create a new Rule in a Security Group
+
+        :param security_group: Security Group in which to add the rule
+        :type  security_group: :class:`OpenStackSecurityGroup`
+
+        :param ip_protocol: Protocol to which this rule applies
+                            Examples: tcp, udp, ...
+        :type  ip_protocol: ``str``
+
+        :param from_port: First port of the port range
+        :type  from_port: ``int``
+
+        :param to_port: Last port of the port range
+        :type  to_port: ``int``
+
+        :param cidr: CIDR notation of the source IP range for this rule
+        :type  cidr: ``str``
+
+        :param source_security_group: Existing Security Group to use as the
+                                      source (instead of CIDR)
+        :type  source_security_group: L{OpenStackSecurityGroup
+
+        :rtype: :class:`OpenStackSecurityGroupRule`
+        """
+        source_security_group_id = None
+        if type(source_security_group) == OpenStackSecurityGroup:
+            source_security_group_id = source_security_group.id
+
+        return self._to_security_group_rule(self.network_connection.request(
+            '/v2.0/security-group-rules', method='POST',
+            data={'security_group_rule': {
+                'protocol': ip_protocol,
+                'port_range_min': from_port,
+                'port_range_max': to_port,
+                'remote_ip_prefix': cidr,
+                'remote_group_id': source_security_group_id,
+                'security_group_id': security_group.id}}
+        ).object['security_group_rule'])
+
+    def ex_delete_security_group_rule(self, rule):
+        """
+        Delete a Rule from a Security Group.
+
+        :param rule: Rule should be deleted
+        :type  rule: :class:`OpenStackSecurityGroupRule`
+
+        :rtype: ``bool``
+        """
+        resp = self.connection.request('/v2.0/security-group-rules/%s' %
+                                       (rule.id), method='DELETE')
+        return resp.status == httplib.NO_CONTENT
 
 
 class OpenStack_1_1_FloatingIpPool(object):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2b2e1f1a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
index df20ef4..d01f206 100644
--- a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
@@ -1,20 +1,10 @@
 {
     "security_group":
         {
-            "description": "FTP Client-Server - Open 20-21 ports", 
-            "id": 4, 
-            "name": "ftp", 
-            "security_group_rules": [
-                {
-                    "security_group_id": "4",
-                    "direction": "ingress",
-                    "port_range_max": 21, 
-                    "port_range_min": 20, 
-                    "remote_ip_prefix": "0.0.0.0/0", 
-                    "id": 1, 
-                    "protocol": "tcp"
-                }
-            ], 
+            "description": "Test Security Group", 
+            "id": 6, 
+            "name": "test", 
+            "security_group_rules": [], 
             "tenant_id": "68"
         }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2b2e1f1a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group_rule.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group_rule.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group_rule.json
new file mode 100644
index 0000000..2004b5d
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group_rule.json
@@ -0,0 +1,13 @@
+{
+    "security_group_rule":
+        {
+            "security_group_id": 6,
+            "direction": "ingress",
+            "port_range_max": 16, 
+            "port_range_min": 14, 
+            "remote_ip_prefix": "0.0.0.0/0", 
+            "id": 2, 
+            "protocol": "tcp"
+        }
+}
+

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2b2e1f1a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
index 5fd84f4..5720901 100644
--- a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
@@ -13,7 +13,7 @@
             "name": "ftp", 
             "security_group_rules": [
                 {
-                    "security_group_id": "4",
+                    "security_group_id": 4,
                     "direction": "ingress",
                     "port_range_max": 21, 
                     "port_range_min": 20, 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2b2e1f1a/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 618b7f5..3faea2b 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -2387,7 +2387,7 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
             return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
         if method == 'DELETE':
             body = ''
-            return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
+            return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v2_1337_v2_0_subnets(self, method, url, body, headers):
         body = self.fixtures.load('_v2_0__subnets.json')
@@ -2408,7 +2408,7 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
             return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
         if method == 'DELETE':
             body = ''
-            return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
+            return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
     
     def _v2_1337_snapshots_detail(self, method, url, body, headers):
         body = self.fixtures.load('_v2_0__snapshots.json')
@@ -2425,15 +2425,33 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
             return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
         if method == 'DELETE':
             body = ''
-            return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
+            return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v2_1337_v2_0_security_groups(self, method, url, body, headers):
         if method == 'POST':
             body = self.fixtures.load('_v2_0__security_group.json')
             return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
         if method == 'GET':
+            body = self.fixtures.load('_v2_0__security_groups.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_v2_0_security_groups_6(self, method, url, body, headers):
+        if method == 'GET':
             body = self.fixtures.load('_v2_0__security_group.json')
             return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'DELETE':
+            body = ''
+            return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_v2_0_security_group_rules(self, method, url, body, headers):
+        if method == 'POST':
+            body = self.fixtures.load('_v2_0__security_group_rule.json')
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_v2_0_security_group_rules_2(self, method, url, body, headers):
+        if method == 'DELETE':
+            body = ''
+            return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
 
 # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures
 # work fine.


[11/23] libcloud git commit: Move sec groups to neutron api LIBCLOUD-874

Posted by vd...@apache.org.
Move sec groups to neutron api LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: f05ff35bfcf021cc12cf613a3927fcc2d764d16d
Parents: d66638a
Author: micafer <mi...@upv.es>
Authored: Mon Sep 24 17:13:29 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 44 +++++++++++++++++++-
 .../openstack_v1.1/_v2_0__security_group.json   | 20 +++++++++
 .../openstack_v1.1/_v2_0__security_groups.json  | 29 +++++++++++++
 libcloud/test/compute/test_openstack.py         | 13 ++++--
 4 files changed, 102 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index df42acd..20826dc 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1816,7 +1816,8 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
                 security_groups]
 
     def _to_security_group(self, obj):
-        rules = self._to_security_group_rules(obj.get('rules', []))
+        rules = self._to_security_group_rules(obj.get('security_group_rules',
+                                                      obj.get('rules', [])))
         return OpenStackSecurityGroup(id=obj['id'],
                                       tenant_id=obj['tenant_id'],
                                       name=obj['name'],
@@ -3118,6 +3119,47 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         return resp.status == httplib.ACCEPTED
 
 
+    def ex_list_security_groups(self):
+        """
+        Get a list of Security Groups that are available.
+
+        :rtype: ``list`` of :class:`OpenStackSecurityGroup`
+        """
+        return self._to_security_groups(
+            self.network_connection.request('/v2.0/security-groups').object)
+
+    def ex_create_security_group(self, name, description):
+        """
+        Create a new Security Group
+
+        :param name: Name of the new Security Group
+        :type  name: ``str``
+
+        :param description: Description of the new Security Group
+        :type  description: ``str``
+
+        :rtype: :class:`OpenStackSecurityGroup`
+        """
+        return self._to_security_group(self.network_connection .request(
+            '/v2.0/security-groups', method='POST',
+            data={'security_group': {'name': name, 'description': description}}
+        ).object['security_group'])
+
+    def ex_delete_security_group(self, security_group):
+        """
+        Delete a Security Group.
+
+        :param security_group: Security Group should be deleted
+        :type  security_group: :class:`OpenStackSecurityGroup`
+
+        :rtype: ``bool``
+        """
+        resp = self.network_connection.request('/v2.0/security-groups/%s' %
+                                       (security_group.id),
+                                       method='DELETE')
+        return resp.status==httplib.NO_CONTENT
+
+
 class OpenStack_1_1_FloatingIpPool(object):
     """
     Floating IP Pool info.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
new file mode 100644
index 0000000..df20ef4
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_group.json
@@ -0,0 +1,20 @@
+{
+    "security_group":
+        {
+            "description": "FTP Client-Server - Open 20-21 ports", 
+            "id": 4, 
+            "name": "ftp", 
+            "security_group_rules": [
+                {
+                    "security_group_id": "4",
+                    "direction": "ingress",
+                    "port_range_max": 21, 
+                    "port_range_min": 20, 
+                    "remote_ip_prefix": "0.0.0.0/0", 
+                    "id": 1, 
+                    "protocol": "tcp"
+                }
+            ], 
+            "tenant_id": "68"
+        }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
new file mode 100644
index 0000000..5fd84f4
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__security_groups.json
@@ -0,0 +1,29 @@
+{
+    "security_groups": [
+        {
+            "description": "default", 
+            "id": 2, 
+            "name": "default", 
+            "security_group_rules": [], 
+            "tenant_id": "68"
+        }, 
+        {
+            "description": "FTP Client-Server - Open 20-21 ports", 
+            "id": 4, 
+            "name": "ftp", 
+            "security_group_rules": [
+                {
+                    "security_group_id": "4",
+                    "direction": "ingress",
+                    "port_range_max": 21, 
+                    "port_range_min": 20, 
+                    "remote_ip_prefix": "0.0.0.0/0", 
+                    "id": 1, 
+                    "protocol": "tcp"
+                }
+            ], 
+            "tenant_id": "68"
+        }
+    ]
+}
+

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f05ff35b/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 9dc39ee..618b7f5 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -2400,7 +2400,7 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
     def _v2_1337_volumes(self, method, url, body, headers):
         if method == 'POST':
             body = self.fixtures.load('_v2_0__volume.json')
-            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v2_1337_volumes_cd76a3a1_c4ce_40f6_9b9f_07a61508938d(self, method, url, body, headers):
         if method == 'GET':
@@ -2417,7 +2417,7 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
     def _v2_1337_snapshots(self, method, url, body, headers):
         if method == 'POST':
             body = self.fixtures.load('_v2_0__snapshot.json')
-            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v2_1337_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5(self, method, url, body, headers):
         if method == 'GET':
@@ -2426,7 +2426,14 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
         if method == 'DELETE':
             body = ''
             return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
-    
+
+    def _v2_1337_v2_0_security_groups(self, method, url, body, headers):
+        if method == 'POST':
+            body = self.fixtures.load('_v2_0__security_group.json')
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__security_group.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
 # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures
 # work fine.


[08/23] libcloud git commit: Add cinder support LIBCLOUD-874

Posted by vd...@apache.org.
Add cinder support LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: 2d9e862382735e6818c01b0972758b12a6297f31
Parents: 3c93d26
Author: micafer <mi...@upv.es>
Authored: Mon Sep 24 16:10:39 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 14 +++----
 libcloud/test/common/test_openstack_identity.py |  9 +++--
 .../compute/fixtures/openstack/_v2_0__auth.json | 22 ++++++++++
 libcloud/test/compute/test_openstack.py         | 42 ++++++++++++++++++++
 4 files changed, 76 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index fba9a8a..9bd80cc 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -3015,11 +3015,11 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
 
     def list_volumes(self):
         return self._to_volumes(
-            self.connection.request('/volumes/detail').object)
+            self.volumev2_connection.request('/volumes/detail').object)
 
     def ex_get_volume(self, volumeId):
         return self._to_volume(
-            self.connection.request('/volumes/%s' % volumeId).object)
+            self.volumev2_connection.request('/volumes/%s' % volumeId).object)
 
     def create_volume(self, size, name, location=None, snapshot=None,
                       ex_volume_type=None):
@@ -3066,18 +3066,18 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         if snapshot:
             volume['snapshot_id'] = snapshot.id
 
-        resp = self.connection.request('/volumes',
+        resp = self.volumev2_connection.request('/volumes',
                                        method='POST',
                                        data={'volume': volume})
         return self._to_volume(resp.object)
 
     def destroy_volume(self, volume):
-        return self.connection.request('/volumes/%s' % volume.id,
+        return self.volumev2_connection.request('/volumes/%s' % volume.id,
                                        method='DELETE').success()
 
     def ex_list_snapshots(self):
         return self._to_snapshots(
-            self.connection.request('/snapshots/detail').object)
+            self.volumev2_connection.request('/snapshots/detail').object)
 
     def create_volume_snapshot(self, volume, name=None, ex_description=None,
                                ex_force=True):
@@ -3108,12 +3108,12 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         if ex_description is not None:
             data['snapshot']['description'] = ex_description
 
-        return self._to_snapshot(self.connection.request('/snapshots',
+        return self._to_snapshot(self.volumev2_connection.request('/snapshots',
                                                          method='POST',
                                                          data=data).object)
 
     def destroy_volume_snapshot(self, snapshot):
-        resp = self.connection.request('/snapshots/%s' % snapshot.id,
+        resp = self.volumev2_connection.request('/snapshots/%s' % snapshot.id,
                                        method='DELETE')
         return resp.status == httplib.ACCEPTED
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py
index 3ed77bb..c93cee3 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -544,7 +544,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
         catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                           auth_version='2.0')
         entries = catalog.get_entries()
-        self.assertEqual(len(entries), 8)
+        self.assertEqual(len(entries), 9)
 
         entry = [e for e in entries if e.service_name == 'cloudServers'][0]
         self.assertEqual(entry.service_type, 'compute')
@@ -611,7 +611,8 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
                                           auth_version='2.0')
         service_types = catalog.get_service_types()
         self.assertEqual(service_types, ['compute', 'image', 'network',
-                                         'object-store', 'rax:object-cdn'])
+                                         'object-store', 'rax:object-cdn',
+                                         'volumev2'])
 
         service_types = catalog.get_service_types(region='ORD')
         self.assertEqual(service_types, ['rax:object-cdn'])
@@ -625,8 +626,8 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
                                           auth_version='2.0')
 
         service_names = catalog.get_service_names()
-        self.assertEqual(service_names, ['cloudFiles', 'cloudFilesCDN',
-                                         'cloudServers',
+        self.assertEqual(service_names, ['cinder', 'cloudFiles',
+                                         'cloudFilesCDN', 'cloudServers',
                                          'cloudServersOpenStack',
                                          'cloudServersPreprod',
                                          'glance',

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
index 79c6776..d2bd3c3 100644
--- a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
+++ b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
@@ -123,6 +123,28 @@
             {
                 "endpoints": [
                     {
+                        "region": "RegionOne",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    },
+                    {
+                        "region": "fr1",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "cinder",
+                "type": "volumev2"
+            },
+            {
+                "endpoints": [
+                    {
                         "region": "DFW",
                         "tenantId": "613469",
                         "publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/1337",

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2d9e8623/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index faf8fe4..9dc39ee 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1576,6 +1576,11 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         # normally authentication happens lazily, but we force it here
         self.driver.network_connection._populate_hosts_and_request_paths()
 
+        self.driver_klass.volumev2_connectionCls.conn_class = OpenStack_2_0_MockHttp
+        self.driver_klass.volumev2_connectionCls.auth_url = "https://auth.api.example.com"
+        # normally authentication happens lazily, but we force it here
+        self.driver.volumev2_connection._populate_hosts_and_request_paths()
+
     def test_ex_force_auth_token_passed_to_connection(self):
         base_url = 'https://servers.api.rackspacecloud.com/v1.1/slug'
         kwargs = {
@@ -1861,6 +1866,43 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
             'created_at': '2013-06-21T12:39:02.000000',
         })
 
+    def test_create_volume_passes_location_to_request_only_if_not_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test', location='mylocation')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertEqual(kwargs["data"]["volume"]["availability_zone"], "mylocation")
+
+    def test_create_volume_does_not_pass_location_to_request_if_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertFalse("availability_zone" in kwargs["data"]["volume"])
+
+    def test_create_volume_passes_volume_type_to_request_only_if_not_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test', ex_volume_type='myvolumetype')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertEqual(kwargs["data"]["volume"]["volume_type"], "myvolumetype")
+
+    def test_create_volume_does_not_pass_volume_type_to_request_if_none(self):
+        with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+            self.driver.create_volume(1, 'test')
+            name, args, kwargs = mock_request.mock_calls[0]
+            self.assertFalse("volume_type" in kwargs["data"]["volume"])
+
+    def test_ex_create_snapshot_does_not_post_optional_parameters_if_none(self):
+        volume = self.driver.list_volumes()[0]
+        with patch.object(self.driver, '_to_snapshot'):
+            with patch.object(self.driver.volumev2_connection, 'request') as mock_request:
+                self.driver.create_volume_snapshot(volume,
+                                                   name=None,
+                                                   ex_description=None,
+                                                   ex_force=True)
+
+        name, args, kwargs = mock_request.mock_calls[0]
+        self.assertFalse("display_name" in kwargs["data"]["snapshot"])
+        self.assertFalse("display_description" in kwargs["data"]["snapshot"])
+
 
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False


[12/23] libcloud git commit: Fix _to_port to make it work with old versions

Posted by vd...@apache.org.
Fix _to_port to make it work with old versions


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

Branch: refs/heads/trunk
Commit: d34b3f0734befd1dfd8b7c044af5cf911bcd69b9
Parents: 84aa986
Author: micafer <mi...@upv.es>
Authored: Tue Sep 25 16:24:14 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/d34b3f07/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index fb92dab..ebcefc2 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2692,11 +2692,12 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
                 mac_address=element['mac_address'],
                 name=element['name'],
                 network_id=element['network_id'],
-                project_id=element['project_id'],
-                port_security_enabled=element['port_security_enabled'],
-                revision_number=element['revision_number'],
+                project_id=element.get('project_id', None),
+                port_security_enabled=element.get('port_security_enabled',
+                                                  None),
+                revision_number=element.get('revision_number', None),
                 security_groups=element['security_groups'],
-                tags=element['tags'],
+                tags=element.get('tags', None),
                 tenant_id=element['tenant_id'],
                 updated=updated,
             )
@@ -3402,8 +3403,9 @@ class OpenStack_2_FloatingIpPool(OpenStack_1_1_FloatingIpPool):
     def _to_floating_ip(self, obj):
         instance_id = None
 
+        print(obj)
         # In neutron version prior to 13.0.0 port_details does not exists
-        if 'port_details' not in obj and 'port_id' in obj:
+        if 'port_details' not in obj and 'port_id' in obj and obj['port_id']:
             port = self.connection.driver.ex_get_port(obj['port_id'])
             if port:
                 obj['port_details'] = {"device_id": port.extra["device_id"],


[21/23] libcloud git commit: Solve PR issues

Posted by vd...@apache.org.
Solve PR issues


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

Branch: refs/heads/trunk
Commit: 9c0da3dd4655ee7c58fee2c709670bec518c6354
Parents: a2faa55
Author: micafer <mi...@upv.es>
Authored: Tue Oct 23 13:05:07 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/9c0da3dd/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index b5914ff..868ae09 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2220,27 +2220,26 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         return StorageVolume(
             id=api_node['id'],
-            name=api_node.get('name', api_node.get('displayName', None)),
+            name=api_node.get('name', api_node.get('displayName')),
             size=api_node['size'],
             state=state,
             driver=self,
             extra={
                 'description': api_node.get('description',
-                                            api_node.get('displayDescription',
-                                                         None)),
+                                            api_node.get('displayDescription')
+                                            ),
                 'attachments': [att for att in api_node['attachments'] if att],
                 # TODO: remove in 1.18.0
                 'state': api_node.get('status', None),
                 'snapshot_id': api_node.get('snapshot_id',
-                                            api_node.get('snapshotId', None)),
+                                            api_node.get('snapshotId')),
                 'location': api_node.get('availability_zone',
-                                         api_node.get('availabilityZone',
-                                                      None)),
+                                         api_node.get('availabilityZone')),
                 'volume_type': api_node.get('volume_type',
-                                            api_node.get('volumeType', None)),
+                                            api_node.get('volumeType')),
                 'metadata': api_node.get('metadata', None),
                 'created_at': api_node.get('created_at',
-                                           api_node.get('createdAt', None))
+                                           api_node.get('createdAt'))
             }
         )
 
@@ -3166,6 +3165,14 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
                                              data=data).object)
 
     def destroy_volume_snapshot(self, snapshot):
+        """
+        Delete a Volume Snapshot.
+
+        :param snapshot: Snapshot to be deleted
+        :type  snapshot: :class:`VolumeSnapshot`
+
+        :rtype: ``bool``
+        """
         resp = self.volumev2_connection.request('/snapshots/%s' % snapshot.id,
                                                 method='DELETE')
         return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
@@ -3423,7 +3430,7 @@ class OpenStack_1_1_FloatingIpAddress(object):
                 % (self.id, self.ip_address, self.pool, self.driver))
 
 
-class OpenStack_2_FloatingIpPool(OpenStack_1_1_FloatingIpPool):
+class OpenStack_2_FloatingIpPool(object):
     """
     Floating IP Pool info.
     """


[20/23] libcloud git commit: Complete docstring

Posted by vd...@apache.org.
Complete docstring


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

Branch: refs/heads/trunk
Commit: e5a69865a0f00d545158a2e593e6c034ea153337
Parents: 33728b2
Author: micafer <mi...@upv.es>
Authored: Wed Nov 28 16:03:39 2018 +0100
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/e5a69865/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index f244f91..3aebda3 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -3064,10 +3064,23 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         return self._to_port(response.object['port'])
 
     def list_volumes(self):
+        """
+        Get a list of Volumes that are available.
+
+        :rtype: ``list`` of :class:`StorageVolume`
+        """
         return self._to_volumes(
             self.volumev2_connection.request('/volumes/detail').object)
 
     def ex_get_volume(self, volumeId):
+        """
+        Retrieve the StorageVolume with the given ID
+
+        :param volumeId: ID of the volume
+        :type volumeId: ``string``
+
+        :return: :class:`StorageVolume`
+        """
         return self._to_volume(
             self.volumev2_connection.request('/volumes/%s' % volumeId).object)
 
@@ -3122,10 +3135,23 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         return self._to_volume(resp.object)
 
     def destroy_volume(self, volume):
+        """
+        Delete a Volume.
+
+        :param volume: Volume to be deleted
+        :type  volume: :class:`StorageVolume`
+
+        :rtype: ``bool``
+        """
         return self.volumev2_connection.request('/volumes/%s' % volume.id,
                                                 method='DELETE').success()
 
     def ex_list_snapshots(self):
+        """
+        Get a list of Snapshot that are available.
+
+        :rtype: ``list`` of :class:`VolumeSnapshot`
+        """
         return self._to_snapshots(
             self.volumev2_connection.request('/snapshots/detail').object)
 


[15/23] libcloud git commit: add direction in security_group_rule creation

Posted by vd...@apache.org.
add direction in security_group_rule creation

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

Branch: refs/heads/trunk
Commit: 33e694f37876693ec2bcb772684900f1ef3d38a1
Parents: 830a0f8
Author: Miguel Caballer <mi...@upv.es>
Authored: Fri Sep 28 08:44:55 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/33e694f3/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 7e78d42..0de0ab3 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -3240,6 +3240,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         return self._to_security_group_rule(self.network_connection.request(
             '/v2.0/security-group-rules', method='POST',
             data={'security_group_rule': {
+                'direction': 'ingress',
                 'protocol': ip_protocol,
                 'port_range_min': from_port,
                 'port_range_max': to_port,


[16/23] libcloud git commit: Add create and delete subnets

Posted by vd...@apache.org.
Add create and delete subnets


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

Branch: refs/heads/trunk
Commit: ca5430d689e621e6f1fb6d4231352471b9a7a91e
Parents: 33e694f
Author: micafer <mi...@upv.es>
Authored: Tue Oct 23 12:19:50 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 40 +++++++++++++++++++-
 .../fixtures/openstack_v1.1/_v2_0__subnet.json  | 32 ++++++++++++++++
 libcloud/test/compute/test_openstack.py         | 27 ++++++++++++-
 3 files changed, 96 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/ca5430d6/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 0de0ab3..ec71091 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1681,7 +1681,7 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
     def ex_delete_network(self, network):
         """
-        Get a list of NodeNetorks that are available.
+        Delete a Network
 
         :param network: Network which should be used
         :type network: :class:`OpenStackNetwork`
@@ -2914,6 +2914,44 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
             self._subnets_url_prefix).object
         return self._to_subnets(response)
 
+    def ex_create_subnet(self, name, network, cidr, ip_version=4):
+        """
+        Create a new Subnet
+
+        :param name: Name of subnet which should be used
+        :type name: ``str``
+
+        :param network: Parent network of the subnet
+        :type network: ``OpenStackNetwork``
+
+        :param cidr: cidr of network which should be used
+        :type cidr: ``str``
+
+        :param ip_version: ip_version of subnet which should be used
+        :type ip_version: ``int``
+
+        :rtype: :class:`OpenStack_2_SubNet`
+        """
+        data = {'subnet': {'cidr': cidr, 'network_id': network.id,
+                           'ip_version': ip_version, 'name': name}}
+        response = self.connection.request(self._subnets_url_prefix,
+                                           method='POST', data=data).object
+        return self._to_subnet(response['subnet'])
+
+    def ex_delete_subnet(self, subnet):
+        """
+        Delete a Subnet
+
+        :param subnet: Subnet which should be deleted
+        :type subnet: :class:`OpenStack_2_SubNet`
+
+        :rtype: ``bool``
+        """
+        resp = self.connection.request('%s/%s' % (self._subnets_url_prefix,
+                                                  subnet.id),
+                                       method='DELETE')
+        return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
+
     def ex_list_ports(self):
         """
         List all OpenStack_2_PortInterfaces

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ca5430d6/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnet.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnet.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnet.json
new file mode 100644
index 0000000..dba344a
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__subnet.json
@@ -0,0 +1,32 @@
+{
+    "subnet":
+        {
+            "name": "name",
+            "enable_dhcp": true,
+            "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
+            "segment_id": null,
+            "project_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
+            "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
+            "dns_nameservers": [],
+            "allocation_pools": [
+                {
+                    "start": "10.0.0.2",
+                    "end": "10.0.0.254"
+                }
+            ],
+            "host_routes": [],
+            "ip_version": 4,
+            "gateway_ip": "10.0.0.1",
+            "cidr": "10.0.0.0/24",
+            "id": "08eae331-0402-425a-923c-34f7cfe39c1b",
+            "created_at": "2016-10-10T14:35:34Z",
+            "description": "",
+            "ipv6_address_mode": null,
+            "ipv6_ra_mode": null,
+            "revision_number": 2,
+            "service_types": [],
+            "subnetpool_id": null,
+            "tags": ["tag1,tag2"],
+            "updated_at": "2016-10-10T14:35:34Z"
+        }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/ca5430d6/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index db7b357..e567f17 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1758,6 +1758,17 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         self.assertEqual(subnet.name, 'private-subnet')
         self.assertEqual(subnet.cidr, '10.0.0.0/24')
 
+    def test_ex_create_subnet(self):
+        network = self.driver.ex_list_networks()[0]
+        subnet = self.driver.ex_create_subnet('name', network, '10.0.0.0/24')
+
+        self.assertEqual(subnet.name, 'name')
+        self.assertEqual(subnet.cidr, '10.0.0.0/24')
+
+    def test_ex_delete_subnet(self):
+        subnet = self.driver.ex_list_subnets()[0]
+        self.assertTrue(self.driver.ex_delete_subnet(subnet=subnet))
+
     def test_ex_list_network(self):
         networks = self.driver.ex_list_networks()
         network = networks[0]
@@ -2440,9 +2451,21 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
             body = ''
             return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
 
+    def _v2_1337_v2_0_subnets_08eae331_0402_425a_923c_34f7cfe39c1b(self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__subnet.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'DELETE':
+            body = ''
+            return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
+
     def _v2_1337_v2_0_subnets(self, method, url, body, headers):
-        body = self.fixtures.load('_v2_0__subnets.json')
-        return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'POST':
+            body = self.fixtures.load('_v2_0__subnet.json')
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
+        else:
+            body = self.fixtures.load('_v2_0__subnets.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
     def _v2_1337_volumes_detail(self, method, url, body, headers):
         body = self.fixtures.load('_v2_0__volumes.json')


[09/23] libcloud git commit: Add cinder support LIBCLOUD-874

Posted by vd...@apache.org.
Add cinder support LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: c8d253f7c8e566aa29589b78236264946a3cade3
Parents: 2d9e862
Author: micafer <mi...@upv.es>
Authored: Mon Sep 24 16:20:20 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c8d253f7/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 9bd80cc..4fcdda6 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -3067,13 +3067,13 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
             volume['snapshot_id'] = snapshot.id
 
         resp = self.volumev2_connection.request('/volumes',
-                                       method='POST',
-                                       data={'volume': volume})
+                                                method='POST',
+                                                data={'volume': volume})
         return self._to_volume(resp.object)
 
     def destroy_volume(self, volume):
         return self.volumev2_connection.request('/volumes/%s' % volume.id,
-                                       method='DELETE').success()
+                                                method='DELETE').success()
 
     def ex_list_snapshots(self):
         return self._to_snapshots(
@@ -3108,13 +3108,13 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         if ex_description is not None:
             data['snapshot']['description'] = ex_description
 
-        return self._to_snapshot(self.volumev2_connection.request('/snapshots',
-                                                         method='POST',
-                                                         data=data).object)
+        return self._to_snapshot(
+            self.volumev2_connection.request('/snapshots', method='POST',
+                                             data=data).object)
 
     def destroy_volume_snapshot(self, snapshot):
         resp = self.volumev2_connection.request('/snapshots/%s' % snapshot.id,
-                                       method='DELETE')
+                                                method='DELETE')
         return resp.status == httplib.ACCEPTED
 
 


[05/23] libcloud git commit: Add cinder support LIBCLOUD-874

Posted by vd...@apache.org.
Add cinder support LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: e9dcb93e4f8591e0980399563e53424215c6fd86
Parents: cd2faa7
Author: micafer <mi...@upv.es>
Authored: Mon Sep 24 12:54:47 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 167 +++++++++++++++++--
 .../openstack_v1.1/_v2_0__snapshot.json         |  14 ++
 .../openstack_v1.1/_v2_0__snapshots.json        |  46 +++++
 .../fixtures/openstack_v1.1/_v2_0__volume.json  |  18 ++
 .../fixtures/openstack_v1.1/_v2_0__volumes.json |  44 +++++
 libcloud/test/compute/test_openstack.py         |  78 +++++++++
 6 files changed, 357 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/e9dcb93e/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 75106f1..bfdf082 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -89,6 +89,12 @@ class OpenStackNetworkConnection(OpenStackBaseConnection):
     service_region = 'RegionOne'
 
 
+class OpenStackVolumeConnection(OpenStackBaseConnection):
+    service_type = 'volume'
+    service_name = 'cinder'
+    service_region = 'RegionOne'
+
+
 class OpenStackNodeDriver(NodeDriver, OpenStackDriverMixin):
     """
     Base OpenStack node driver. Should not be used directly.
@@ -2200,20 +2206,27 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         return StorageVolume(
             id=api_node['id'],
-            name=api_node['displayName'],
+            name=api_node.get('name', api_node.get('displayName', None)),
             size=api_node['size'],
             state=state,
             driver=self,
             extra={
-                'description': api_node['displayDescription'],
+                'description': api_node.get('description',
+                                            api_node.get('displayDescription',
+                                                         None)),
                 'attachments': [att for att in api_node['attachments'] if att],
                 # TODO: remove in 1.18.0
                 'state': api_node.get('status', None),
-                'snapshot_id': api_node.get('snapshotId', None),
-                'location': api_node.get('availabilityZone', None),
-                'volume_type': api_node.get('volumeType', None),
+                'snapshot_id': api_node.get('snapshot_id',
+                                            api_node.get('snapshotId', None)),
+                'location': api_node.get('availability_zone',
+                                         api_node.get('availabilityZone',
+                                                      None)),
+                'volume_type': api_node.get('volume_type',
+                                            api_node.get('volumeType', None)),
                 'metadata': api_node.get('metadata', None),
-                'created_at': api_node.get('createdAt', None)
+                'created_at': api_node.get('created_at',
+                                           api_node.get('createdAt', None))
             }
         )
 
@@ -2222,10 +2235,13 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
             data = data['snapshot']
 
         volume_id = data.get('volume_id', data.get('volumeId', None))
-        display_name = data.get('display_name', data.get('displayName', None))
+        display_name = data.get('name',
+                                data.get('display_name',
+                                         data.get('displayName', None)))
         created_at = data.get('created_at', data.get('createdAt', None))
-        description = data.get('display_description',
-                               data.get('displayDescription', None))
+        description = data.get('description',
+                               data.get('display_description',
+                                        data.get('displayDescription', None)))
         status = data.get('status', None)
 
         extra = {'volume_id': volume_id,
@@ -2514,6 +2530,15 @@ class OpenStack_2_NetworkConnection(OpenStackNetworkConnection):
         return json.dumps(data)
 
 
+class OpenStack_2_VolumeConnection(OpenStackVolumeConnection):
+    responseCls = OpenStack_1_1_Response
+    accept_format = 'application/json'
+    default_content_type = 'application/json; charset=UTF-8'
+
+    def encode_data(self, data):
+        return json.dumps(data)
+
+
 class OpenStack_2_PortInterfaceState(Type):
     """
     Standard states of OpenStack_2_PortInterfaceState
@@ -2562,6 +2587,14 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
     # accessed from there.
     network_connectionCls = OpenStack_2_NetworkConnection
     network_connection = None
+
+    # Similarly not all node-related operations are exposed through the
+    # compute API
+    # See https://developer.openstack.org/api-ref/compute/
+    # For example, volume management are made in the cinder service
+    volume_connectionCls = OpenStack_2_VolumeConnection
+    volume_connection = None
+
     type = Provider.OPENSTACK
 
     features = {"create_node": ["generates_password"]}
@@ -2594,8 +2627,18 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
         self.image_connection = self.connection
 
+        # We run the init once to get the Cinder V2 API connection
+        # and put that on the object under self.volume_connection.
+        if original_ex_force_base_url or kwargs.get('ex_force_volume_url'):
+            kwargs['ex_force_base_url'] = \
+                str(kwargs.pop('ex_force_volume_url',
+                               original_ex_force_base_url))
+        self.connectionCls = self.volume_connectionCls
+        super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
+        self.volume_connection = self.connection
+
         # We run the init once to get the Neutron V2 API connection
-        # and put that on the object under self.image_connection.
+        # and put that on the object under self.network_connection.
         if original_ex_force_base_url or kwargs.get('ex_force_network_url'):
             kwargs['ex_force_base_url'] = \
                 str(kwargs.pop('ex_force_network_url',
@@ -2970,6 +3013,110 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         )
         return self._to_port(response.object['port'])
 
+    def list_volumes(self):
+        return self._to_volumes(
+            self.connection.request('/volumes/detail').object)
+
+    def ex_get_volume(self, volumeId):
+        return self._to_volume(
+            self.connection.request('/volumes/%s' % volumeId).object)
+
+    def create_volume(self, size, name, location=None, snapshot=None,
+                      ex_volume_type=None):
+        """
+        Create a new volume.
+
+        :param size: Size of volume in gigabytes (required)
+        :type size: ``int``
+
+        :param name: Name of the volume to be created
+        :type name: ``str``
+
+        :param location: Which data center to create a volume in. If
+                               empty, undefined behavior will be selected.
+                               (optional)
+        :type location: :class:`.NodeLocation`
+
+        :param snapshot:  Snapshot from which to create the new
+                          volume.  (optional)
+        :type snapshot:  :class:`.VolumeSnapshot`
+
+        :param ex_volume_type: What kind of volume to create.
+                            (optional)
+        :type ex_volume_type: ``str``
+
+        :return: The newly created volume.
+        :rtype: :class:`StorageVolume`
+        """
+        volume = {
+            'name': name,
+            'description': name,
+            'size': size,
+            'metadata': {
+                'contents': name,
+            },
+        }
+
+        if ex_volume_type:
+            volume['volume_type'] = ex_volume_type
+
+        if location:
+            volume['availability_zone'] = location
+
+        if snapshot:
+            volume['snapshot_id'] = snapshot.id
+
+        resp = self.connection.request('/volumes',
+                                       method='POST',
+                                       data={'volume': volume})
+        return self._to_volume(resp.object)
+
+    def destroy_volume(self, volume):
+        return self.connection.request('/volumes/%s' % volume.id,
+                                       method='DELETE').success()
+
+    def ex_list_snapshots(self):
+        return self._to_snapshots(
+            self.connection.request('/snapshots/detail').object)
+
+    def create_volume_snapshot(self, volume, name=None, ex_description=None,
+                               ex_force=True):
+        """
+        Create snapshot from volume
+
+        :param volume: Instance of `StorageVolume`
+        :type  volume: `StorageVolume`
+
+        :param name: Name of snapshot (optional)
+        :type  name: `str` | `NoneType`
+
+        :param ex_description: Description of the snapshot (optional)
+        :type  ex_description: `str` | `NoneType`
+
+        :param ex_force: Specifies if we create a snapshot that is not in
+                         state `available`. For example `in-use`. Defaults
+                         to True. (optional)
+        :type  ex_force: `bool`
+
+        :rtype: :class:`VolumeSnapshot`
+        """
+        data = {'snapshot': {'volume_id': volume.id, 'force': ex_force}}
+
+        if name is not None:
+            data['snapshot']['name'] = name
+
+        if ex_description is not None:
+            data['snapshot']['description'] = ex_description
+
+        return self._to_snapshot(self.connection.request('/snapshots',
+                                                         method='POST',
+                                                         data=data).object)
+
+    def destroy_volume_snapshot(self, snapshot):
+        resp = self.connection.request('/snapshots/%s' % snapshot.id,
+                                       method='DELETE')
+        return resp.status == httplib.ACCEPTED
+
 
 class OpenStack_1_1_FloatingIpPool(object):
     """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e9dcb93e/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshot.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshot.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshot.json
new file mode 100644
index 0000000..3b4e846
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshot.json
@@ -0,0 +1,14 @@
+{
+    "snapshot": {
+        "status": "available",
+        "os-extended-snapshot-attributes:progress": "100%",
+        "description": "Daily backup",
+        "created_at": "2013-02-25T04:13:17.07Z",
+        "metadata": {},
+        "volume_id": "5aa119a8-d25b-45a7-8d1b-88e127885635",
+        "os-extended-snapshot-attributes:project_id": "0c2eba2c5af04d3f9e9d0d410b371fde",
+        "size": 1,
+        "id": "3fbbcccf-d058-4502-8844-6feeffdf4cb5",
+        "name": "test"
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e9dcb93e/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshots.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshots.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshots.json
new file mode 100644
index 0000000..763831c
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__snapshots.json
@@ -0,0 +1,46 @@
+{
+    "snapshots": [
+        {
+            "status": "available",
+            "metadata": {
+                "name": "test"
+            },
+            "os-extended-snapshot-attributes:progress": "100%",
+            "name": "snap-001",
+            "volume_id": "373f7b48-c4c1-4e70-9acc-086b39073506",
+            "os-extended-snapshot-attributes:project_id": "bab7d5c60cd041a0a36f7c4b6e1dd978",
+            "created_at": "2012-02-29T03:50:07Z",
+            "size": 1,
+            "id": "3fbbcccf-d058-4502-8844-6feeffdf4cb5",
+            "description": "volume snapshot"
+        },
+        {
+            "status": "available",
+            "metadata": {
+                "name": "test"
+            },
+            "os-extended-snapshot-attributes:progress": "100%",
+            "name": "test-volume-snapshot",
+            "volume_id": "6edbc2f4-1507-44f8-ac0d-eed1d2608d38",
+            "os-extended-snapshot-attributes:project_id": "bab7d5c60cd041a0a36f7c4b6e1dd978",
+            "created_at": "2015-11-29T02:25:51.000000",
+            "size": 1,
+            "id": "4fbbdccf-e058-6502-8844-6feeffdf4cb5",
+            "description": "volume snapshot"
+        },
+        {
+            "status": "available",
+            "metadata": {
+                "name": "test"
+            },
+            "os-extended-snapshot-attributes:progress": "100%",
+            "name": "test-volume-snapshot",
+            "volume_id": "373f7b48-c4c1-4e70-9acc-086b39073506",
+            "os-extended-snapshot-attributes:project_id": "bab7d5c60cd041a0a36f7c4b6e1dd978",
+            "created_at": "2013-02-29T03:50:07Z",
+            "size": 1,
+            "id": "1fbbcccf-d058-4502-8844-6feeffdf4cb5",
+            "description": "volume snapshot"
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e9dcb93e/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volume.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volume.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volume.json
new file mode 100644
index 0000000..46587e6
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volume.json
@@ -0,0 +1,18 @@
+{
+    "volume": {
+        "status": "available",
+        "attachments": [],
+        "availability_zone": "nova",
+        "bootable": "false",
+        "os-vol-host-attr:host": "ip-10-168-107-25",
+        "source_volid": null,
+        "snapshot_id": null,
+        "id": "cd76a3a1-c4ce-40f6-9b9f-07a61508938d",
+        "description": "Super volume.",
+        "name": "test",
+        "created_at": "2013-02-25T02:40:21.000000",
+        "volume_type": "None",
+        "size": 1,
+        "metadata": {}
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e9dcb93e/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volumes.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volumes.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volumes.json
new file mode 100644
index 0000000..8415a18
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__volumes.json
@@ -0,0 +1,44 @@
+{
+    "volumes": [
+        {
+            "status": "in-use",
+            "attachments": [
+                {
+                    "server_id": "f4fda93b-06e0-4743-8117-bc8bcecd651b",
+                    "attachment_id": "3b4db356-253d-4fab-bfa0-e3626c0b8405",
+                    "volume_id": "6edbc2f4-1507-44f8-ac0d-eed1d2608d38",
+                    "device": "/dev/vdb",
+                    "id": "6edbc2f4-1507-44f8-ac0d-eed1d2608d38"
+                }
+            ],
+            "availability_zone": "nova",
+            "replication_status": "disabled",
+            "snapshot_id": null,
+            "id": "6edbc2f4-1507-44f8-ac0d-eed1d2608d38",
+            "size": 2,
+            "user_id": "32779452fcd34ae1a53a797ac8a1e064",
+            "metadata": {},
+            "description": "",
+            "name": "test-volume-attachments",
+            "created_at": "2013-06-24T11:20:13.000000",
+            "volume_type": "lvmdriver-1"
+        },
+        {
+            "status": "some-unknown-state",
+            "migration_status": null,
+            "attachments": [],
+            "availability_zone": "nova",
+            "replication_status": "disabled",
+            "snapshot_id": "01f48111-7866-4cd2-986a-e92683c4a363",
+            "id": "cfcec3bc-b736-4db5-9535-4c24112691b5",
+            "size": 50,
+            "user_id": "32779452fcd34ae1a53a797ac8a1e064",
+            "metadata": {},
+            "description": "some description",
+            "name": "test_volume",
+            "bootable": "false",
+            "created_at": "2013-06-21T12:39:02.000000",
+            "volume_type": null
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/e9dcb93e/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 78c13e0..faf8fe4 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1818,6 +1818,49 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
 
         self.assertTrue(ret)
 
+    def test_list_volumes(self):
+        volumes = self.driver.list_volumes()
+        self.assertEqual(len(volumes), 2)
+        volume = volumes[0]
+
+        self.assertEqual('6edbc2f4-1507-44f8-ac0d-eed1d2608d38', volume.id)
+        self.assertEqual('test-volume-attachments', volume.name)
+        self.assertEqual(StorageVolumeState.INUSE, volume.state)
+        self.assertEqual(2, volume.size)
+        self.assertEqual(volume.extra, {
+            'description': '',
+            'attachments': [{
+                "attachment_id": "3b4db356-253d-4fab-bfa0-e3626c0b8405",
+                "id": '6edbc2f4-1507-44f8-ac0d-eed1d2608d38',
+                "device": "/dev/vdb",
+                "server_id": "f4fda93b-06e0-4743-8117-bc8bcecd651b",
+                "volume_id": "6edbc2f4-1507-44f8-ac0d-eed1d2608d38",
+            }],
+            'snapshot_id': None,
+            'state': 'in-use',
+            'location': 'nova',
+            'volume_type': 'lvmdriver-1',
+            'metadata': {},
+            'created_at': '2013-06-24T11:20:13.000000'
+        })
+
+        # also test that unknown state resolves to StorageVolumeState.UNKNOWN
+        volume = volumes[1]
+        self.assertEqual('cfcec3bc-b736-4db5-9535-4c24112691b5', volume.id)
+        self.assertEqual('test_volume', volume.name)
+        self.assertEqual(50, volume.size)
+        self.assertEqual(StorageVolumeState.UNKNOWN, volume.state)
+        self.assertEqual(volume.extra, {
+            'description': 'some description',
+            'attachments': [],
+            'snapshot_id': '01f48111-7866-4cd2-986a-e92683c4a363',
+            'state': 'some-unknown-state',
+            'location': 'nova',
+            'volume_type': None,
+            'metadata': {},
+            'created_at': '2013-06-21T12:39:02.000000',
+        })
+
 
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False
@@ -2308,6 +2351,41 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
         body = self.fixtures.load('_v2_0__subnets.json')
         return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
 
+    def _v2_1337_volumes_detail(self, method, url, body, headers):
+        body = self.fixtures.load('_v2_0__volumes.json')
+        return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_volumes(self, method, url, body, headers):
+        if method == 'POST':
+            body = self.fixtures.load('_v2_0__volume.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_volumes_cd76a3a1_c4ce_40f6_9b9f_07a61508938d(self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__volume.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'DELETE':
+            body = ''
+            return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
+    
+    def _v2_1337_snapshots_detail(self, method, url, body, headers):
+        body = self.fixtures.load('_v2_0__snapshots.json')
+        return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_snapshots(self, method, url, body, headers):
+        if method == 'POST':
+            body = self.fixtures.load('_v2_0__snapshot.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+
+    def _v2_1337_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5(self, method, url, body, headers):
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__snapshot.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'DELETE':
+            body = ''
+            return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
+    
+
 # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures
 # work fine.
 


[06/23] libcloud git commit: Add cinder support LIBCLOUD-874

Posted by vd...@apache.org.
Add cinder support LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: c4b5cfa6a25e8f9fe373650b60e770c2b9b51235
Parents: e9dcb93
Author: micafer <mi...@upv.es>
Authored: Mon Sep 24 13:03:38 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c4b5cfa6/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index bfdf082..fba9a8a 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -89,8 +89,8 @@ class OpenStackNetworkConnection(OpenStackBaseConnection):
     service_region = 'RegionOne'
 
 
-class OpenStackVolumeConnection(OpenStackBaseConnection):
-    service_type = 'volume'
+class OpenStackVolumeV2Connection(OpenStackBaseConnection):
+    service_type = 'volumev2'
     service_name = 'cinder'
     service_region = 'RegionOne'
 
@@ -2530,7 +2530,7 @@ class OpenStack_2_NetworkConnection(OpenStackNetworkConnection):
         return json.dumps(data)
 
 
-class OpenStack_2_VolumeConnection(OpenStackVolumeConnection):
+class OpenStack_2_VolumeV2Connection(OpenStackVolumeV2Connection):
     responseCls = OpenStack_1_1_Response
     accept_format = 'application/json'
     default_content_type = 'application/json; charset=UTF-8'
@@ -2592,8 +2592,8 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
     # compute API
     # See https://developer.openstack.org/api-ref/compute/
     # For example, volume management are made in the cinder service
-    volume_connectionCls = OpenStack_2_VolumeConnection
-    volume_connection = None
+    volumev2_connectionCls = OpenStack_2_VolumeV2Connection
+    volumev2_connection = None
 
     type = Provider.OPENSTACK
 
@@ -2628,14 +2628,14 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         self.image_connection = self.connection
 
         # We run the init once to get the Cinder V2 API connection
-        # and put that on the object under self.volume_connection.
+        # and put that on the object under self.volumev2_connection.
         if original_ex_force_base_url or kwargs.get('ex_force_volume_url'):
             kwargs['ex_force_base_url'] = \
                 str(kwargs.pop('ex_force_volume_url',
                                original_ex_force_base_url))
-        self.connectionCls = self.volume_connectionCls
+        self.connectionCls = self.volumev2_connectionCls
         super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
-        self.volume_connection = self.connection
+        self.volumev2_connection = self.connection
 
         # We run the init once to get the Neutron V2 API connection
         # and put that on the object under self.network_connection.


[04/23] libcloud git commit: Move floatingips to neutron api LIBCLOUD-874

Posted by vd...@apache.org.
Move floatingips to neutron api LIBCLOUD-874


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

Branch: refs/heads/trunk
Commit: 84aa986ff8c21db2e547b22c117cbff3795204dd
Parents: 2b2e1f1
Author: micafer <mi...@upv.es>
Authored: Tue Sep 25 15:35:28 2018 +0200
Committer: Rick van de Loo <ri...@gmail.com>
Committed: Tue Dec 4 09:45:48 2018 +0100

----------------------------------------------------------------------
 libcloud/common/openstack.py                    |   5 +-
 libcloud/compute/drivers/openstack.py           | 122 ++++++++++++++++++-
 .../openstack_v1.1/_v2_0__floatingip.json       |  23 ++++
 .../openstack_v1.1/_v2_0__floatingips.json      |  52 ++++++++
 .../openstack_v1.1/_v2_0__networks_public.json  |  64 ++++++++++
 libcloud/test/compute/test_openstack.py         |  70 ++++++++++-
 6 files changed, 329 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/84aa986f/libcloud/common/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack.py b/libcloud/common/openstack.py
index b64f669..db9f43f 100644
--- a/libcloud/common/openstack.py
+++ b/libcloud/common/openstack.py
@@ -390,8 +390,9 @@ class OpenStackResponse(Response):
             context = self.connection.context
             driver = self.connection.driver
             key_pair_name = context.get('key_pair_name', None)
-
-            if len(values) > 0 and values[0]['code'] == 404 and key_pair_name:
+            print(values)
+            if len(values) > 0 and 'code' in values[0] and \
+                    values[0]['code'] == 404 and key_pair_name:
                 raise KeyPairDoesNotExistError(name=key_pair_name,
                                                driver=driver)
             elif len(values) > 0 and 'message' in values[0]:

http://git-wip-us.apache.org/repos/asf/libcloud/blob/84aa986f/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index de6d445..fb92dab 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -59,6 +59,7 @@ __all__ = [
     'OpenStack_1_1_Connection',
     'OpenStack_1_1_NodeDriver',
     'OpenStack_1_1_FloatingIpPool',
+    'OpenStack_2_FloatingIpPool',
     'OpenStack_1_1_FloatingIpAddress',
     'OpenStack_2_PortInterfaceState',
     'OpenStack_2_PortInterface',
@@ -3255,10 +3256,29 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
 
         :rtype: ``bool``
         """
-        resp = self.connection.request('/v2.0/security-group-rules/%s' %
-                                       (rule.id), method='DELETE')
+        resp = self.network_connection.request(
+            '/v2.0/security-group-rules/%s' % (rule.id), method='DELETE')
         return resp.status == httplib.NO_CONTENT
 
+    def _to_floating_ip_pool(self, obj):
+        return OpenStack_2_FloatingIpPool(obj['id'], obj['name'],
+                                          self.network_connection)
+
+    def _to_floating_ip_pools(self, obj):
+        pool_elements = obj['networks']
+        return [self._to_floating_ip_pool(pool) for pool in pool_elements]
+
+    def ex_list_floating_ip_pools(self):
+        """
+        List available floating IP pools
+
+        :rtype: ``list`` of :class:`OpenStack_1_1_FloatingIpPool`
+        """
+        return self._to_floating_ip_pools(
+            self.network_connection.request('/v2.0/networks?router:external'
+                                            '=True&fields=id&fields='
+                                            'name').object)
+
 
 class OpenStack_1_1_FloatingIpPool(object):
     """
@@ -3365,6 +3385,104 @@ class OpenStack_1_1_FloatingIpAddress(object):
                 % (self.id, self.ip_address, self.pool, self.driver))
 
 
+class OpenStack_2_FloatingIpPool(OpenStack_1_1_FloatingIpPool):
+    """
+    Floating IP Pool info.
+    """
+
+    def __init__(self, id, name, connection):
+        self.id = id
+        self.name = name
+        self.connection = connection
+
+    def _to_floating_ips(self, obj):
+        ip_elements = obj['floatingips']
+        return [self._to_floating_ip(ip) for ip in ip_elements]
+
+    def _to_floating_ip(self, obj):
+        instance_id = None
+
+        # In neutron version prior to 13.0.0 port_details does not exists
+        if 'port_details' not in obj and 'port_id' in obj:
+            port = self.connection.driver.ex_get_port(obj['port_id'])
+            if port:
+                obj['port_details'] = {"device_id": port.extra["device_id"],
+                                       "device_owner":
+                                           port.extra["device_owner"],
+                                       "mac_address":
+                                           port.extra["mac_address"]}
+
+        if 'port_details' in obj and obj['port_details']:
+            if obj['port_details']['device_owner'] == 'compute:nova':
+                instance_id = obj['port_details']['device_id']
+
+        ip_address = obj['floating_ip_address']
+        return OpenStack_1_1_FloatingIpAddress(id=obj['id'],
+                                               ip_address=ip_address,
+                                               pool=self,
+                                               node_id=instance_id,
+                                               driver=self.connection.driver)
+
+    def list_floating_ips(self):
+        """
+        List floating IPs in the pool
+
+        :rtype: ``list`` of :class:`OpenStack_1_1_FloatingIpAddress`
+        """
+        return self._to_floating_ips(
+            self.connection.request('/v2.0/floatingips').object)
+
+    def get_floating_ip(self, ip):
+        """
+        Get specified floating IP from the pool
+
+        :param      ip: floating IP to get
+        :type       ip: ``str``
+
+        :rtype: :class:`OpenStack_1_1_FloatingIpAddress`
+        """
+        floating_ips = self._to_floating_ips(
+            self.connection.request('/v2.0/floatingips?floating_ip_address'
+                                    '=%s' % ip).object)
+        return floating_ips[0]
+
+    def create_floating_ip(self):
+        """
+        Create new floating IP in the pool
+
+        :rtype: :class:`OpenStack_1_1_FloatingIpAddress`
+        """
+        resp = self.connection.request('/v2.0/floatingips',
+                                       method='POST',
+                                       data={'floatingip':
+                                             {'floating_network_id': self.id}}
+                                       )
+        data = resp.object['floatingip']
+        id = data['id']
+        ip_address = data['floating_ip_address']
+        return OpenStack_1_1_FloatingIpAddress(id=id,
+                                               ip_address=ip_address,
+                                               pool=self,
+                                               node_id=None,
+                                               driver=self.connection.driver)
+
+    def delete_floating_ip(self, ip):
+        """
+        Delete specified floating IP from the pool
+
+        :param      ip: floating IP to remove
+        :type       ip: :class:`OpenStack_1_1_FloatingIpAddress`
+
+        :rtype: ``bool``
+        """
+        resp = self.connection.request('/v2.0/floatingips/%s' % ip.id,
+                                       method='DELETE')
+        return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
+
+    def __repr__(self):
+        return ('<OpenStack_2_FloatingIpPool: name=%s>' % self.name)
+
+
 class OpenStack_2_SubNet(object):
     """
     A Virtual SubNet.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/84aa986f/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingip.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingip.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingip.json
new file mode 100644
index 0000000..0ef2ef5
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingip.json
@@ -0,0 +1,23 @@
+{
+    "floatingip": 
+    {
+        "router_id": null,
+        "description": "for test",
+        "dns_domain": "my-domain.org.",
+        "dns_name": "myfip2",
+        "created_at": "2016-12-21T11:55:50Z",
+        "updated_at": "2016-12-21T11:55:53Z",
+        "revision_number": 2,
+        "project_id": "4969c491a3c74ee4af974e6d800c62de",
+        "tenant_id": "4969c491a3c74ee4af974e6d800c62de",
+        "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57",
+        "fixed_ip_address": null,
+        "floating_ip_address": "10.3.1.42",
+        "port_id": null,
+        "id": "09ea1784-2f81-46dc-8c91-244b4df75bde",
+        "status": "DOWN",
+        "port_details": null,
+        "tags": ["tag1,tag2"],
+        "port_forwardings": []
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/84aa986f/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingips.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingips.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingips.json
new file mode 100644
index 0000000..fa71752
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__floatingips.json
@@ -0,0 +1,52 @@
+{
+    "floatingips": [
+        {
+            "router_id": null,
+            "description": "for test",
+            "dns_domain": "my-domain.org.",
+            "dns_name": "myfip2",
+            "created_at": "2016-12-21T11:55:50Z",
+            "updated_at": "2016-12-21T11:55:53Z",
+            "revision_number": 2,
+            "project_id": "4969c491a3c74ee4af974e6d800c62de",
+            "tenant_id": "4969c491a3c74ee4af974e6d800c62de",
+            "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57",
+            "fixed_ip_address": null,
+            "floating_ip_address": "10.3.1.42",
+            "port_id": null,
+            "id": "09ea1784-2f81-46dc-8c91-244b4df75bde",
+            "status": "DOWN",
+            "port_details": null,
+            "tags": ["tag1,tag2"],
+            "port_forwardings": []
+        },
+        {
+            "router_id": "d23abc8d-2991-4a55-ba98-2aaea84cc72f",
+            "description": "for test",
+            "dns_domain": "my-domain.org.",
+            "dns_name": "myfip",
+            "created_at": "2016-12-21T10:55:50Z",
+            "updated_at": "2016-12-21T10:55:53Z",
+            "revision_number": 1,
+            "project_id": "4969c491a3c74ee4af974e6d800c62de",
+            "tenant_id": "4969c491a3c74ee4af974e6d800c62de",
+            "floating_network_id": "376da547-b977-4cfe-9cba-275c80debf57",
+            "fixed_ip_address": "10.0.0.3",
+            "floating_ip_address": "10.3.1.1",
+            "port_id": "ce705c24-c1ef-408a-bda3-7bbd946164ab",
+            "id": "04c5336a-0629-4694-ba30-04b0bdfa88a4",
+            "status": "ACTIVE",
+            "port_details": {
+                "status": "ACTIVE",
+                "name": "",
+                "admin_state_up": true,
+                "network_id": "02dd8479-ef26-4398-a102-d19d0a7b3a1f",
+                "device_owner": "compute:nova",
+                "mac_address": "fa:16:3e:b1:3b:30",
+                "device_id": "fcfc96da-19e2-40fd-8497-f29da1b21143"
+            },
+            "tags": ["tag1,tag2"],
+            "port_forwardings": []
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/84aa986f/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_public.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_public.json b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_public.json
new file mode 100644
index 0000000..4ac5688
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_v2_0__networks_public.json
@@ -0,0 +1,64 @@
+{
+    "networks": [
+        {
+            "admin_state_up": true,
+            "availability_zone_hints": [],
+            "availability_zones": [
+                "nova"
+            ],
+            "created_at": "2016-03-08T20:19:41",
+            "dns_domain": "my-domain.org.",
+            "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+            "ipv4_address_scope": null,
+            "ipv6_address_scope": null,
+            "l2_adjacency": false,
+            "mtu": 1500,
+            "name": "public",
+            "port_security_enabled": true,
+            "project_id": "4fd44f30292945e481c7b8a0c8908869",
+            "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e",
+            "revision_number": 1,
+            "router:external": true,
+            "shared": false,
+            "status": "ACTIVE",
+            "subnets": [
+                "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
+            ],
+            "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
+            "updated_at": "2016-03-08T20:19:41",
+            "vlan_transparent": true,
+            "description": "",
+            "is_default": false
+        },
+        {
+            "admin_state_up": true,
+            "availability_zone_hints": [],
+            "availability_zones": [
+                "nova"
+            ],
+            "created_at": "2016-03-08T20:19:41",
+            "dns_domain": "my-domain.org.",
+            "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+            "ipv4_address_scope": null,
+            "ipv6_address_scope": null,
+            "l2_adjacency": false,
+            "mtu": 1500,
+            "name": "foobar",
+            "port_security_enabled": true,
+            "project_id": "4fd44f30292945e481c7b8a0c8908869",
+            "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e",
+            "revision_number": 1,
+            "router:external": true,
+            "shared": false,
+            "status": "ACTIVE",
+            "subnets": [
+                "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
+            ],
+            "tenant_id": "4fd44f30292945e481c7b8a0c8908869",
+            "updated_at": "2016-03-08T20:19:41",
+            "vlan_transparent": true,
+            "description": "",
+            "is_default": false
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/84aa986f/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 3faea2b..db7b357 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -45,7 +45,7 @@ from libcloud.compute.drivers.openstack import (
     OpenStack_1_1_NodeDriver, OpenStackSecurityGroup,
     OpenStackSecurityGroupRule, OpenStack_1_1_FloatingIpPool,
     OpenStack_1_1_FloatingIpAddress, OpenStackKeyPair,
-    OpenStack_1_0_Connection,
+    OpenStack_1_0_Connection, OpenStack_2_FloatingIpPool,
     OpenStackNodeDriver,
     OpenStack_2_NodeDriver, OpenStack_2_PortInterfaceState, OpenStackNetwork)
 from libcloud.compute.base import Node, NodeImage, NodeSize
@@ -1399,6 +1399,53 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
 
         self.assertEqual(pool.delete_floating_ip.call_count, 1)
 
+    def test_OpenStack_2_FloatingIpPool_list_floating_ips(self):
+        pool = OpenStack_2_FloatingIpPool(1, 'foo', self.driver.connection)
+        ret = pool.list_floating_ips()
+
+        self.assertEqual(ret[0].id, '09ea1784-2f81-46dc-8c91-244b4df75bde')
+        self.assertEqual(ret[0].pool, pool)
+        self.assertEqual(ret[0].ip_address, '10.3.1.42')
+        self.assertEqual(ret[0].node_id, None)
+        self.assertEqual(ret[1].id, '04c5336a-0629-4694-ba30-04b0bdfa88a4')
+        self.assertEqual(ret[1].pool, pool)
+        self.assertEqual(ret[1].ip_address, '10.3.1.1')
+        self.assertEqual(
+            ret[1].node_id, 'fcfc96da-19e2-40fd-8497-f29da1b21143')
+
+    def test_OpenStack_2_FloatingIpPool_get_floating_ip(self):
+        pool = OpenStack_2_FloatingIpPool(1, 'foo', self.driver.connection)
+        ret = pool.get_floating_ip('10.3.1.42')
+
+        self.assertEqual(ret.id, '09ea1784-2f81-46dc-8c91-244b4df75bde')
+        self.assertEqual(ret.pool, pool)
+        self.assertEqual(ret.ip_address, '10.3.1.42')
+        self.assertEqual(ret.node_id, None)
+
+    def test_OpenStack_2_FloatingIpPool_create_floating_ip(self):
+        pool = OpenStack_2_FloatingIpPool(1, 'foo', self.driver.connection)
+        ret = pool.create_floating_ip()
+
+        self.assertEqual(ret.id, '09ea1784-2f81-46dc-8c91-244b4df75bde')
+        self.assertEqual(ret.pool, pool)
+        self.assertEqual(ret.ip_address, '10.3.1.42')
+        self.assertEqual(ret.node_id, None)
+
+    def test_OpenStack_2_FloatingIpPool_delete_floating_ip(self):
+        pool = OpenStack_2_FloatingIpPool(1, 'foo', self.driver.connection)
+        ip = OpenStack_1_1_FloatingIpAddress('foo-bar-id', '42.42.42.42', pool)
+
+        self.assertTrue(pool.delete_floating_ip(ip))
+
+    def test_OpenStack_2_FloatingIpAddress_delete(self):
+        pool = OpenStack_2_FloatingIpPool(1, 'foo', self.driver.connection)
+        pool.delete_floating_ip = Mock()
+        ip = OpenStack_1_1_FloatingIpAddress('foo-bar-id', '42.42.42.42', pool)
+
+        ip.pool.delete_floating_ip()
+
+        self.assertEqual(pool.delete_floating_ip.call_count, 1)
+
     def test_ex_get_metadata_for_node(self):
         image = NodeImage(id=11, name='Ubuntu 8.10 (intrepid)', driver=self.driver)
         size = NodeSize(1, '256 slice', None, None, None, None, driver=self.driver)
@@ -2374,8 +2421,12 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
 
     def _v2_1337_v2_0_networks(self, method, url, body, headers):
         if method == 'GET':
-            body = self.fixtures.load('_v2_0__networks.json')
-            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+            if "router:external=True" in url:
+                body = self.fixtures.load('_v2_0__networks_public.json')
+                return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+            else:
+                body = self.fixtures.load('_v2_0__networks.json')
+                return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
         elif method == 'POST':
             body = self.fixtures.load('_v2_0__networks_POST.json')
             return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK])
@@ -2453,6 +2504,19 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
             body = ''
             return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
 
+    def _v2_1337_v2_0_floatingips(self, method, url, body, headers):
+        if method == 'POST':
+            body = self.fixtures.load('_v2_0__floatingip.json')
+            return (httplib.CREATED, body, self.json_content_headers, httplib.responses[httplib.OK])
+        if method == 'GET':
+            body = self.fixtures.load('_v2_0__floatingips.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+    
+    def _v2_1337_v2_0_floatingips_foo_bar_id(self, method, url, body, headers):
+        if method == 'DELETE':
+            body = ''
+            return (httplib.NO_CONTENT, body, self.json_content_headers, httplib.responses[httplib.OK])
+
 # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures
 # work fine.