summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2017-01-31 16:40:54 -0500
committerDoug Hellmann <doug@doughellmann.com>2017-01-31 16:40:54 -0500
commit0656fd6d547b7e77f4bf41daa02d0e77b5af47cc (patch)
tree283779ed71fce45893a915f68180713e8dda5e05
parentfc3335e5953f4c9ba4afc3a03332c0d27eb95fba (diff)
read list of resources to export from data file
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
-rw-r--r--.gitignore2
-rw-r--r--aerostat/app.py27
-rw-r--r--aerostat/resources.py34
3 files changed, 51 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index f22580b..3114356 100644
--- a/.gitignore
+++ b/.gitignore
@@ -58,4 +58,4 @@ ChangeLog
58releasenotes/build 58releasenotes/build
59/clouds.yaml 59/clouds.yaml
60/*.dat 60/*.dat
61/playbook.yml 61/*.yml
diff --git a/aerostat/app.py b/aerostat/app.py
index 37ffc55..c054f06 100644
--- a/aerostat/app.py
+++ b/aerostat/app.py
@@ -27,6 +27,7 @@ import yaml
27 27
28from aerostat import download 28from aerostat import download
29from aerostat import resolver 29from aerostat import resolver
30from aerostat import resources
30 31
31 32
32def main(): 33def main():
@@ -52,28 +53,32 @@ def main():
52 cloud = shade.OpenStackCloud(cloud_config=cloud_config) 53 cloud = shade.OpenStackCloud(cloud_config=cloud_config)
53 downloader = download.Downloader(output_path, cloud) 54 downloader = download.Downloader(output_path, cloud)
54 res = resolver.Resolver(cloud, downloader) 55 res = resolver.Resolver(cloud, downloader)
55
56 tasks = [] 56 tasks = []
57 57
58 # FIXME(dhellmann): We want the list of things to download to be 58 # Export independent resources. The resolver handles dependencies
59 # part of the inputs to the program, but for now let's just grab 59 # automatically.
60 # all servers and private images.. 60 to_export = resources.load(args.resource_file)
61
62 for server in cloud.list_servers():
63 tasks.extend(res.server(server))
64 61
65 for image in cloud.list_images(): 62 for image_info in to_export.images:
66 if image.visibility != 'private': 63 image = cloud.get_image(image_info.name)
67 continue
68 tasks.extend(res.image(image)) 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 playbook = [ 74 playbook = [
75 # The default playbook is configured to run instructions
76 # locally to talk to the cloud API.
71 {'hosts': 'localhost', 77 {'hosts': 'localhost',
72 'connection': 'local', 78 'connection': 'local',
73 'tasks': tasks, 79 'tasks': tasks,
74 }, 80 },
75 ] 81 ]
76
77 playbook_filename = os.path.join(output_path, 'playbook.yml') 82 playbook_filename = os.path.join(output_path, 'playbook.yml')
78 with open(playbook_filename, 'w', encoding='utf-8') as fd: 83 with open(playbook_filename, 'w', encoding='utf-8') as fd:
79 yaml.dump(playbook, fd, default_flow_style=False, explicit_start=True) 84 yaml.dump(playbook, fd, default_flow_style=False, explicit_start=True)
diff --git a/aerostat/resources.py b/aerostat/resources.py
new file mode 100644
index 0000000..123e71d
--- /dev/null
+++ b/aerostat/resources.py
@@ -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
18import munch
19
20
21def 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