Browse Source

support querying images by name

Change-Id: Idc4cb0eb0bad40d6cf18597b984941a1f2879607
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 2 years ago
parent
commit
91786cdd9f
1 changed files with 20 additions and 0 deletions
  1. 20
    0
      downpour/query.py

+ 20
- 0
downpour/query.py View File

@@ -26,6 +26,7 @@ class ResourceFileEditor:
26 26
         self._save_state = save_state
27 27
         self._resources = resources.load(filename, missing_ok=True)
28 28
         self._servers = set(s.name for s in self._resources.servers)
29
+        self._images = set(i.name for i in self._resources.images)
29 30
 
30 31
     def add_server(self, info):
31 32
         if info.name in self._servers:
@@ -37,6 +38,14 @@ class ResourceFileEditor:
37 38
             'key_name': info.key_name,
38 39
         })
39 40
 
41
+    def add_image(self, info):
42
+        if info.name in self._images:
43
+            return
44
+        LOG.info('found image %s to export', info.name)
45
+        self._resources.images.append({
46
+            'name': info.name,
47
+        })
48
+
40 49
     def save(self):
41 50
         resources.save(self._filename, self._resources)
42 51
 
@@ -68,6 +77,12 @@ def register_command(subparsers):
68 77
         default=[],
69 78
         help='server flavor(s) to capture',
70 79
     )
80
+    do_query.add_argument(
81
+        '--image-name',
82
+        action='append',
83
+        default=[],
84
+        help='pattern to match against image names',
85
+    )
71 86
     do_query.set_defaults(func=query_data)
72 87
 
73 88
 
@@ -85,4 +100,9 @@ def query_data(cloud, config, args):
85 100
                 filters={'flavor': {'id': flavor}}):
86 101
             editor.add_server(server_info)
87 102
 
103
+    for pattern in args.image_name:
104
+        LOG.info('searching for images matching pattern %r', pattern)
105
+        for info in cloud.search_images(name_or_id=pattern):
106
+            editor.add_image(info)
107
+
88 108
     editor.save()

Loading…
Cancel
Save