Browse Source

handle query for server by name

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

+ 1
- 0
.gitignore View File

@@ -63,3 +63,4 @@ releasenotes/build
63 63
 /demo/*.retry
64 64
 /demo/venv
65 65
 /demo/export/*
66
+/demo/query-resources.yml

+ 26
- 2
downpour/query.py View File

@@ -14,7 +14,7 @@
14 14
 
15 15
 import logging
16 16
 
17
-import yaml
17
+from downpour import resources
18 18
 
19 19
 LOG = logging.getLogger(__name__)
20 20
 
@@ -28,8 +28,32 @@ def register_command(subparsers):
28 28
         'resource_file',
29 29
         help='the name of the file listing resources to be updated',
30 30
     )
31
+    do_query.add_argument(
32
+        '--save-state',
33
+        action='store_true',
34
+        default=False,
35
+        help='should the state of the server or volume be saved',
36
+    )
37
+    do_query.add_argument(
38
+        '--server',
39
+        action='append',
40
+        help='pattern to match against server names',
41
+    )
31 42
     do_query.set_defaults(func=query_data)
32 43
 
33 44
 
34 45
 def query_data(cloud, config, args):
35
-    raise NotImplementedError('query not implemented')
46
+    to_export = resources.load(args.resource_file, missing_ok=True)
47
+    servers = set(s.name for s in to_export.servers)
48
+
49
+    for pattern in args.server:
50
+        LOG.info('searching for server %r', pattern)
51
+        for server_info in cloud.search_servers(name_or_id=pattern):
52
+            if server_info.name not in servers:
53
+                LOG.info('found server %s to export', server_info.name)
54
+                to_export.servers.append({
55
+                    'name': server_info.name,
56
+                    'save_state': args.save_state,
57
+                })
58
+
59
+    resources.save(args.resource_file, to_export)

Loading…
Cancel
Save