[
https://issues.apache.org/jira/browse/LIBCLOUD-687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14394496#comment-14394496
]
Eric Johnson commented on LIBCLOUD-687:
---------------------------------------
Thanks for this most excellent bug report Eli!
I'll work on a fix soon and hopefully get it into a 0.17.1 release.
> Unable to set GCE metadata if no metadata already exists
> --------------------------------------------------------
>
> Key: LIBCLOUD-687
> URL: https://issues.apache.org/jira/browse/LIBCLOUD-687
> 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/gce.py",
> 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
(v6.3.4#6332)