support querying images by name
Change-Id: Idc4cb0eb0bad40d6cf18597b984941a1f2879607 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
3467befaf1
commit
91786cdd9f
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue