Skip to content

Instantly share code, notes, and snippets.

@WaltHP
Created April 8, 2015 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaltHP/2c24ea17559d658bf392 to your computer and use it in GitHub Desktop.
Save WaltHP/2c24ea17559d658bf392 to your computer and use it in GitHub Desktop.
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 9cf5c9d..efd3dbf 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -1034,6 +1034,7 @@ class LibvirtDriver(driver.ComputeDriver):
image_meta, bdm)
self._connect_volume(connection_info, disk_info)
conf = self._get_volume_config(connection_info, disk_info)
+ LOG.warning("CONF = %s", conf)
self._set_cache_mode(conf)
try:
@@ -1049,6 +1050,7 @@ class LibvirtDriver(driver.ComputeDriver):
encryptor = self._get_volume_encryptor(connection_info,
encryption)
encryptor.attach_volume(context, **encryption)
+ conf.source_path = ("/dev/mapper/%s" % encryptor.dev_uuid)
virt_dom.attachDeviceFlags(conf.to_xml(), flags)
except Exception as ex:
diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py
index d60c162..70cfc36 100644
--- a/nova/virt/libvirt/volume.py
+++ b/nova/virt/libvirt/volume.py
@@ -832,18 +832,20 @@ class LibvirtISCSIVolumeDriver(LibvirtBaseVolumeDriver):
def _get_host_device(self, transport_properties):
"""Find device path in devtemfs."""
+ LOG.warning("TRANSPORT %s", self._get_transport())
device = ("ip-%s-iscsi-%s-lun-%s" %
(transport_properties['target_portal'],
transport_properties['target_iqn'],
transport_properties.get('target_lun', 0)))
if self._get_transport() == "default":
- return ("/dev/disk/by-path/%s" % device)
+ path = ("/dev/disk/by-path/%s" % device)
+ return os.path.realpath(path)
else:
host_device = None
look_for_device = glob.glob('/dev/disk/by-path/*%s' % device)
if look_for_device:
host_device = look_for_device[0]
- return host_device
+ return os.path.realpath(host_device)
def _reconnect(self, iscsi_properties):
# Note: iscsiadm does not support changing iface.iscsi_ifacename
diff --git a/nova/volume/encryptors/cryptsetup.py b/nova/volume/encryptors/cryptsetup.py
index a4343a1..fd209a5 100644
--- a/nova/volume/encryptors/cryptsetup.py
+++ b/nova/volume/encryptors/cryptsetup.py
@@ -42,6 +42,9 @@ class CryptsetupEncryptor(base.VolumeEncryptor):
# the device's actual path on the compute host -- e.g., /dev/sd_
self.dev_path = os.path.realpath(self.symlink_path)
+ LOG.warning("CONN %s", connection_info)
+ self.dev_uuid = connection_info['data']['volume_id']
+
def _get_passphrase(self, key):
return ''.join(hex(x).replace('0x', '') for x in key)
@@ -65,7 +68,8 @@ class CryptsetupEncryptor(base.VolumeEncryptor):
if key_size is not None:
cmd.extend(["--key-size", key_size])
- cmd.extend([self.dev_name, self.dev_path])
+ #cmd.extend([self.dev_name, self.dev_path])
+ cmd.extend([self.dev_uuid, self.dev_path])
utils.execute(*cmd, process_input=passphrase,
check_exit_code=True, run_as_root=True)
@@ -87,13 +91,18 @@ class CryptsetupEncryptor(base.VolumeEncryptor):
# modify the original symbolic link to refer to the decrypted device
utils.execute('ln', '--symbolic', '--force',
- '/dev/mapper/%s' % self.dev_name, self.symlink_path,
+ self.symlink_path,
+ '/dev/mapper/%s' % self.dev_uuid,
run_as_root=True, check_exit_code=True)
+ output = utils.execute('ls', '-al', '/dev/mapper',
+ run_as_root=True, check_exit_code=True)
+ LOG.warning("CRAP %s", output)
+
def _close_volume(self, **kwargs):
"""Closes the device (effectively removes the dm-crypt mapping)."""
LOG.debug("closing encrypted volume %s", self.dev_path)
- utils.execute('cryptsetup', 'remove', self.dev_name,
+ utils.execute('cryptsetup', 'remove', self.dev_uuid,
run_as_root=True, check_exit_code=True)
def detach_volume(self, **kwargs):
diff --git a/nova/volume/encryptors/luks.py b/nova/volume/encryptors/luks.py
index 9ade553..4cd46bf 100644
--- a/nova/volume/encryptors/luks.py
+++ b/nova/volume/encryptors/luks.py
@@ -53,6 +53,8 @@ class LuksEncryptor(cryptsetup.CryptsetupEncryptor):
def __init__(self, connection_info, **kwargs):
super(LuksEncryptor, self).__init__(connection_info, **kwargs)
+ self.dev_uuid = connection_info['data']['volume_id']
+
def _format_volume(self, passphrase, **kwargs):
"""Creates a LUKS header on the volume.
@@ -72,6 +74,9 @@ class LuksEncryptor(cryptsetup.CryptsetupEncryptor):
if key_size is not None:
cmd.extend(["--key-size", key_size])
+ if self.dev_uuid:
+ cmd.extend(["--uuid", self.dev_uuid])
+
cmd.extend([self.dev_path])
utils.execute(*cmd, process_input=passphrase,
@@ -117,12 +122,12 @@ class LuksEncryptor(cryptsetup.CryptsetupEncryptor):
# modify the original symbolic link to refer to the decrypted device
utils.execute('ln', '--symbolic', '--force',
- '/dev/mapper/%s' % self.dev_name, self.symlink_path,
+ '/dev/mapper/%s' % self.dev_uuid, self.symlink_path,
run_as_root=True, check_exit_code=True)
def _close_volume(self, **kwargs):
"""Closes the device (effectively removes the dm-crypt mapping)."""
LOG.debug("closing encrypted volume %s", self.dev_path)
- utils.execute('cryptsetup', 'luksClose', self.dev_name,
+ utils.execute('cryptsetup', 'luksClose', self.dev_uuid,
run_as_root=True, check_exit_code=True,
attempts=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment