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

Cloudstack driver ex_list_keypairs does not work if no keypairs exist

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.13.2
    • Fix Version/s: 0.14.0-beta3
    • Component/s: Compute
    • Labels:
      None
    • Environment:

      python 2.6

      Description

      If there are no sshkeypairs in cloudstack one gets the following when trying ex_list_keypairs or ex_create_keypair which calls the first:

      Traceback (most recent call last):
      File "./csListKeyPairs.py", line 26, in <module>
      keys = driver.ex_list_keypairs()
      File "/usr/lib/python2.6/site-packages/libcloud/compute/drivers/cloudstack.py", line 601, in ex_list_keypairs
      return res['sshkeypair']
      KeyError: 'sshkeypair'

      I fixed it with the following change. Please note I am a python noob so not sure if this is the best way to do fix or not:

      — apache-libcloud-0.13.2/libcloud/compute/drivers/cloudstack.py 2013-09-15 15:40:43.000000000 +0000
      +++ cloudstack.py 2013-11-14 04:05:26.000000000 +0000
      @@ -597,7 +598,9 @@

      extra_args = kwargs.copy()
      res = self._sync_request('listSSHKeyPairs', **extra_args)

      • return res['sshkeypair']
        + if res.has_key('sshkeypair'):
        + return res['sshkeypair']
        + return {}

      def ex_create_keypair(self, name, **kwargs):
      """

        Activity

        Hide
        kami Tomaz Muraus added a comment -

        Carlos Reategui I improved and fixed the original patch you have attached to this ticket, added tests and merged it into trunk.

        The issue with the attached patch is that it returns an invalid value. It returns an empty dict while it should return an empty list. I imagine the reason for that is that you have just followed a docstring which incorrectly states that the method returns a dictionary. In any case, I have also fixed the docstring.

        @sebastien goasguen During the hackathon we can go over the driver together and find the things which can be worked on / improved

        Thanks for reporting this issue!

        Show
        kami Tomaz Muraus added a comment - Carlos Reategui I improved and fixed the original patch you have attached to this ticket, added tests and merged it into trunk. The issue with the attached patch is that it returns an invalid value. It returns an empty dict while it should return an empty list. I imagine the reason for that is that you have just followed a docstring which incorrectly states that the method returns a dictionary. In any case, I have also fixed the docstring. @sebastien goasguen During the hackathon we can go over the driver together and find the things which can be worked on / improved Thanks for reporting this issue!
        Hide
        creategui Carlos Reategui added a comment -

        sebastien goasguen Browsing the code, I think ex_list_security_groups may have the same problem.

        Show
        creategui Carlos Reategui added a comment - sebastien goasguen Browsing the code, I think ex_list_security_groups may have the same problem.
        Hide
        sebgoa sebastien goasguen added a comment -

        yes, omission on my part. indeed it can return nothing...I will check it during the hackathon in amsterdam, we can probably patch it then.

        Show
        sebgoa sebastien goasguen added a comment - yes, omission on my part. indeed it can return nothing...I will check it during the hackathon in amsterdam, we can probably patch it then.
        Hide
        kami Tomaz Muraus added a comment -

        Looks good to me. sebastien goasguen what do you think?

        Show
        kami Tomaz Muraus added a comment - Looks good to me. sebastien goasguen what do you think?

          People

          • Assignee:
            kami Tomaz Muraus
            Reporter:
            creategui Carlos Reategui
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development