Browse Source

support querying available volumes by name

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

+ 26
- 0
downpour/query.py View File

@@ -27,6 +27,7 @@ class ResourceFileEditor:
27 27
         self._resources = resources.load(filename, missing_ok=True)
28 28
         self._servers = set(s.name for s in self._resources.servers)
29 29
         self._images = set(i.name for i in self._resources.images)
30
+        self._volumes = set(v.name for v in self._resources.volumes)
30 31
 
31 32
     def add_server(self, info):
32 33
         if info.name in self._servers:
@@ -46,6 +47,15 @@ class ResourceFileEditor:
46 47
             'name': info.name,
47 48
         })
48 49
 
50
+    def add_volume(self, info):
51
+        if info.name in self._volumes:
52
+            return
53
+        LOG.info('found volume %s to export', info.name)
54
+        self._resources.volumes.append({
55
+            'name': info.name,
56
+            'save_state': self._save_state,
57
+        })
58
+
49 59
     def save(self):
50 60
         resources.save(self._filename, self._resources)
51 61
 
@@ -83,6 +93,12 @@ def register_command(subparsers):
83 93
         default=[],
84 94
         help='pattern to match against image names',
85 95
     )
96
+    do_query.add_argument(
97
+        '--volume-name',
98
+        action='append',
99
+        default=[],
100
+        help='pattern to match against volume names',
101
+    )
86 102
     do_query.set_defaults(func=query_data)
87 103
 
88 104
 
@@ -105,4 +121,14 @@ def query_data(cloud, config, args):
105 121
         for info in cloud.search_images(name_or_id=pattern):
106 122
             editor.add_image(info)
107 123
 
124
+    for pattern in args.volume_name:
125
+        LOG.info('searching for available volumes matching pattern %r',
126
+                 pattern)
127
+        for info in cloud.search_volumes(
128
+                name_or_id=pattern,
129
+                filters={
130
+                    'status': 'available',
131
+                }):
132
+            editor.add_volume(info)
133
+
108 134
     editor.save()

Loading…
Cancel
Save