Browse Source

add support for available volumes

Create an image from the volume and download the image.

Change-Id: Idc1c44c74f43f8d9b259e9da4895c94f25464973
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 1 year ago
parent
commit
817ed2be06
1 changed files with 26 additions and 13 deletions
  1. 26
    13
      downpour/resolver.py

+ 26
- 13
downpour/resolver.py View File

@@ -13,6 +13,9 @@
13 13
 # under the License.
14 14
 
15 15
 import itertools
16
+import logging
17
+
18
+LOG = logging.getLogger(__name__)
16 19
 
17 20
 
18 21
 class Resolver:
@@ -122,22 +125,32 @@ class Resolver:
122 125
         if ('volume', volume.name) in self._memo:
123 126
             return
124 127
         self._memo.add(('volume', volume.name))
125
-        # FIXME(dhellmann): For now this only creates new empty
126
-        # volumes, and doesn't handle cases like booting from a volume
127
-        # or creating a volume from an image.
128
-        #
129
-        # FIXME(dhellmann): Need to snapshot the volume and then
130
-        # download the results.
131 128
         if save_state:
132
-            self._downloader.add_volume(volume)
129
+            image_name = 'volume-capture-{}'.format(volume.id)
130
+            image_info = self.cloud.get_image(image_name)
131
+            if image_info:
132
+                LOG.info('found existing capture of volume %s in %s',
133
+                         volume.name, image_name)
134
+            else:
135
+                LOG.info('creating image from volume %s as %s',
136
+                         volume.name, image_name)
137
+                image_info = self.cloud.create_image(
138
+                    name=image_name,
139
+                    volume=volume.id,
140
+                    wait=True,
141
+                )
142
+            yield from self.image(image_info)
143
+        os_volume = {
144
+            'display_name': volume.display_name,
145
+            'display_description': volume.display_description,
146
+            'size': volume.size,
147
+            'state': 'present',
148
+        }
149
+        if save_state:
150
+            os_volume['image'] = image_name
133 151
         yield {
134 152
             'name': 'Create volume {}'.format(volume.name),
135
-            'os_volume': {
136
-                'display_name': volume.display_name,
137
-                'display_description': volume.display_description,
138
-                'size': volume.size,
139
-                'state': 'present',
140
-            },
153
+            'os_volume': os_volume,
141 154
             'register': self._mk_var_name('vol'),
142 155
         }
143 156
         yield self._map_uuids('volume', volume.name, volume.id, 'volume.id')

Loading…
Cancel
Save