def __init__(self, connection): super(LibvirtHGSTVolumeDriver, self).__init__(connection, is_block_dev=True) self.connector = connector.InitiatorConnector.factory( 'HGST', utils._get_root_helper(), device_scan_attempts=CONF.libvirt.num_iscsi_scan_tries)
def _snapshot_ve(self, context, instance, image_id, update_task_state, ve): def upload(context, image_service, image_id, metadata, f): LOG.info("Start uploading image %s ..." % image_id) image_service.update(context, image_id, metadata, f) LOG.info("Image %s uploading complete." % image_id) _image_service = glance.get_remote_image_service(context, image_id) snapshot_image_service, snapshot_image_id = _image_service snapshot = snapshot_image_service.show(context, snapshot_image_id) disk_format = CONF.pcs_snapshot_disk_format metadata = {'is_public': False, 'status': 'active', 'name': snapshot['name'], 'container_format': 'bare', 'disk_format': disk_format, } props = {} metadata['properties'] = props if ve.get_vm_type() == pc.PVT_VM: props['vm_mode'] = 'hvm' else: props['vm_mode'] = 'exe' update_task_state(task_state=task_states.IMAGE_UPLOADING, expected_state=task_states.IMAGE_PENDING_UPLOAD) hdd = pcsutils.get_boot_disk(ve) hdd_path = hdd.get_image_path() props['pcs_ostemplate'] = ve.get_os_template() if disk_format == 'ploop': xml_path = os.path.join(hdd_path, "DiskDescriptor.xml") cmd = ['ploop', 'snapshot-list', '-H', '-o', 'fname', xml_path] out, err = utils.execute(*cmd, run_as_root=True) image_path = out.strip() with open(xml_path) as f: props['pcs_disk_descriptor'] = f.read().replace('\n', '') with open(image_path) as f: upload(context, snapshot_image_service, image_id, metadata, f) elif disk_format == 'cploop': uploader = pcsutils.CPloopUploader(hdd_path) f = uploader.start() try: upload(context, snapshot_image_service, image_id, metadata, f) finally: uploader.wait() else: dst = tempfile.mktemp(dir=os.path.dirname(hdd_path)) LOG.info("Convert image %s to %s format ..." % (image_id, disk_format)) pcsutils.convert_image(hdd_path, dst, disk_format, root_helper=utils._get_root_helper()) with open(dst) as f: upload(context, snapshot_image_service, image_id, metadata, f) os.unlink(dst)
def __init__(self, connection): super(LibvirtAOEVolumeDriver, self).__init__(connection, is_block_dev=True) # Call the factory here so we can support # more than x86 architectures. self.connector = connector.InitiatorConnector.factory( 'AOE', utils._get_root_helper(), device_scan_attempts=CONF.libvirt.num_aoe_discover_tries)
def __init__(self, connection): super(LibvirtFibreChannelVolumeDriver, self).__init__(connection, is_block_dev=False) # Call the factory here so we can support # more than x86 architectures. self.connector = connector.InitiatorConnector.factory( 'FIBRE_CHANNEL', utils._get_root_helper(), use_multipath=CONF.libvirt.iscsi_use_multipath, device_scan_attempts=CONF.libvirt.num_iscsi_scan_tries)
def __init__(self, connection): super(LibvirtISERVolumeDriver, self).__init__(connection) # Call the factory here so we can support # more than x86 architectures. self.connector = connector.InitiatorConnector.factory( 'ISER', utils._get_root_helper(), use_multipath=CONF.libvirt.iser_use_multipath, device_scan_attempts=CONF.libvirt.num_iser_scan_tries, transport=self._get_transport())
def get_iscsi_initiator(execute=None): """Get iscsi initiator name for this machine.""" root_helper = utils._get_root_helper() # so we can mock out the execute itself # in unit tests. if not execute: execute = putils.execute iscsi = connector.ISCSIConnector(root_helper=root_helper, execute=execute) return iscsi.get_initiator()
def put_image(self, context, image_ref, image_meta, dst): utils.execute('mkdir', dst, run_as_root=True) f = self._open_cached_file(context, image_ref, image_meta, dst) try: LOG.info("Unpacking image %s to %s" % (self._get_cached_file(image_meta['id']), dst)) pcsutils.uncompress_ploop(None, dst, src_file=f, root_helper=utils._get_root_helper()) finally: f.close()
def _inject_files(self, sdk_ve, boot_hdd, instance, network_info=None, files=None, admin_pass=None): disk_path = boot_hdd.get_image_path() target_partition = CONF.pcs_inject_partition if target_partition == 0: target_partition = None key = str(instance['key_data']) net = netutils.get_injected_network_template(network_info) metadata = instance.get('metadata') if any((key, net, metadata, admin_pass, files)): # If we're not using config_drive, inject into root fs LOG.info('Injecting files') try: img_id = instance['image_ref'] for inj, val in [('key', key), ('net', net), ('metadata', metadata), ('admin_pass', admin_pass), ('files', files)]: if val: LOG.info(_('Injecting %(inj)s into image ' '%(img_id)s'), {'inj': inj, 'img_id': img_id}, instance=instance) with pcsutils.PloopMount(disk_path, chown=True, root_helper=utils._get_root_helper()) as dev: disk.inject_data(dev, key, net, metadata, admin_pass, files, partition=target_partition, use_cow=False, mandatory=('files',)) except Exception as e: with excutils.save_and_reraise_exception(): LOG.error(_('Error injecting data into image ' '%(img_id)s (%(e)s)'), {'img_id': img_id, 'e': e}, instance=instance)
def test_use_sudo(self): self.flags(disable_rootwrap=True, group='workarounds') cmd = utils._get_root_helper() self.assertEqual('sudo', cmd)
def test_use_rootwrap(self): self.flags(disable_rootwrap=False, group='workarounds') self.flags(rootwrap_config='foo') cmd = utils._get_root_helper() self.assertEqual('sudo nova-rootwrap foo', cmd)
def test_use_rootwrap(self): self.flags(disable_rootwrap=False, group="workarounds") self.flags(rootwrap_config="foo") cmd = utils._get_root_helper() self.assertEqual("sudo nova-rootwrap foo", cmd)
def __init__(self, connection): super(LibvirtScaleIOVolumeDriver, self).__init__(connection, is_block_dev=False) self.connector = connector.InitiatorConnector.factory( 'SCALEIO', utils._get_root_helper(), device_scan_attempts=CONF.libvirt.num_iscsi_scan_tries)