libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [13/21] libcloud git commit: Vultr ssh key implementation - Added ex_ssh_key_ids to create_node - Implemented list_key_pairs with public key retreival
Date Sun, 14 Jun 2015 10:52:24 GMT
Vultr ssh key implementation - Added ex_ssh_key_ids to create_node - Implemented list_key_pairs
with public key retreival

Signed-off-by: Tomaz Muraus <tomaz@tomaz.me>


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

Branch: refs/heads/trunk
Commit: 33cbf99218f4d884e260ce7fb02f6403dc84efe1
Parents: b70bbbd
Author: jcastillo2nd <j.castillo.2nd@gmail.com>
Authored: Thu May 28 18:57:51 2015 +0000
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Sun Jun 14 18:05:58 2015 +0800

----------------------------------------------------------------------
 libcloud/compute/drivers/vultr.py | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/33cbf992/libcloud/compute/drivers/vultr.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vultr.py b/libcloud/compute/drivers/vultr.py
index ab47aa0..3823119 100644
--- a/libcloud/compute/drivers/vultr.py
+++ b/libcloud/compute/drivers/vultr.py
@@ -39,6 +39,17 @@ class VultrResponse(JsonResponse):
             raise LibcloudError(self.body)
 
 
+class SSHKey(object):
+    def __init__(self, id, name, pub_key):
+        self.id = id
+        self.name = name
+        self.pub_key = pub_key
+
+    def __repr__(self):
+        return (('<SSHKey: id=%s, name=%s, pub_key=%s>') %
+                (self.id, self.name, self.pub_key))
+
+
 class VultrConnection(ConnectionKey):
     """
     Connection class for the Vultr driver.
@@ -85,6 +96,14 @@ class VultrNodeDriver(NodeDriver):
     def list_nodes(self):
         return self._list_resources('/v1/server/list', self._to_node)
 
+    def list_key_pairs(self):
+        """
+        List all the available SSH keys.
+        :return: Available SSH keys.
+        :rtype: ``list`` of :class:`SSHKey`
+        """
+        return self._list_resources('/v1/sshkey/list', self._to_ssh_key)
+
     def list_locations(self):
         return self._list_resources('/v1/regions/list', self._to_location)
 
@@ -94,10 +113,13 @@ class VultrNodeDriver(NodeDriver):
     def list_images(self):
         return self._list_resources('/v1/os/list', self._to_image)
 
-    def create_node(self, name, size, image, location):
+    def create_node(self, name, size, image, location, ex_ssh_key_ids=None):
         params = {'DCID': location.id, 'VPSPLANID': size.id,
                   'OSID': image.id, 'label': name}
 
+        if ex_ssh_key_ids is not None:
+            params['SSHKEYID'] = ','.join(ex_ssh_key_ids)
+
         result = self.connection.post('/v1/server/create', params)
         if result.status != httplib.OK:
             return False
@@ -182,3 +204,7 @@ class VultrNodeDriver(NodeDriver):
         extra = {'arch': data['arch'], 'family': data['family']}
         return NodeImage(id=data['OSID'], name=data['name'], extra=extra,
                          driver=self)
+
+    def _to_ssh_key(self, data):
+        return SSHKey(id=data['SSHKEYID'], name=data['name'],
+                      pub_key=data['ssh_key'])


Mime
View raw message