You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2017/09/24 14:33:12 UTC

[06/10] libcloud git commit: fix urlencode for Python 3 & retain back compatibility for Node and Volume create

fix urlencode for Python 3 & retain back compatibility for Node and Volume create


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

Branch: refs/heads/trunk
Commit: 5d76cf6dfa015c27d3dfb69620a36f90d7797c8f
Parents: 85de9c1
Author: nurfet-becirevic <nu...@stackpointcloud.com>
Authored: Mon Sep 11 12:49:44 2017 +0200
Committer: nurfet-becirevic <nu...@stackpointcloud.com>
Committed: Mon Sep 11 12:49:44 2017 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/profitbricks.py | 41 ++++++++++++++++++---------
 1 file changed, 28 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5d76cf6d/libcloud/compute/drivers/profitbricks.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/profitbricks.py b/libcloud/compute/drivers/profitbricks.py
index b310f09..9477a09 100644
--- a/libcloud/compute/drivers/profitbricks.py
+++ b/libcloud/compute/drivers/profitbricks.py
@@ -19,13 +19,14 @@ import base64
 import json
 import copy
 import time
-import urllib
 
 from libcloud.utils.py3 import b
+from libcloud.utils.py3 import urlencode
 from libcloud.compute.providers import Provider
 from libcloud.common.base import ConnectionUserAndKey, JsonResponse
 from libcloud.compute.base import Node, NodeDriver, NodeLocation, NodeSize
 from libcloud.compute.base import NodeImage, StorageVolume, VolumeSnapshot
+from libcloud.compute.base import NodeAuthPassword, NodeAuthSSHKey
 from libcloud.compute.base import UuidMixin
 from libcloud.compute.types import NodeState
 from libcloud.common.types import LibcloudError, MalformedResponseError
@@ -695,10 +696,11 @@ class ProfitBricksNodeDriver(NodeDriver):
         :type   ex_disk: ``int``
 
         :param  ex_password: The password for the volume.
-        :type   ex_password: :class:`NodeAuthPassword`
+        :type   ex_password: :class:`NodeAuthPassword` or ``str``
 
         :param  ex_ssh_keys: Optional SSH keys for the volume.
-        :type   ex_ssh_keys: ``list`` of :class:`NodeAuthSSHKey`
+        :type   ex_ssh_keys: ``list`` of :class:`NodeAuthSSHKey` or
+                             ``list`` of ``str``
 
         :param  ex_bus_type: Volume bus type (VIRTIO, IDE).
         :type   ex_bus_type: ``str``
@@ -832,12 +834,18 @@ class ProfitBricksNodeDriver(NodeDriver):
             }
 
             if ex_password is not None:
-                new_volume['properties']['imagePassword'] = \
-                    ex_password.password
+                if isinstance(ex_password, NodeAuthPassword):
+                    new_volume['properties']['imagePassword'] = \
+                        ex_password.password
+                else:
+                    new_volume['properties']['imagePassword'] = ex_password
 
             if ex_ssh_keys is not None:
-                new_volume['properties']['sshKeys'] = \
-                    [ssh_key.pubkey for ssh_key in ex_ssh_keys]
+                if isinstance(ex_ssh_keys[0], NodeAuthSSHKey):
+                    new_volume['properties']['sshKeys'] = \
+                        [ssh_key.pubkey for ssh_key in ex_ssh_keys]
+                else:
+                    new_volume['properties']['sshKeys'] = ex_ssh_keys
 
             body['entities']['volumes']['items'].append(new_volume)
 
@@ -1072,10 +1080,11 @@ class ProfitBricksNodeDriver(NodeDriver):
         :type   ex_bus_type: ``str``
 
         :param  ex_ssh_keys: Optional SSH keys.
-        :type   ex_ssh_keys: ``list`` of :class:`NodeAuthSSHKey`
+        :type   ex_ssh_keys: ``list`` of :class:`NodeAuthSSHKey` or
+                             ``list`` of ``str``
 
         :param  ex_password: Optional password for root.
-        :type   ex_password: :class:`NodeAuthPassword`
+        :type   ex_password: :class:`NodeAuthPassword` or ``str``
 
         :param  ex_availability_zone: Volume Availability Zone.
         :type   ex_availability_zone: ``str``
@@ -1132,10 +1141,16 @@ class ProfitBricksNodeDriver(NodeDriver):
         if ex_bus_type is not None:
             body['properties']['bus'] = ex_bus_type
         if ex_ssh_keys is not None:
-            body['properties']['sshKeys'] = \
-                [ssh_key.pubkey for ssh_key in ex_ssh_keys]
+            if isinstance(ex_ssh_keys[0], NodeAuthSSHKey):
+                body['properties']['sshKeys'] = \
+                    [ssh_key.pubkey for ssh_key in ex_ssh_keys]
+            else:
+                body['properties']['sshKeys'] = ex_ssh_keys
         if ex_password is not None:
-            body['properties']['imagePassword'] = ex_password.password
+            if isinstance(ex_password, NodeAuthPassword):
+                body['properties']['imagePassword'] = ex_password.password
+            else:
+                body['properties']['imagePassword'] = ex_password
         if ex_availability_zone is not None:
             body['properties']['availabilityZone'] = ex_availability_zone
 
@@ -2697,7 +2712,7 @@ class ProfitBricksNodeDriver(NodeDriver):
 
         action = volume.extra['href'] + '/restore-snapshot'
         data = {'snapshotId': snapshot.id}
-        body = urllib.urlencode(data)
+        body = urlencode(data)
 
         self.connection.request(
             action=action,