Browse Source

add input and output args; write playbook to file

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 2 years ago
parent
commit
fc3335e595
2 changed files with 22 additions and 5 deletions
  1. 1
    0
      .gitignore
  2. 21
    5
      aerostat/app.py

+ 1
- 0
.gitignore View File

@@ -58,3 +58,4 @@ ChangeLog
58 58
 releasenotes/build
59 59
 /clouds.yaml
60 60
 /*.dat
61
+/playbook.yml

+ 21
- 5
aerostat/app.py View File

@@ -16,6 +16,7 @@
16 16
 # under the License.
17 17
 
18 18
 import argparse
19
+import os.path
19 20
 import pprint
20 21
 import sys
21 22
 
@@ -33,11 +34,23 @@ def main():
33 34
     config = os_client_config.OpenStackConfig()
34 35
 
35 36
     config.register_argparse_arguments(parser, sys.argv, None)
36
-    parsed_options = parser.parse_known_args(sys.argv[1:])
37
-
38
-    cloud_config = config.get_one_cloud(options=parsed_options)
37
+    parser.add_argument(
38
+        'resource_file',
39
+        help='the name of the file listing resources to be exported',
40
+    )
41
+    parser.add_argument(
42
+        'output_path',
43
+        default='.',
44
+        nargs='?',
45
+        help='the name of a directory to use for output file(s)',
46
+    )
47
+
48
+    args, remaining = parser.parse_known_args(sys.argv[1:])
49
+    output_path = args.output_path
50
+
51
+    cloud_config = config.get_one_cloud(options=(args, remaining))
39 52
     cloud = shade.OpenStackCloud(cloud_config=cloud_config)
40
-    downloader = download.Downloader('.', cloud)
53
+    downloader = download.Downloader(output_path, cloud)
41 54
     res = resolver.Resolver(cloud, downloader)
42 55
 
43 56
     tasks = []
@@ -61,7 +74,10 @@ def main():
61 74
          },
62 75
     ]
63 76
 
64
-    print(yaml.dump(playbook, default_flow_style=False, explicit_start=True))
77
+    playbook_filename = os.path.join(output_path, 'playbook.yml')
78
+    with open(playbook_filename, 'w', encoding='utf-8') as fd:
79
+        yaml.dump(playbook, fd, default_flow_style=False, explicit_start=True)
80
+    print('wrote playbook to {}'.format(playbook_filename))
65 81
 
66 82
     downloader.start()
67 83
 

Loading…
Cancel
Save