libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (LIBCLOUD-687) Unable to set GCE metadata if no metadata already exists
Date Wed, 13 May 2015 20:44:01 GMT


ASF GitHub Bot commented on LIBCLOUD-687:

GitHub user erjohnso opened a pull request:

    [google compute] handle empty project metadata

    Bugfix for new projects that contain no project-level metadata. This fixes

You can merge this pull request into a Git repository by running:

    $ git pull jira687

Alternatively you can review and apply these changes as the patch at:

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #521
commit cc988cc9b40ebaf50bcc523bb48caef9c868bdbf
Author: Eric Johnson <>
Date:   2015-05-13T20:31:45Z

    [google compute] handle empty project metadata


> Unable to set GCE metadata if no metadata already exists
> --------------------------------------------------------
>                 Key: LIBCLOUD-687
>                 URL:
>             Project: Libcloud
>          Issue Type: Bug
>          Components: Compute
>            Reporter: Eli Courtwright
>            Assignee: Eric Johnson
> 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:
> {code}
> >>> 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'
> {code}
> 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:
> {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']:
> {code}
> 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:
> {code}
> 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
> {code}
> but having a "real" fix would be great for the next version.

This message was sent by Atlassian JIRA

View raw message