From 91786cdd9f2c4803ccbd878235813e0dc6486240 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Sun, 30 Apr 2017 21:50:53 +0000 Subject: [PATCH] support querying images by name Change-Id: Idc4cb0eb0bad40d6cf18597b984941a1f2879607 Signed-off-by: Doug Hellmann --- downpour/query.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/downpour/query.py b/downpour/query.py index fb0feba..10dd874 100644 --- a/downpour/query.py +++ b/downpour/query.py @@ -26,6 +26,7 @@ class ResourceFileEditor: self._save_state = save_state self._resources = resources.load(filename, missing_ok=True) self._servers = set(s.name for s in self._resources.servers) + self._images = set(i.name for i in self._resources.images) def add_server(self, info): if info.name in self._servers: @@ -37,6 +38,14 @@ class ResourceFileEditor: 'key_name': info.key_name, }) + def add_image(self, info): + if info.name in self._images: + return + LOG.info('found image %s to export', info.name) + self._resources.images.append({ + 'name': info.name, + }) + def save(self): resources.save(self._filename, self._resources) @@ -68,6 +77,12 @@ def register_command(subparsers): default=[], help='server flavor(s) to capture', ) + do_query.add_argument( + '--image-name', + action='append', + default=[], + help='pattern to match against image names', + ) do_query.set_defaults(func=query_data) @@ -85,4 +100,9 @@ def query_data(cloud, config, args): filters={'flavor': {'id': flavor}}): editor.add_server(server_info) + for pattern in args.image_name: + LOG.info('searching for images matching pattern %r', pattern) + for info in cloud.search_images(name_or_id=pattern): + editor.add_image(info) + editor.save()