def create_volume(self, volume): """Creates a volume. Called on "cinder create ..." or "nova volume-create ..." :param volume: volume reference (sqlalchemy Model) """ _debug_vol_info("CREATE", volume) hostname = str(volume.host) name = volume.display_name if not name: name = volume.name mountpoint = self._get_hostname_mountpoint(hostname) location = '{}/{}.raw'.format(mountpoint, name) size = volume.size LOG.info('DO_CREATE_VOLUME %s %s' % (location, size)) VDiskController.create_volume(location = location, size = size) volume['provider_location'] = location try: ovs_disk = self._find_ovs_model_disk_by_location(location, hostname) except RuntimeError: VDiskController.delete_volume(location = location) raise ovs_disk.cinder_id = volume.id ovs_disk.name = name ovs_disk.save() return {'provider_location': volume['provider_location']}
def create_volume(self, volume): """Creates a volume. Called on "cinder create ..." or "nova volume-create ..." :param volume: volume reference (sqlalchemy Model) """ _debug_vol_info("CREATE", volume) hostname = str(volume.host) name = volume.display_name if not name: name = volume.name mountpoint = self._get_hostname_mountpoint(hostname) location = '{}/{}.raw'.format(mountpoint, name) size = volume.size LOG.info('DO_CREATE_VOLUME %s %s' % (location, size)) VDiskController.create_volume(location=location, size=size) volume['provider_location'] = location try: ovs_disk = self._find_ovs_model_disk_by_location( location, hostname) except RuntimeError: VDiskController.delete_volume(location=location) raise ovs_disk.cinder_id = volume.id ovs_disk.name = name ovs_disk.save() return {'provider_location': volume['provider_location']}
def copy_image_to_volume(self, context, volume, image_service, image_id): """Copy image to volume Called on "nova volume-create --image-id ..." or "cinder create --image-id" Downloads image from glance server into local .raw :param volume: volume reference (sqlalchemy Model) """ _debug_vol_info("CP_IMG_TO_VOL", volume) LOG.info("CP_IMG_TO_VOL %s %s" % (image_service, image_id)) name = volume.display_name if not name: name = volume.name volume.display_name = volume.name # downloading from an existing image destination_path = volume.provider_location if destination_path: try: LOG.info("CP_IMG_TO_VOL Deleting existing empty raw file %s " % destination_path) VDiskController.delete_volume(location=destination_path) LOG.info("CP_IMG_TO_VOL Downloading image to %s" % destination_path) image_utils.fetch_to_raw(context, image_service, image_id, destination_path, "1M", size=volume["size"]) LOG.info("CP_IMG_TO_VOL Resizing volume to size %s" % volume["size"]) self.extend_volume(volume=volume, size_gb=volume["size"]) except Exception as ex: LOG.error("CP_IMG_TO_VOL Internal error %s " % unicode(ex)) self.delete_volume(volume) raise ovs_disk = self._find_ovs_model_disk_by_location(volume.provider_location, str(volume.host)) ovs_disk.name = name ovs_disk.save()
def delete_volume(self, volume): """Deletes a logical volume. Called on "cinder delete ... " :param volume: volume reference (sqlalchemy Model) """ _debug_vol_info("DELETE", volume) location = volume.provider_location if location is not None: LOG.info('DO_DELETE_VOLUME %s' % (location)) VDiskController.delete_volume(location = location)
def delete_volume(self, volume): """Deletes a logical volume. Called on "cinder delete ... " :param volume: volume reference (sqlalchemy Model) """ _debug_vol_info("DELETE", volume) location = volume.provider_location if location is not None: LOG.info('DO_DELETE_VOLUME %s' % (location)) VDiskController.delete_volume(location=location)
def copy_image_to_volume(self, context, volume, image_service, image_id): """Copy image to volume Called on "nova volume-create --image-id ..." or "cinder create --image-id" Downloads image from glance server into local .raw :param volume: volume reference (sqlalchemy Model) """ _debug_vol_info("CP_IMG_TO_VOL", volume) LOG.info("CP_IMG_TO_VOL %s %s" % (image_service, image_id)) name = volume.display_name if not name: name = volume.name volume.display_name = volume.name # downloading from an existing image destination_path = volume.provider_location if destination_path: try: LOG.info('CP_IMG_TO_VOL Deleting existing empty raw file %s ' % destination_path) VDiskController.delete_volume(location=destination_path) LOG.info('CP_IMG_TO_VOL Downloading image to %s' % destination_path) image_utils.fetch_to_raw(context, image_service, image_id, destination_path, '1M', size=volume['size']) LOG.info('CP_IMG_TO_VOL Resizing volume to size %s' % volume['size']) self.extend_volume(volume=volume, size_gb=volume['size']) except Exception as ex: LOG.error('CP_IMG_TO_VOL Internal error %s ' % unicode(ex)) self.delete_volume(volume) raise ovs_disk = self._find_ovs_model_disk_by_location( volume.provider_location, str(volume.host)) ovs_disk.name = name ovs_disk.save()