You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@libcloud.apache.org by "sebastien goasguen (JIRA)" <ji...@apache.org> on 2013/05/28 14:01:25 UTC

[dev] [jira] [Commented] (LIBCLOUD-333) CloudStack driver does not deal with SSH KeyPairs

    [ https://issues.apache.org/jira/browse/LIBCLOUD-333?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13668257#comment-13668257 ] 

sebastien goasguen commented on LIBCLOUD-333:
---------------------------------------------

Same as 332, here is the basic functionality. I tested it with a production cloud. I have not written tests yet and you may want to handle extra arguments a different way. Let me know:

----

>From fcaa0e6c5b8818fa0d8136c7108f55a88290671c Mon Sep 17 00:00:00 2001
From: Sebastien Goasguen <ru...@gmail.com>
Date: Tue, 28 May 2013 07:58:48 -0400
Subject: [PATCH] LIBCLOUD-333: three functions to manage ssh keypairs

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

diff --git libcloud/compute/drivers/cloudstack.py libcloud/compute/drivers/cloudstack.py
index e2c85dd..49d2695 100644
--- libcloud/compute/drivers/cloudstack.py
+++ libcloud/compute/drivers/cloudstack.py
@@ -463,6 +463,72 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
         self._async_request('deleteIpForwardingRule', id=rule.id)
         return True
 
+    def ex_list_keypairs(self, **kwargs):
+        """
+        List Registered SSH Key Pairs
+
+        Parameters
+		==========
+		projectid = (uuid) list objects by project
+		page = (integer) 
+		keyword = (string) List by keyword
+		listall = (boolean) If set to false, list only resources belonging to the command's caller; if set to true - list resources that the caller is authorized to see. Default value is false
+		pagesize = (integer) 
+		account = (string) list resources by account. Must be used with the domainId parameter.
+		isrecursive = (boolean) defaults to false, but if true, lists all resources from the parent specified by the domainId till leaves.
+		fingerprint = (string) A public key fingerprint to look for
+		name = (string) A key pair name to look for
+		domainid = (uuid) list only resources belonging to the domain specified
+        """	
+        
+        extra_args={}
+        for key in kwargs.keys():
+            extra_args[key]=kwargs.pop(key)
+     
+        return self._sync_request('listSSHKeyPairs', **extra_args)['sshkeypair']
+
+    def ex_create_keypair(self, name, **kwargs):
+        """
+        Creates a SSH KeyPair, returns fingerprint and private key
+
+        Required params are name
+        Parameters
+		==========
+		projectid = (uuid) an optional project for the ssh key
+		domainid = (uuid) an optional domainId for the ssh key. If the account parameter is used, domainId must also be used.
+		name = (string) Name of the keypair
+		account = (string) an optional account for the ssh key. Must be used with domainId.
+        """
+
+        extra_args={}
+        for key in kwargs.keys():
+            extra_args[key]=kwargs.pop(key)
+
+        for keypair in self.ex_list_keypairs():
+             if keypair['name'] == name:
+                 raise LibcloudError('SSH KeyPair with name=%s already exists' % name)
+
+        return self._sync_request('createSSHKeyPair',name=name, **extra_args)['keypair']
+
+    def ex_delete_keypair(self,name, **kwargs):
+        """
+        Deletes an existing SSH KeyPair
+
+        Required params are name
+        Parameters
+		==========
+		projectid = (uuid) the project associated with keypair
+		domainid = (uuid) the domain ID associated with the keypair
+		name = (string) Name of the keypair
+		account = (string) the account associated with the keypair. Must be used with the domainId parameter.
+        """
+
+        extra_args={}
+        for key in kwargs.keys():
+            extra_args[key]=kwargs.pop(key)
+
+        return self._sync_request('deleteSSHKeyPair',name=name, **extra_args)['success']
+
     def ex_register_iso(self, name, url, location=None, **kwargs):
         """
         Registers an existing ISO by URL.
-- 
1.8.1.3
                
> CloudStack driver does not deal with SSH KeyPairs
> -------------------------------------------------
>
>                 Key: LIBCLOUD-333
>                 URL: https://issues.apache.org/jira/browse/LIBCLOUD-333
>             Project: Libcloud
>          Issue Type: Bug
>          Components: Compute
>    Affects Versions: 0.12.3
>         Environment: trunk
>            Reporter: sebastien goasguen
>
> there are no extension functions for managing ssh key pairs.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira