diff --git a/aerostat/app.py b/aerostat/app.py index c054f06..de3ec65 100644 --- a/aerostat/app.py +++ b/aerostat/app.py @@ -65,11 +65,11 @@ def main(): for volume_info in to_export.volumes: volume = cloud.get_volume(volume_info.name) - tasks.extend(res.volume(volume)) + tasks.extend(res.volume(volume, save_state=volume_info.save_state)) for server_info in to_export.servers: server = cloud.get_server(server_info.name) - tasks.extend(res.server(server)) + tasks.extend(res.server(server, save_state=server_info.save_state)) playbook = [ # The default playbook is configured to run instructions diff --git a/aerostat/download.py b/aerostat/download.py index 3cdd66d..f32f1c7 100644 --- a/aerostat/download.py +++ b/aerostat/download.py @@ -72,6 +72,9 @@ class Downloader: self._add('image', image, output_path) return base + def add_volume(self, volume): + print('DO NOT KNOW HOW TO SAVE VOLUME STATE YET', volume.name) + def start(self): # FIXME(dhellmann): start downloads in a separate thread or process for resource_type, resource, output_path in self._tasks: diff --git a/aerostat/resolver.py b/aerostat/resolver.py index 3bb827c..8eae859 100644 --- a/aerostat/resolver.py +++ b/aerostat/resolver.py @@ -58,13 +58,15 @@ class Resolver: rule_data['remote_group_id'] = remote_groups[rule.remote_group_id] yield {'os_security_group_rule': rule_data} - def volume(self, volume): + def volume(self, volume, save_state): # FIXME(dhellmann): For now this only creates new empty # volumes, and doesn't handle cases like booting from a volume # or creating a volume from an image. # # FIXME(dhellmann): Need to snapshot the volume and then # download the results. + if save_state: + self._downloader.add_volume(volume) yield { 'name': 'Create volume {}'.format(volume.name), 'os_volume': { @@ -75,8 +77,7 @@ class Resolver: }, } - def server(self, server): - pprint.pprint(server) + def server(self, server, save_state): for sg in server.security_groups: sg_data = self.cloud.get_security_group(sg.name) yield from self.security_group(sg_data) @@ -84,7 +85,7 @@ class Resolver: for vol in server.volumes: vol_data = self.cloud.get_volume(vol.id) vol_names.append(vol_data.name) - yield from self.volume(vol_data) + yield from self.volume(vol_data, save_state) # FIXME(dhellmann): Need to handle networks other than 'public'. # FIXME(dhellmann): Need to handle public IPs. Use auto_ip? # FIXME(dhellmann): For now assume the image exists, but we may diff --git a/aerostat/resources.py b/aerostat/resources.py index 123e71d..2867c84 100644 --- a/aerostat/resources.py +++ b/aerostat/resources.py @@ -21,6 +21,8 @@ import munch def load(filename): "Read the file and return the parsed data in a consistent format." + # Ensure the return value has a basic set of keys representing the + # types of resources we expect to find. to_return = munch.Munch( servers=[], volumes=[], @@ -29,6 +31,16 @@ def load(filename): with open(filename, 'r', encoding='utf-8') as fd: contents = munch.Munch.fromYAML(fd.read()) - to_return.update(contents) + + # Ensure all entries have consistent sets of keys so the rest of + # the app doesn't have to check every time it wants to use a + # value. + for s in to_return.servers: + if 'save_state' not in s: + s['save_state'] = True + for s in to_return.volumes: + if 'save_state' not in s: + s['save_state'] = True + return to_return