def handle_update(self, json_snippet, tmpl_diff, prop_diff): prg_attach = None prg_detach = None if prop_diff: # Even though some combinations of changed properties # could be updated in UpdateReplace manner, # we still first detach the old resource so that # self.resource_id is not replaced prematurely volume_id = self.properties[self.VOLUME_ID] server_id = self._stored_properties_data.get(self.INSTANCE_ID) self.client_plugin('nova').detach_volume(server_id, self.resource_id) prg_detach = heat_cinder.VolumeDetachProgress( server_id, volume_id, self.resource_id) prg_detach.called = True if self.VOLUME_ID in prop_diff: volume_id = prop_diff.get(self.VOLUME_ID) device = self.properties[self.DEVICE] if self.DEVICE in prop_diff: device = prop_diff.get(self.DEVICE) if self.INSTANCE_ID in prop_diff: server_id = prop_diff.get(self.INSTANCE_ID) prg_attach = heat_cinder.VolumeAttachProgress( server_id, volume_id, device) return prg_detach, prg_attach
def handle_delete(self): server_id = self.properties[self.INSTANCE_ID] vol_id = self.properties[self.VOLUME_ID] self.client_plugin('nova').detach_volume(server_id, self.resource_id) prg = heat_cinder.VolumeDetachProgress(server_id, vol_id, self.resource_id) prg.called = True return prg
def handle_update(self, json_snippet, tmpl_diff, prop_diff): vol = None cinder = self.client() prg_resize = None prg_attach = None prg_detach = None # update the name and description for cinder volume if self.NAME in prop_diff or self.DESCRIPTION in prop_diff: vol = cinder.volumes.get(self.resource_id) update_name = (prop_diff.get(self.NAME) or self.properties[self.NAME]) update_description = (prop_diff.get(self.DESCRIPTION) or self.properties[self.DESCRIPTION]) kwargs = self._fetch_name_and_description( cinder.volume_api_version, update_name, update_description) cinder.volumes.update(vol, **kwargs) # update the metadata for cinder volume if self.METADATA in prop_diff: if not vol: vol = cinder.volumes.get(self.resource_id) metadata = prop_diff.get(self.METADATA) cinder.volumes.update_all_metadata(vol, metadata) # retype if self.VOLUME_TYPE in prop_diff: if cinder.volume_api_version == 1: LOG.info( _LI('Volume type update not supported ' 'by Cinder API V1.')) raise exception.NotSupported( feature=_('Using Cinder API V1, volume_type update')) else: if not vol: vol = cinder.volumes.get(self.resource_id) new_vol_type = prop_diff.get(self.VOLUME_TYPE) cinder.volumes.retype(vol, new_vol_type, 'never') # update read_only access mode if self.READ_ONLY in prop_diff: flag = prop_diff.get(self.READ_ONLY) cinder.volumes.update_readonly_flag(self.resource_id, flag) # extend volume size if self.SIZE in prop_diff: if not vol: vol = cinder.volumes.get(self.resource_id) new_size = prop_diff[self.SIZE] if new_size < vol.size: raise exception.NotSupported(feature=_("Shrinking volume")) elif new_size > vol.size: prg_resize = heat_cinder.VolumeResizeProgress(size=new_size) if vol.attachments: # NOTE(pshchelo): # this relies on current behavior of cinder attachments, # i.e. volume attachments is a list with len<=1, # so the volume can be attached only to single instance, # and id of attachment is the same as id of the volume # it describes, so detach/attach the same volume # will not change volume attachment id. server_id = vol.attachments[0]['server_id'] device = vol.attachments[0]['device'] attachment_id = vol.attachments[0]['id'] prg_detach = heat_cinder.VolumeDetachProgress( server_id, vol.id, attachment_id) prg_attach = heat_cinder.VolumeAttachProgress( server_id, vol.id, device) return prg_detach, prg_resize, prg_attach