add save_state flag for expensive resources
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
0656fd6d54
commit
7ddac309d5
|
@ -65,11 +65,11 @@ def main():
|
||||||
|
|
||||||
for volume_info in to_export.volumes:
|
for volume_info in to_export.volumes:
|
||||||
volume = cloud.get_volume(volume_info.name)
|
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:
|
for server_info in to_export.servers:
|
||||||
server = cloud.get_server(server_info.name)
|
server = cloud.get_server(server_info.name)
|
||||||
tasks.extend(res.server(server))
|
tasks.extend(res.server(server, save_state=server_info.save_state))
|
||||||
|
|
||||||
playbook = [
|
playbook = [
|
||||||
# The default playbook is configured to run instructions
|
# The default playbook is configured to run instructions
|
||||||
|
|
|
@ -72,6 +72,9 @@ class Downloader:
|
||||||
self._add('image', image, output_path)
|
self._add('image', image, output_path)
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
def add_volume(self, volume):
|
||||||
|
print('DO NOT KNOW HOW TO SAVE VOLUME STATE YET', volume.name)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# FIXME(dhellmann): start downloads in a separate thread or process
|
# FIXME(dhellmann): start downloads in a separate thread or process
|
||||||
for resource_type, resource, output_path in self._tasks:
|
for resource_type, resource, output_path in self._tasks:
|
||||||
|
|
|
@ -58,13 +58,15 @@ class Resolver:
|
||||||
rule_data['remote_group_id'] = remote_groups[rule.remote_group_id]
|
rule_data['remote_group_id'] = remote_groups[rule.remote_group_id]
|
||||||
yield {'os_security_group_rule': rule_data}
|
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
|
# FIXME(dhellmann): For now this only creates new empty
|
||||||
# volumes, and doesn't handle cases like booting from a volume
|
# volumes, and doesn't handle cases like booting from a volume
|
||||||
# or creating a volume from an image.
|
# or creating a volume from an image.
|
||||||
#
|
#
|
||||||
# FIXME(dhellmann): Need to snapshot the volume and then
|
# FIXME(dhellmann): Need to snapshot the volume and then
|
||||||
# download the results.
|
# download the results.
|
||||||
|
if save_state:
|
||||||
|
self._downloader.add_volume(volume)
|
||||||
yield {
|
yield {
|
||||||
'name': 'Create volume {}'.format(volume.name),
|
'name': 'Create volume {}'.format(volume.name),
|
||||||
'os_volume': {
|
'os_volume': {
|
||||||
|
@ -75,8 +77,7 @@ class Resolver:
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def server(self, server):
|
def server(self, server, save_state):
|
||||||
pprint.pprint(server)
|
|
||||||
for sg in server.security_groups:
|
for sg in server.security_groups:
|
||||||
sg_data = self.cloud.get_security_group(sg.name)
|
sg_data = self.cloud.get_security_group(sg.name)
|
||||||
yield from self.security_group(sg_data)
|
yield from self.security_group(sg_data)
|
||||||
|
@ -84,7 +85,7 @@ class Resolver:
|
||||||
for vol in server.volumes:
|
for vol in server.volumes:
|
||||||
vol_data = self.cloud.get_volume(vol.id)
|
vol_data = self.cloud.get_volume(vol.id)
|
||||||
vol_names.append(vol_data.name)
|
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 networks other than 'public'.
|
||||||
# FIXME(dhellmann): Need to handle public IPs. Use auto_ip?
|
# FIXME(dhellmann): Need to handle public IPs. Use auto_ip?
|
||||||
# FIXME(dhellmann): For now assume the image exists, but we may
|
# FIXME(dhellmann): For now assume the image exists, but we may
|
||||||
|
|
|
@ -21,6 +21,8 @@ import munch
|
||||||
def load(filename):
|
def load(filename):
|
||||||
"Read the file and return the parsed data in a consistent format."
|
"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(
|
to_return = munch.Munch(
|
||||||
servers=[],
|
servers=[],
|
||||||
volumes=[],
|
volumes=[],
|
||||||
|
@ -29,6 +31,16 @@ def load(filename):
|
||||||
|
|
||||||
with open(filename, 'r', encoding='utf-8') as fd:
|
with open(filename, 'r', encoding='utf-8') as fd:
|
||||||
contents = munch.Munch.fromYAML(fd.read())
|
contents = munch.Munch.fromYAML(fd.read())
|
||||||
|
|
||||||
to_return.update(contents)
|
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
|
return to_return
|
||||||
|
|
Loading…
Reference in New Issue