# # Copyright 2016 Cray Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from oslo_config import cfg from oslo_log import log as logging from bareon.drivers.deploy.generic import GenericDeployDriver from bareon import errors from bareon.utils import artifact as au from bareon.utils import fs as fu from bareon.utils import utils CONF = cfg.CONF LOG = logging.getLogger(__name__) class Swift(GenericDeployDriver): def do_copyimage(self, os_id): LOG.debug('--- Copying images (do_copyimage) ---') for image in self.driver.image_scheme.get_os_images(os_id): LOG.debug('Processing image: %s' % image.uri) processing = au.Chain() LOG.debug('Appending uri processor: %s' % image.uri) processing.append(image.uri) if image.uri.startswith('http://'): LOG.debug('Appending HTTP processor') processing.append(au.HttpUrl) elif image.uri.startswith('file://'): LOG.debug('Appending FILE processor') processing.append(au.LocalFile) if image.container == 'gzip': LOG.debug('Appending GZIP processor') processing.append(au.GunzipStream) LOG.debug('Appending TARGET processor: %s' % image.target_device) target = self.driver.partition_scheme.fs_by_mount( image.target_device, os_id=os_id).device processing.append(target) LOG.debug('Launching image processing chain') processing.process() if image.size and image.md5: LOG.debug('Trying to compare image checksum') actual_md5 = utils.calculate_md5(image.target_device, image.size) if actual_md5 == image.md5: LOG.debug('Checksum matches successfully: md5=%s' % actual_md5) else: raise errors.ImageChecksumMismatchError( 'Actual checksum %s mismatches with expected %s for ' 'file %s' % (actual_md5, image.md5, image.target_device)) else: LOG.debug('Skipping image checksum comparing. ' 'Ether size or hash have been missed') LOG.debug('Extending image file systems') if image.format in ('ext2', 'ext3', 'ext4', 'xfs'): LOG.debug('Extending %s %s' % (image.format, image.target_device)) fu.extend_fs(image.format, image.target_device) fu.change_uuid(target)