Browse Source

add support for capturing server state

capture the server, but not any attached volumes

Change-Id: Ifd79908b3ef80f6b208faf424ba998f1dfd80f59
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 1 year ago
parent
commit
f96762fd77
1 changed files with 30 additions and 11 deletions
  1. 30
    11
      downpour/resolver.py

+ 30
- 11
downpour/resolver.py View File

@@ -199,6 +199,7 @@ class Resolver:
199 199
         # The ssh key needed to login to the server.
200 200
         keypair = self.cloud.get_keypair(server.key_name)
201 201
         yield from self.keypair(keypair)
202
+
202 203
         # The security groups and other network settings for the
203 204
         # server.
204 205
         for sg in server.security_groups:
@@ -207,26 +208,45 @@ class Resolver:
207 208
         for net_name in server.networks:
208 209
             net_data = self.cloud.get_network(net_name)
209 210
             yield from self.network(net_data)
211
+        # FIXME(dhellmann): Need to handle public IPs. Use auto_ip?
212
+
210 213
         # Any volumes attached to the server.
214
+        # FIXME(dhellmann): The server needs to be stopped and the
215
+        # volumes need to be detached before this step.
211 216
         vol_names = []
212
-        for vol in server.volumes:
213
-            vol_data = self.cloud.get_volume(vol.id)
214
-            vol_names.append(vol_data.name)
215
-            yield from self.volume(vol_data, save_state)
216
-        # FIXME(dhellmann): Need to handle public IPs. Use auto_ip?
217
-        # FIXME(dhellmann): For now assume the image exists, but we may
218
-        #                   have to dump and recreate it.
219
-        # image = self.cloud.get_image(server.image.id)
220
-        # pprint.pprint(image)
217
+        # for vol in server.volumes:
218
+        #     vol_data = self.cloud.get_volume(vol.id)
219
+        #     vol_names.append(vol_data.name)
220
+        #     yield from self.volume(vol_data, save_state)
221
+
222
+        # The main portion of the server image.
221 223
         # FIXME(dhellmann): It looks like ceph-backed servers have an
222 224
         # image ID set to their volume or something? It's not a public
223 225
         # image visible through the glance API.
226
+        if save_state:
227
+            image_name = 'downpour-server-capture-{}'.format(server.id)
228
+            image = self.cloud.get_image(image_name)
229
+            if image:
230
+                LOG.info('found existing capture of server %s in %s',
231
+                         server.name, image_name)
232
+            else:
233
+                LOG.info('capturing server %s to image %s',
234
+                         server.name, image_name)
235
+                image = self.cloud.create_image_snapshot(
236
+                    name=image_name,
237
+                    server=server,
238
+                    wait=True,
239
+                )
240
+        else:
241
+            image = self.cloud.get_image(server.image.id)
242
+        yield from self.image(image)
243
+
224 244
         server_data = {
225 245
             'name': server.name,
226 246
             'state': 'present',
227 247
             # Attach to the networks by name.
228 248
             'nics': list(server.networks.keys()),
229
-            # 'image': image.name if image else server.image.id,
249
+            'image': image.name,
230 250
         }
231 251
         key_name = key_name or server.key_name
232 252
         if key_name:
@@ -237,7 +257,6 @@ class Resolver:
237 257
             'name': 'Creating server {}'.format(server.name),
238 258
             'os_server': server_data,
239 259
             'register': self._mk_var_name('server'),
240
-            # FIXME(dhellmann): ssh keypair
241 260
         }
242 261
         yield self._map_uuids('server', server.name, server.id, 'server.id')
243 262
 

Loading…
Cancel
Save