launch-node.py: request flavors/images by ID or name

It is deemed useful by some to pass IDs rather than names to
launch-node.py for flavors and images; mostly due to the fact that
names are not unique, and the "first-matched" behavior on names
means that it can end up doing the wrong thing in certain cases.

Change-Id: Ief89174fedac7921f85bbfe3a456059ecc0f19bf
This commit is contained in:
Nicolas Simonds 2014-08-06 11:08:28 -07:00
parent 142410fc33
commit d795d7f6fb

View File

@ -194,12 +194,13 @@ def main():
cert)): cert)):
raise Exception("Please specify the name of a signed puppet cert.") raise Exception("Please specify the name of a signed puppet cert.")
flavors = [f for f in client.flavors.list() if options.flavor in f.name] flavors = [f for f in client.flavors.list()
if options.flavor in (f.name, f.id)]
flavor = flavors[0] flavor = flavors[0]
print "Found flavor", flavor print "Found flavor", flavor
images = [i for i in client.images.list() images = [i for i in client.images.list()
if (options.image.lower() in i.name.lower() and if (options.image.lower() in (i.id, i.name.lower()) and
not i.name.endswith('(Kernel)') and not i.name.endswith('(Kernel)') and
not i.name.endswith('(Ramdisk)'))] not i.name.endswith('(Ramdisk)'))]