libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eli Courtwright (JIRA)" <>
Subject [jira] [Created] (LIBCLOUD-687) Unable to set GCE metadata if no metadata already exists
Date Fri, 03 Apr 2015 14:36:53 GMT
Eli Courtwright created LIBCLOUD-687:

             Summary: Unable to set GCE metadata if no metadata already exists
                 Key: LIBCLOUD-687
             Project: Libcloud
          Issue Type: Bug
          Components: Compute
            Reporter: Eli Courtwright

The {{libcloud.compute.drivers.gce.GCENodeDriver}} class has a nonstandard method {{ex_set_common_metadata}}
which we can use to (among other things) set SSH keys.

When calling this method on the latest libcloud 0.17.0 (which is not currently a listed version
in Jira), I get the following error:
>>> conn.ex_set_common_instance_metadata({})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/sideboard/lib/python2.7/site-packages/libcloud/compute/drivers/", line
1129, in ex_set_common_instance_metadata
    for md in current_metadata['items']:
KeyError: 'items'

I get this error regardless of what data I pass to the {{ex_set_common_instance_metadata}}
method.  From delving into the libcloud code, I find the following block of code:

        project = self.ex_get_project()
        current_metadata = project.extra['commonInstanceMetadata']
        fingerprint = current_metadata['fingerprint']

        # grab copy of current 'sshKeys' in case we want to retain them
        current_keys = ""
        for md in current_metadata['items']:

So it looks as if the method assumes that {{self.ex_get_project()}} will return:
- an object with a {{.extra}} dictionary (which it does)
- that dictionary will have a "commonInstanceMetadata" key which maps to another dictionary
(which is correct)
- that sub-dictionary will have an "items" key whose value is iterable (which is wrong)

That last assumption is only wrong if there is no project metadata already associated with
the project, e.g. for a new project.

I'm working around this problem currently by monkeypatching libcloud:

def patch_gce_ex_get_project():
    orig_get_project = GCENodeDriver.ex_get_project
    def ex_get_project(self):
        project = orig_get_project(self)
        project.extra['commonInstanceMetadata'].setdefault('items', [])
        return project
    GCENodeDriver.ex_get_project = ex_get_project

but having a "real" fix would be great for the next version.

This message was sent by Atlassian JIRA

View raw message