Browse Source

read list of resources to export from data file

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
tags/0.1.0
Doug Hellmann 2 years ago
parent
commit
0656fd6d54
3 changed files with 51 additions and 12 deletions
  1. 1
    1
      .gitignore
  2. 16
    11
      aerostat/app.py
  3. 34
    0
      aerostat/resources.py

+ 1
- 1
.gitignore View File

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

+ 16
- 11
aerostat/app.py View File

@@ -27,6 +27,7 @@ import yaml
27 27
 
28 28
 from aerostat import download
29 29
 from aerostat import resolver
30
+from aerostat import resources
30 31
 
31 32
 
32 33
 def main():
@@ -52,28 +53,32 @@ def main():
52 53
     cloud = shade.OpenStackCloud(cloud_config=cloud_config)
53 54
     downloader = download.Downloader(output_path, cloud)
54 55
     res = resolver.Resolver(cloud, downloader)
55
-
56 56
     tasks = []
57 57
 
58
-    # FIXME(dhellmann): We want the list of things to download to be
59
-    # part of the inputs to the program, but for now let's just grab
60
-    # all servers and private images..
61
-
62
-    for server in cloud.list_servers():
63
-        tasks.extend(res.server(server))
58
+    # Export independent resources. The resolver handles dependencies
59
+    # automatically.
60
+    to_export = resources.load(args.resource_file)
64 61
 
65
-    for image in cloud.list_images():
66
-        if image.visibility != 'private':
67
-            continue
62
+    for image_info in to_export.images:
63
+        image = cloud.get_image(image_info.name)
68 64
         tasks.extend(res.image(image))
69 65
 
66
+    for volume_info in to_export.volumes:
67
+        volume = cloud.get_volume(volume_info.name)
68
+        tasks.extend(res.volume(volume))
69
+
70
+    for server_info in to_export.servers:
71
+        server = cloud.get_server(server_info.name)
72
+        tasks.extend(res.server(server))
73
+
70 74
     playbook = [
75
+        # The default playbook is configured to run instructions
76
+        # locally to talk to the cloud API.
71 77
         {'hosts': 'localhost',
72 78
          'connection': 'local',
73 79
          'tasks': tasks,
74 80
          },
75 81
     ]
76
-
77 82
     playbook_filename = os.path.join(output_path, 'playbook.yml')
78 83
     with open(playbook_filename, 'w', encoding='utf-8') as fd:
79 84
         yaml.dump(playbook, fd, default_flow_style=False, explicit_start=True)

+ 34
- 0
aerostat/resources.py View File

@@ -0,0 +1,34 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+# Copyright 2010-2011 OpenStack Foundation
4
+# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
5
+#
6
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
+# not use this file except in compliance with the License. You may obtain
8
+# a copy of the License at
9
+#
10
+#      http://www.apache.org/licenses/LICENSE-2.0
11
+#
12
+# Unless required by applicable law or agreed to in writing, software
13
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+# License for the specific language governing permissions and limitations
16
+# under the License.
17
+
18
+import munch
19
+
20
+
21
+def load(filename):
22
+    "Read the file and return the parsed data in a consistent format."
23
+
24
+    to_return = munch.Munch(
25
+        servers=[],
26
+        volumes=[],
27
+        images=[],
28
+    )
29
+
30
+    with open(filename, 'r', encoding='utf-8') as fd:
31
+        contents = munch.Munch.fromYAML(fd.read())
32
+
33
+    to_return.update(contents)
34
+    return to_return

Loading…
Cancel
Save