Uploaded image for project: 'Libcloud'
  1. Libcloud
  2. LIBCLOUD-333

CloudStack driver does not deal with SSH KeyPairs

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.12.3
    • Fix Version/s: 0.13.0
    • Component/s: Compute
    • Labels:
      None
    • Environment:

      trunk

      Description

      there are no extension functions for managing ssh key pairs.

      1. acs333.patch
        7 kB
        sebastien goasguen

        Activity

        Hide
        sebgoa sebastien goasguen added a comment -

        thanks. Kinda of too bad that you don't use git. svn authorship information is not kept.

        I opened another bug for the tests.

        Show
        sebgoa sebastien goasguen added a comment - thanks. Kinda of too bad that you don't use git. svn authorship information is not kept. I opened another bug for the tests.
        Hide
        kami Tomaz Muraus added a comment -

        Merged into trunk.

        Please don't forget to submit tests.

        Show
        kami Tomaz Muraus added a comment - Merged into trunk. Please don't forget to submit tests.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1490005 from Tomaz Muraus
        [ https://svn.apache.org/r1490005 ]

        Add extension functions for managing keypairs to the CloudStack driver.

        Contributed by sebastien goasguen, part of LIBCLOUD-333.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1490005 from Tomaz Muraus [ https://svn.apache.org/r1490005 ] Add extension functions for managing keypairs to the CloudStack driver. Contributed by sebastien goasguen, part of LIBCLOUD-333 .
        Hide
        sebgoa sebastien goasguen added a comment -

        Hi Tomaz, I attach a patch.
        Fix a few pep8 compliance issues that were unrelated to this bug.
        Checked all around pep8 compliance.
        Added docstrings
        And access kwargs by keys.
        Checked functionality with a production cloud, it works. I will open a bug for tests..
        If you accept this patch I will work on one for 332

        thanks for your time

        Show
        sebgoa sebastien goasguen added a comment - Hi Tomaz, I attach a patch. Fix a few pep8 compliance issues that were unrelated to this bug. Checked all around pep8 compliance. Added docstrings And access kwargs by keys. Checked functionality with a production cloud, it works. I will open a bug for tests.. If you accept this patch I will work on one for 332 thanks for your time
        Hide
        sebgoa sebastien goasguen added a comment -

        pep8 compliance and docstrings, plus fix about kwargs access

        Show
        sebgoa sebastien goasguen added a comment - pep8 compliance and docstrings, plus fix about kwargs access
        Hide
        kami Tomaz Muraus added a comment - - edited

        Comments from LIBCLOUD-332 also apply here.

        As far as the kwargs go, please directly access the dictionary value (kwargs[key]) instead of using pop. pop removes an item from a dictionary or returns a default value if key doesn't exist and a default value is provided.

        Because of the way Python handlers kwargs, mutating kwargs dictionary won't have any bad side affects, but accessing dictionary in a normal way is preferred if there is no need to mutate the dictionary you operate on.

        Show
        kami Tomaz Muraus added a comment - - edited Comments from LIBCLOUD-332 also apply here. As far as the kwargs go, please directly access the dictionary value (kwargs [key] ) instead of using pop. pop removes an item from a dictionary or returns a default value if key doesn't exist and a default value is provided. Because of the way Python handlers kwargs, mutating kwargs dictionary won't have any bad side affects, but accessing dictionary in a normal way is preferred if there is no need to mutate the dictionary you operate on.
        Hide
        sebgoa sebastien goasguen added a comment -

        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 <runseb@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

        Show
        sebgoa sebastien goasguen added a comment - 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 <runseb@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

          People

          • Assignee:
            kami Tomaz Muraus
            Reporter:
            sebgoa sebastien goasguen
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development