コード例 #1
0
    def comm_delete_lun_core(self, command, hostgroups, lun):
        unit = self.unit_name

        no_lun_cnt = 0
        deleted_hostgroups = []
        for hostgroup in hostgroups:
            LOG.debug('comm_delete_lun: hostgroup is %s' % hostgroup)
            port = hostgroup['port']
            gid = hostgroup['gid']
            ctl_no = port[0]
            port_no = port[1]

            is_deleted = False
            for deleted in deleted_hostgroups:
                if port == deleted['port'] and gid == deleted['gid']:
                    is_deleted = True
            if is_deleted:
                continue
            ret, stdout, stderr = self.exec_hsnm(command,
                                                 '-unit %s -refer' % unit)
            if ret:
                msg = basic_lib.output_err(600,
                                           cmd=command,
                                           ret=ret,
                                           out=stdout,
                                           err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

            lines = stdout.splitlines()
            for line in lines[2:]:
                line = shlex.split(line)
                if not line:
                    continue
                if (line[0] == port and int(line[1][0:3]) == gid
                        and int(line[3]) == lun):
                    hlu = int(line[2])
                    break
            else:
                no_lun_cnt += 1
                if no_lun_cnt == len(hostgroups):
                    raise exception.HBSDNotFound
                else:
                    continue

            opt = '-unit %s -rm %s %s %d %d %d' % (unit, ctl_no, port_no, gid,
                                                   hlu, lun)
            ret, stdout, stderr = self.exec_hsnm(command, opt)
            if ret:
                msg = basic_lib.output_err(600,
                                           cmd=command,
                                           ret=ret,
                                           out=stdout,
                                           err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

            deleted_hostgroups.append({'port': port, 'gid': gid})
            LOG.debug('comm_delete_lun is over (%d)' % lun)
コード例 #2
0
 def add_used_hlun(self, command, port, gid, used_list, ldev):
     unit = self.unit_name
     ret, stdout, stderr = self.exec_hsnm(command, '-unit %s -refer' % unit)
     if ret:
         msg = basic_lib.output_err(600,
                                    cmd=command,
                                    ret=ret,
                                    out=stdout,
                                    err=stderr)
         raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
     lines = stdout.splitlines()
     for line in lines[2:]:
         line = shlex.split(line)
         if not line:
             continue
         if line[0] == port and int(line[1][0:3]) == gid:
             if int(line[2]) not in used_list:
                 used_list.append(int(line[2]))
             if int(line[3]) == ldev:
                 hlu = int(line[2])
                 LOG.warning(
                     _LW('ldev(%(ldev)d) is already mapped '
                         '(hlun: %(hlu)d)') % {
                             'ldev': ldev,
                             'hlu': hlu
                         })
                 return hlu
     return None
コード例 #3
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
    def get_unused_ldev(self, ldev_range):
        start = ldev_range[0]
        end = ldev_range[1]
        unit = self.unit_name

        ret, stdout, stderr = self.exec_hsnm('auluref', '-unit %s' % unit)
        if ret:
            msg = basic_lib.output_err(
                600, cmd='auluref', ret=ret, out=stdout, err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
        free_ldev = start
        lines = stdout.splitlines()
        found = False
        for line in lines[2:]:
            line = shlex.split(line)
            if not line:
                continue
            ldev_num = int(line[0])
            if free_ldev > ldev_num:
                continue
            if free_ldev == ldev_num:
                free_ldev += 1
            else:
                found = True
                break
            if free_ldev > end:
                break
        else:
            found = True

        if not found:
            msg = basic_lib.output_err(648, resource='LDEV')
            raise exception.HBSDError(message=msg)

        return free_ldev
コード例 #4
0
    def comm_set_target_wwns(self, target_ports):
        unit = self.unit_name
        ret, stdout, stderr = self.exec_hsnm('aufibre1',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='aufibre1',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        lines = stdout.splitlines()
        target_wwns = {}
        for line in lines[3:]:
            if re.match('Transfer', line):
                break

            line = shlex.split(line)
            if len(line) < 4:
                continue

            port = '%s%s' % (line[0], line[1])
            if target_ports:
                if port in target_ports:
                    target_wwns[port] = line[3]
            else:
                target_wwns[port] = line[3]

        LOG.debug('target wwns: %s' % target_wwns)
        return target_wwns
コード例 #5
0
    def comm_delete_ldev(self, ldev, is_vvol):
        unit = self.unit_name

        if is_vvol:
            command = 'aureplicationvvol'
            opt = '-unit %s -rm -lu %d' % (unit, ldev)
        else:
            command = 'auludel'
            opt = '-unit %s -lu %d -f' % (unit, ldev)

        ret, stdout, stderr = self.exec_hsnm(command,
                                             opt,
                                             timeout=30,
                                             interval=3)
        if ret:
            if (re.search('DMEC002048', stderr)
                    or re.search('DMED090026', stderr)):
                raise exception.HBSDNotFound
            msg = basic_lib.output_err(600,
                                       cmd=command,
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
        return ret
コード例 #6
0
    def comm_get_iscsi_ip(self, port):
        unit = self.unit_name
        ret, stdout, stderr = self.exec_hsnm('auiscsi',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='auiscsi',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        lines = stdout.splitlines()
        is_target_port = False
        for line in lines:
            line_array = shlex.split(line)
            if not line_array:
                continue
            if line_array[0] == 'Port' and line_array[1] != 'Number':
                if line_array[1] == port:
                    is_target_port = True
                else:
                    is_target_port = False
                continue
            if is_target_port and re.search('IPv4 Address', line):
                ip_addr = shlex.split(line)[3]
                break
            if is_target_port and re.search('Port Number', line):
                ip_port = shlex.split(line)[3]
        else:
            msg = basic_lib.output_err(651)
            raise exception.HBSDError(message=msg)

        return ip_addr, ip_port
コード例 #7
0
 def get_hgname_gid(self, port, host_grp_name):
     unit = self.unit_name
     ret, stdout, stderr = self.exec_hsnm('auhgdef',
                                          '-unit %s -refer' % unit)
     if ret:
         msg = basic_lib.output_err(600,
                                    cmd='auhgdef',
                                    ret=ret,
                                    out=stdout,
                                    err=stderr)
         raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
     lines = stdout.splitlines()
     is_target_port = False
     for line in lines:
         line = shlex.split(line)
         if not line:
             continue
         if line[0] == 'Port' and line[1] == port:
             is_target_port = True
             continue
         if is_target_port:
             if line[0] == 'Port':
                 break
             if not line[0].isdigit():
                 continue
             gid = int(line[0])
             if line[1] == host_grp_name:
                 return gid
     return None
コード例 #8
0
    def comm_get_hostgroup_info(self, hgs, wwns, target_ports, login=True):
        unit = self.unit_name
        ret, stdout, stderr = self.exec_hsnm('auhgwwn',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='auhgwwn',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        security_ports = []
        patterns = []
        for wwn in wwns:
            pt = re.compile(wwn, re.IGNORECASE)
            patterns.append(pt)

        lines = stdout.splitlines()
        buf = {}
        _buffer = []
        port = None
        security = None
        for line in lines:
            if re.match('Port', line):
                port = shlex.split(line)[1]
                if target_ports and port not in target_ports:
                    port = None
                else:
                    security = True if shlex.split(line)[5] == 'ON' else False
                    buf[port] = {
                        'detected': [],
                        'assigned': [],
                        'assignable': []
                    }
                    if security:
                        security_ports.append(port)
                continue
            if port and security:
                if re.search('Detected WWN', line):
                    _buffer = buf[port]['detected']
                    continue
                elif re.search('Assigned WWN', line):
                    _buffer = buf[port]['assigned']
                    continue
                elif re.search('Assignable WWN', line):
                    _buffer = buf[port]['assignable']
                    continue
                _buffer.append(line)

        hostgroups = []
        for port in buf.keys():
            self.get_hostgroup_from_wwns(hostgroups, port, patterns, buf,
                                         login)

        for hostgroup in hostgroups:
            hgs.append(hostgroup)

        return security_ports
コード例 #9
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
 def get_comm_version(self):
     ret, stdout, stderr = self.exec_hsnm('auman', '-help')
     m = re.search('Version (\d+).(\d+)', stdout)
     if not m:
         msg = basic_lib.output_err(
             600, cmd='auman', ret=ret, out=stdout, err=stderr)
         raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
     return '%s.%s' % (m.group(1), m.group(2))
コード例 #10
0
    def set_chap_authention(self, port, gid):
        ctl_no = port[0]
        port_no = port[1]
        unit = self.unit_name
        auth_username = self.conf.hitachi_auth_user
        auth_password = self.conf.hitachi_auth_password
        add_chap_user = self.conf.hitachi_add_chap_user
        assign_flag = True
        added_flag = False
        opt = '-unit %s -refer %s %s -user %s' % (unit, ctl_no, port_no,
                                                  auth_username)
        ret, stdout, stderr = self.exec_hsnm('auchapuser', opt, noretry=True)

        if ret:
            if not add_chap_user:
                msg = basic_lib.output_err(643, user=auth_username)
                raise exception.HBSDError(message=msg)

            root_helper = utils.get_root_helper()
            cmd = ('%s env %s auchapuser -unit %s -add %s %s '
                   '-tno %d -user %s' % (root_helper, SNM2_ENV, unit, ctl_no,
                                         port_no, gid, auth_username))

            LOG.debug('Add CHAP user')
            loop = loopingcall.FixedIntervalLoopingCall(
                self._wait_for_add_chap_user, cmd, auth_username,
                auth_password, time.time())

            added_flag = loop.start(interval=EXEC_INTERVAL).wait()

        else:
            lines = stdout.splitlines()[4:]
            for line in lines:
                if int(shlex.split(line)[0][0:3]) == gid:
                    assign_flag = False
                    break

        if assign_flag:
            opt = '-unit %s -assign %s %s -tno %d -user %s' % (
                unit, ctl_no, port_no, gid, auth_username)
            ret, stdout, stderr = self.exec_hsnm('auchapuser', opt)
            if ret:
                if added_flag:
                    _ret, _stdout, _stderr = self.delete_chap_user(port)
                    if _ret:
                        msg = basic_lib.set_msg(303, user=auth_username)
                        LOG.warning(msg)

                msg = basic_lib.output_err(600,
                                           cmd='auchapuser',
                                           ret=ret,
                                           out=stdout,
                                           err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        return added_flag
コード例 #11
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
    def comm_extend_ldev(self, ldev, old_size, new_size):
        unit = self.unit_name
        command = 'auluchgsize'
        options = '-unit %s -lu %d -size %dg' % (unit, ldev, new_size)

        ret, stdout, stderr = self.exec_hsnm(command, options)
        if ret:
            msg = basic_lib.output_err(
                600, cmd=command, ret=ret, out=stdout, err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
コード例 #12
0
    def get_gid_from_targetiqn(self, target_iqn, target_alias, port):
        unit = self.unit_name
        ret, stdout, stderr = self.exec_hsnm('autargetdef',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='autargetdef',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        gid = None
        tmp_port = None
        found_alias_full = False
        found_alias_part = False
        lines = stdout.splitlines()
        for line in lines:
            line = shlex.split(line)
            if not line:
                continue

            if line[0] == "Port":
                tmp_port = line[1]
                continue

            if port != tmp_port:
                continue

            if line[0][0:3].isdigit():
                tmp_gid = int(line[0][0:3])
                if re.match(basic_lib.NAME_PREFIX, line[0][4:]):
                    found_alias_part = True
                if line[0][4:] == target_alias:
                    found_alias_full = True
                continue

            if line[0] == "iSCSI":
                if line[3] == target_iqn:
                    gid = tmp_gid
                    break
                else:
                    found_alias_part = False

        if found_alias_full and gid is None:
            msg = basic_lib.output_err(641)
            raise exception.HBSDError(message=msg)

        # When 'gid' is 0, it should be true.
        # So, it cannot remove 'is not None'.
        if not found_alias_part and gid is not None:
            msg = basic_lib.output_err(641)
            raise exception.HBSDError(message=msg)

        return gid
コード例 #13
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
 def comm_del_hostgrp(self, port, gid, host_grp_name):
     unit = self.unit_name
     ctl_no = port[0]
     port_no = port[1]
     opt = '-unit %s -rm %s %s -gname %s' % (unit, ctl_no, port_no,
                                             host_grp_name)
     ret, stdout, stderr = self.exec_hsnm('auhgdef', opt)
     if ret:
         msg = basic_lib.output_err(
             600, cmd='auhgdef', ret=ret, out=stdout, err=stderr)
         raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
コード例 #14
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
 def comm_set_hostgrp_reportportal(self, port, target_alias):
     unit = self.unit_name
     ctl_no = port[0]
     port_no = port[1]
     opt = '-unit %s -set %s %s -talias %s' % (unit, ctl_no, port_no,
                                               target_alias)
     opt = '%s -ReportFullPortalList enable' % opt
     ret, stdout, stderr = self.exec_hsnm('autargetopt', opt)
     if ret:
         msg = basic_lib.output_err(
             600, cmd='autargetopt', ret=ret, out=stdout, err=stderr)
         raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
コード例 #15
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
 def comm_add_initiator(self, port, gid, host_iqn):
     unit = self.unit_name
     ctl_no = port[0]
     port_no = port[1]
     opt = '-unit %s -add %s %s -tno %d -iname %s' % (unit, ctl_no,
                                                      port_no, gid,
                                                      host_iqn)
     ret, stdout, stderr = self.exec_hsnm('autargetini', opt)
     if ret:
         msg = basic_lib.output_err(
             600, cmd='autargetini', ret=ret, out=stdout, err=stderr)
         raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
コード例 #16
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
 def pairoperate(self, opr, pvol, svol, is_vvol, args=None):
     unit = self.unit_name
     method = '-ss' if is_vvol else '-si'
     opt = '-unit %s -%s %s -pvol %d -svol %d' % (unit, opr, method,
                                                  pvol, svol)
     if args:
         opt = '%s %s' % (opt, args)
     ret, stdout, stderr = self.exec_hsnm('aureplicationlocal', opt)
     if ret:
         opt = '%s %s' % ('aureplicationlocal', opt)
         msg = basic_lib.output_err(
             600, cmd=opt, ret=ret, out=stdout, err=stderr)
         raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
コード例 #17
0
    def get_unused_gid(self, group_range, port):
        start = group_range[0]
        end = group_range[1]
        unit = self.unit_name

        ret, stdout, stderr = self.exec_hsnm('auhgdef',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='auhgdef',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        lines = stdout.splitlines()
        is_target_port = False
        free_gid = start
        found = False
        for line in lines:
            line = shlex.split(line)
            if not line:
                continue
            if line[0] == 'Port' and line[1] == port:
                is_target_port = True
                continue
            if is_target_port:
                if line[0] == 'Port':
                    found = True
                    break
                if not line[0].isdigit():
                    continue

                gid = int(line[0])
                if free_gid > gid:
                    continue
                if free_gid == gid:
                    free_gid += 1
                else:
                    found = True
                    break
                if free_gid > end or free_gid > MAX_HOSTGROUPS:
                    break
        else:
            found = True

        if not found:
            msg = basic_lib.output_err(648, resource='GID')
            raise exception.HBSDError(message=msg)

        return free_gid
コード例 #18
0
    def comm_get_hostgroup_info_iscsi(self, hgs, host_iqn, target_ports):
        unit = self.unit_name
        ret, stdout, stderr = self.exec_hsnm('autargetini',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='autargetini',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        security_ports = []
        lines = stdout.splitlines()
        hostgroups = []
        security = True
        for line in lines:
            if not shlex.split(line):
                continue
            if re.match('Port', line):
                line = shlex.split(line)
                port = line[1]
                security = True if line[4] == 'ON' else False
                continue

            if target_ports and port not in target_ports:
                continue

            if security:
                if (host_iqn in shlex.split(line[72:])
                        and re.match(basic_lib.NAME_PREFIX,
                                     shlex.split(line)[0][4:])):
                    gid = int(shlex.split(line)[0][0:3])
                    hostgroups.append({
                        'port': port,
                        'gid': gid,
                        'detected': True
                    })
                    LOG.debug('Find port=%(port)s gid=%(gid)d' % {
                        'port': port,
                        'gid': gid
                    })
                if port not in security_ports:
                    security_ports.append(port)

        for hostgroup in hostgroups:
            hgs.append(hostgroup)

        return security_ports
コード例 #19
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
 def comm_add_hbawwn(self, port, gid, wwn):
     unit = self.unit_name
     ctl_no = port[0]
     port_no = port[1]
     opt = '-unit %s -set -permhg %s %s %s -gno %d' % (unit, ctl_no,
                                                       port_no, wwn, gid)
     ret, stdout, stderr = self.exec_hsnm('auhgwwn', opt)
     if ret:
         opt = '-unit %s -assign -permhg %s %s %s -gno %d' % (unit, ctl_no,
                                                              port_no, wwn,
                                                              gid)
         ret, stdout, stderr = self.exec_hsnm('auhgwwn', opt)
         if ret:
             msg = basic_lib.output_err(
                 600, cmd='auhgwwn', ret=ret, out=stdout, err=stderr)
             raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
コード例 #20
0
    def get_unused_gid_iscsi(self, group_range, port):
        start = group_range[0]
        end = min(group_range[1], MAX_HOSTGROUPS_ISCSI)
        unit = self.unit_name

        ret, stdout, stderr = self.exec_hsnm('autargetdef',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='autargetdef',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        used_list = []
        tmp_port = None
        lines = stdout.splitlines()
        for line in lines:
            line = shlex.split(line)
            if not line:
                continue

            if line[0] == "Port":
                tmp_port = line[1]
                continue

            if port != tmp_port:
                continue

            if line[0][0:3].isdigit():
                gid = int(line[0][0:3])
                if start <= gid <= end:
                    used_list.append(gid)
        if not used_list:
            return start

        for gid in range(start, end + 1):
            if gid not in used_list:
                break
        else:
            msg = basic_lib.output_err(648, resource='GID')
            raise exception.HBSDError(message=msg)

        return gid
コード例 #21
0
    def comm_get_target_iqn(self, port, gid):
        unit = self.unit_name
        ret, stdout, stderr = self.exec_hsnm('autargetdef',
                                             '-unit %s -refer' % unit)
        if ret:
            msg = basic_lib.output_err(600,
                                       cmd='autargetdef',
                                       ret=ret,
                                       out=stdout,
                                       err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        is_target_host = False
        tmp_port = None
        lines = stdout.splitlines()
        for line in lines:
            line = shlex.split(line)
            if not line:
                continue

            if line[0] == "Port":
                tmp_port = line[1]
                continue

            if port != tmp_port:
                continue

            gid_tmp = line[0][0:3]
            if gid_tmp.isdigit() and int(gid_tmp) == gid:
                is_target_host = True
                continue
            if is_target_host and line[0] == "iSCSI":
                target_iqn = line[3]
                break
        else:
            msg = basic_lib.output_err(650, resource='IQN')
            raise exception.HBSDError(message=msg)

        return target_iqn
コード例 #22
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
    def comm_add_ldev(self, pool_id, ldev, capacity, is_vvol):
        unit = self.unit_name

        if is_vvol:
            command = 'aureplicationvvol'
            opt = ('-unit %s -add -lu %d -size %dg'
                   % (unit, ldev, capacity))
        else:
            command = 'auluadd'
            opt = ('-unit %s -lu %d -dppoolno %d -size %dg'
                   % (unit, ldev, pool_id, capacity))

        ret, stdout, stderr = self.exec_hsnm(command, opt)
        if ret:
            if (re.search('DMEC002047', stderr)
                    or re.search('DMES052602', stderr)
                    or re.search('DMED09000A', stderr)):
                raise exception.HBSDNotFound
            else:
                msg = basic_lib.output_err(
                    600, cmd=command, ret=ret, out=stdout, err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
コード例 #23
0
ファイル: hbsd_snm2.py プロジェクト: Nexenta/cinder-nedge1.1
    def comm_get_dp_pool(self, pool_id):
        unit = self.unit_name
        ret, stdout, stderr = self.exec_hsnm('audppool',
                                             '-unit %s -refer -g' % unit,
                                             printflag=False)
        if ret:
            msg = basic_lib.output_err(
                600, cmd='audppool', ret=ret, out=stdout, err=stderr)
            raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)

        lines = stdout.splitlines()
        for line in lines[2:]:
            tc_cc = re.search('\s(\d+\.\d) GB\s+(\d+\.\d) GB\s', line)
            pool_tmp = re.match('\s*\d+', line)
            if (pool_tmp and tc_cc
                    and int(pool_tmp.group(0)) == pool_id):
                total_gb = int(float(tc_cc.group(1)))
                free_gb = total_gb - int(float(tc_cc.group(2)))
                return total_gb, free_gb

        msg = basic_lib.output_err(640, pool_id=pool_id)
        raise exception.HBSDError(message=msg)
コード例 #24
0
    def comm_add_lun(self, command, hostgroups, ldev, is_once=False):
        unit = self.unit_name
        tmp_hostgroups = hostgroups[:]
        used_list = []
        is_ok = False
        hlu = None
        old_hlu = None
        for hostgroup in hostgroups:
            port = hostgroup['port']
            gid = hostgroup['gid']
            hlu = self.add_used_hlun(command, port, gid, used_list, ldev)
            # When 'hlu' or 'old_hlu' is 0, it should be true.
            # So, it cannot remove 'is not None'.
            if hlu is not None:
                if old_hlu is not None and old_hlu != hlu:
                    msg = basic_lib.output_err(648, resource='LUN (HLUN)')
                    raise exception.HBSDError(message=msg)
                is_ok = True
                hostgroup['lun'] = hlu
                tmp_hostgroups.remove(hostgroup)
                old_hlu = hlu
            else:
                hlu = old_hlu

        if not used_list:
            hlu = 0
        elif hlu is None:
            for i in range(MAX_HLUN + 1):
                if i not in used_list:
                    hlu = i
                    break
            else:
                raise exception.HBSDNotFound

        ret = 0
        stdout = None
        stderr = None
        invalid_hgs_str = None
        for hostgroup in tmp_hostgroups:
            port = hostgroup['port']
            gid = hostgroup['gid']
            ctl_no = port[0]
            port_no = port[1]
            if not hostgroup['detected']:
                if invalid_hgs_str:
                    invalid_hgs_str = '%s, %s:%d' % (invalid_hgs_str, port,
                                                     gid)
                else:
                    invalid_hgs_str = '%s:%d' % (port, gid)
                continue
            opt = '-unit %s -add %s %s %d %d %d' % (unit, ctl_no, port_no, gid,
                                                    hlu, ldev)
            ret, stdout, stderr = self.exec_hsnm(command, opt)
            if ret == 0:
                is_ok = True
                hostgroup['lun'] = hlu
                if is_once:
                    break
            else:
                msg = basic_lib.set_msg(314,
                                        ldev=ldev,
                                        lun=hlu,
                                        port=port,
                                        id=gid)
                LOG.warning(msg)

        if not is_ok:
            if stderr:
                msg = basic_lib.output_err(600,
                                           cmd=command,
                                           ret=ret,
                                           out=stdout,
                                           err=stderr)
                raise exception.HBSDCmdError(message=msg, ret=ret, err=stderr)
            else:
                msg = basic_lib.output_err(659, gid=invalid_hgs_str)
                raise exception.HBSDError(message=msg)