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}".format( host_device=device_path) LOG.error(msg) 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 check_path_and_rescan(sudo_password): # 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), sudo_password=sudo_password) 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), sudo_password=sudo_password)
def _check_local_sudo_password_set(self): current_user = getpass.getuser() if current_user != 'root' and \ self.cfg.migrate.local_sudo_password is None: try: local.sudo('ls') except local.LocalExecutionFailed: msg = ("CloudFerry is running as '{user}' user, but " "passwordless sudo does not seem to be configured on " "current host. Please either specify password in " "`local_sudo_password` config option, or run " "CloudFerry as root user.").format(user=current_user) LOG.error(msg) raise exception.AbortMigrationError(msg)
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 flush_device_io(device): local.sudo('blockdev --flushbufs {device}'.format(device=device))