Browse Source

add save_state flag for expensive resources

Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 2 years ago
parent
commit
7ddac309d5
4 changed files with 23 additions and 7 deletions
  1. 2
    2
      aerostat/app.py
  2. 3
    0
      aerostat/download.py
  3. 5
    4
      aerostat/resolver.py
  4. 13
    1
      aerostat/resources.py

+ 2
- 2
aerostat/app.py View File

@@ -65,11 +65,11 @@ def main():
65 65
 
66 66
     for volume_info in to_export.volumes:
67 67
         volume = cloud.get_volume(volume_info.name)
68
-        tasks.extend(res.volume(volume))
68
+        tasks.extend(res.volume(volume, save_state=volume_info.save_state))
69 69
 
70 70
     for server_info in to_export.servers:
71 71
         server = cloud.get_server(server_info.name)
72
-        tasks.extend(res.server(server))
72
+        tasks.extend(res.server(server, save_state=server_info.save_state))
73 73
 
74 74
     playbook = [
75 75
         # The default playbook is configured to run instructions

+ 3
- 0
aerostat/download.py View File

@@ -72,6 +72,9 @@ class Downloader:
72 72
         self._add('image', image, output_path)
73 73
         return base
74 74
 
75
+    def add_volume(self, volume):
76
+        print('DO NOT KNOW HOW TO SAVE VOLUME STATE YET', volume.name)
77
+
75 78
     def start(self):
76 79
         # FIXME(dhellmann): start downloads in a separate thread or process
77 80
         for resource_type, resource, output_path in self._tasks:

+ 5
- 4
aerostat/resolver.py View File

@@ -58,13 +58,15 @@ class Resolver:
58 58
                 rule_data['remote_group_id'] = remote_groups[rule.remote_group_id]
59 59
             yield {'os_security_group_rule': rule_data}
60 60
 
61
-    def volume(self, volume):
61
+    def volume(self, volume, save_state):
62 62
         # FIXME(dhellmann): For now this only creates new empty
63 63
         # volumes, and doesn't handle cases like booting from a volume
64 64
         # or creating a volume from an image.
65 65
         #
66 66
         # FIXME(dhellmann): Need to snapshot the volume and then
67 67
         # download the results.
68
+        if save_state:
69
+            self._downloader.add_volume(volume)
68 70
         yield {
69 71
             'name': 'Create volume {}'.format(volume.name),
70 72
             'os_volume': {
@@ -75,8 +77,7 @@ class Resolver:
75 77
             },
76 78
         }
77 79
 
78
-    def server(self, server):
79
-        pprint.pprint(server)
80
+    def server(self, server, save_state):
80 81
         for sg in server.security_groups:
81 82
             sg_data = self.cloud.get_security_group(sg.name)
82 83
             yield from self.security_group(sg_data)
@@ -84,7 +85,7 @@ class Resolver:
84 85
         for vol in server.volumes:
85 86
             vol_data = self.cloud.get_volume(vol.id)
86 87
             vol_names.append(vol_data.name)
87
-            yield from self.volume(vol_data)
88
+            yield from self.volume(vol_data, save_state)
88 89
         # FIXME(dhellmann): Need to handle networks other than 'public'.
89 90
         # FIXME(dhellmann): Need to handle public IPs. Use auto_ip?
90 91
         # FIXME(dhellmann): For now assume the image exists, but we may

+ 13
- 1
aerostat/resources.py View File

@@ -21,6 +21,8 @@ import munch
21 21
 def load(filename):
22 22
     "Read the file and return the parsed data in a consistent format."
23 23
 
24
+    # Ensure the return value has a basic set of keys representing the
25
+    # types of resources we expect to find.
24 26
     to_return = munch.Munch(
25 27
         servers=[],
26 28
         volumes=[],
@@ -29,6 +31,16 @@ def load(filename):
29 31
 
30 32
     with open(filename, 'r', encoding='utf-8') as fd:
31 33
         contents = munch.Munch.fromYAML(fd.read())
32
-
33 34
     to_return.update(contents)
35
+
36
+    # Ensure all entries have consistent sets of keys so the rest of
37
+    # the app doesn't have to check every time it wants to use a
38
+    # value.
39
+    for s in to_return.servers:
40
+        if 'save_state' not in s:
41
+            s['save_state'] = True
42
+    for s in to_return.volumes:
43
+        if 'save_state' not in s:
44
+            s['save_state'] = True
45
+
34 46
     return to_return

Loading…
Cancel
Save