예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
 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))
예제 #4
0
 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)
예제 #5
0
 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 _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)
예제 #7
0
    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()]
예제 #8
0
    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()
            ]
예제 #9
0
def rescan_iscsi():
    local.sudo('iscsiadm -m node --rescan')
    local.sudo('iscsiadm -m session --rescan')
예제 #10
0
def flush_device_io(device):
    local.sudo('blockdev --flushbufs {device}'.format(device=device))
예제 #11
0
def rescan_iscsi():
    local.sudo('iscsiadm -m node --rescan')
    local.sudo('iscsiadm -m session --rescan')
예제 #12
0
def flush_device_io(device):
    local.sudo('blockdev --flushbufs {device}'.format(device=device))