def connect_volume(self, target_portal, target_iqn, target_lun): """:raises: CannotConnectISCSIVolume if volume is not available or cannot be connected""" connect_cmd = ('iscsiadm ' '-m node ' '-T {target_iqn} ' '-p {target_portal}').format( target_iqn=target_iqn, target_portal=target_portal) password = self.sudo_password local.sudo_ignoring_errors(connect_cmd, sudo_password=password) sessions = self.get_sessions() if len(sessions) == 0 or not any( (s.target_portal == target_portal for s in sessions)): try: local.sudo(connect_cmd + ' --login', sudo_password=password) finally: update = ' --op update -n node.startup -v automatic' local.sudo_ignoring_errors(connect_cmd + update) device_path = get_device_path(target_portal, target_iqn, target_lun) if not self._path_exists(device_path, target_portal, target_iqn): msg = "iSCSI volume not found at {host_device}".format( host_device=device_path) LOG.error(msg) raise CannotConnectISCSIVolume(msg) return device_path
def connect_volume(self, target_portal, target_iqn, target_lun): """:raises: CannotConnectISCSIVolume if volume is not available or cannot be connected""" connect_cmd = ('iscsiadm ' '-m node ' '-T {target_iqn} ' '-p {target_portal}').format( target_iqn=target_iqn, target_portal=target_portal) password = self.sudo_password local.sudo_ignoring_errors(connect_cmd, sudo_password=password) sessions = self.get_sessions() if len(sessions) == 0 or not any((s.target_portal == target_portal for s in sessions)): try: local.sudo(connect_cmd + ' --login', sudo_password=password) finally: update = ' --op update -n node.startup -v automatic' local.sudo_ignoring_errors(connect_cmd + update) device_path = get_device_path(target_portal, target_iqn, target_lun) if not self._path_exists(device_path, target_portal, target_iqn): msg = "iSCSI volume not found at {host_device}" LOG.error(msg.format(host_device=device_path)) raise CannotConnectISCSIVolume(msg) return device_path
def check_path_and_rescan(): # The rescan isn't documented as being necessary(?), but it helps try: rescan = "iscsiadm -m node -T {iqn} -p {portal} --rescan" local.sudo(rescan.format(iqn=target_iqn, portal=target_portal)) except local.LocalExecutionFailed as e: LOG.debug("Rescan failed with %d: %s", e.code, e.message) return local.sudo("test -e {path}".format(path=path))
def discover(self, portal): discover = 'iscsiadm -m discovery -t sendtargets -p {portal}' discovered = local.sudo( discover.format(portal=portal), sudo_password=self.sudo_password) if discovered: return [VolumeParams.from_iscsiadm_string(s) for s in discovered.splitlines()]
def discover(self, portal): discover = 'iscsiadm -m discovery -t sendtargets -p {portal}' discovered = local.sudo(discover.format(portal=portal), sudo_password=self.sudo_password) if discovered: return [ VolumeParams.from_iscsiadm_string(s) for s in discovered.splitlines() ]
def rescan_iscsi(): local.sudo('iscsiadm -m node --rescan') local.sudo('iscsiadm -m session --rescan')
def remove_iscsi_device(dev_name): path = "/sys/block/%s/device/delete" % dev_name.replace("/dev/", "") if os.path.exists(path): flush_device_io(dev_name) local.sudo("echo 1 > {path}".format(path=path))
def flush_device_io(device): local.sudo('blockdev --flushbufs {device}'.format(device=device))