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 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 get_sessions(self): password = self.sudo_password _, out = local.sudo_ignoring_errors('iscsiadm -m session', sudo_password=password) sessions = [VolumeParams.from_iscsiadm_string(l) for l in out.splitlines()] return [s for s in sessions if s is not None]
def get_sessions(self): password = self.sudo_password _, out = local.sudo_ignoring_errors('iscsiadm -m session', sudo_password=password) sessions = [ VolumeParams.from_iscsiadm_string(l) for l in out.splitlines() ] return [s for s in sessions if s is not None]