Example #1
0
 def import_raid_foreign(self):
     all_pdinfo = self.get_all_pdinfo()
     found = False
     for adp in all_pdinfo:
         for pd in all_pdinfo[adp]:
             if all_pdinfo[adp][pd]['stat'] == 'Unconfigured(bad)':
                 res = _exec_pipe(self.cmd + [
                     '-PDMakeGood',
                     '-PhysDrv[' + all_pdinfo[adp][pd]['encl'] + ':' + all_pdinfo[adp][pd]['slot'] + ']',
                     '-a' + adp,
                     '-Nolog'
                 ], 0, False)
                 res = _exec_pipe(self.cmd + [
                     '-CfgForeign',
                     '-Import',
                     '-a' + adp,
                     '-Nolog'
                 ], 0, False)
                 found = True
             if all_pdinfo[adp][pd]['foreign'] == 'Foreign':
                 res = _exec_pipe(self.cmd + [
                     '-CfgForeign',
                     '-Import',
                     '-a' + adp,
                     '-Nolog'
                 ], 0, False)
                 found = True
     if not found:
         dwarn("no Device state 'Foreign'")
Example #2
0
    def dev_mount(self, dev, path, verbose=False):
        if not dev.startswith("/dev/"):
            dev = "/dev/" + dev
        if not stat.S_ISBLK(os.lstat(os.path.realpath(dev)).st_mode):
            raise Exp('not a block device', dev)

        _exec_pipe(["mount", dev, path], 0, verbose)
Example #3
0
    def dev_try_umount(self, dev, verbose=False):
        if not dev.startswith("/dev/"):
            dev = "/dev/" + dev
        if not self.is_block(dev):
            raise Exp('not a block device', dev)

        _exec_pipe(["umount", dev], 0, verbose)
Example #4
0
    def get_dev_type(self, dev):
        if not dev.startswith("/dev/"):
            dev = "/dev/" + dev
        if self.is_part(dev):
            dev = re.match('(\D+)(\d*)', dev).group(1)
        if not self.is_block(dev):
            raise Exp(errno.EINVAL, os.strerror(errno.EINVAL))

        dev = os.path.realpath(dev)
        dev_name = dev.split('/')[-1]
        dev_type = 'UNKNOW'

        rotational = "/sys/block/" + dev_name + "/queue/rotational"
        if os.path.exists(rotational):
            type_num = _exec_pipe(["cat", rotational], 0, False)
            type_num = type_num.strip()
            if '0' == type_num:
                dev_type = 'SSD'
            elif '1' == type_num:
                dev_type = 'HDD'

        realpath = os.path.realpath('/sys/block/' + dev_name)
        m = re.match('(/sys/devices/platform/host\d+)', realpath)
        if m is not None:
            path = os.path.join(m.group(1), 'iscsi_host')
            if os.path.exists(path):
                dev_type = 'ISCSI'
            else:
                dev_type = 'UNKNOW'
            return dev_type

        pci_path = re.findall(
            r'[0-9a-fA-F]{4}:([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F])',
            realpath, re.M)
        if len(pci_path) == 0:
            realpath = os.path.realpath(os.path.join(realpath, "device"))
            pci_path = re.findall(
                r'[0-9a-fA-F]{4}:([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F])',
                realpath, re.M)
            if len(pci_path) == 0:
                return 'UNKNOW'
        if self.ls_pci is None:
            self.ls_pci = _exec_pipe(["lspci"], 0, False)
        for line in self.ls_pci.splitlines():
            if line.startswith(pci_path[-1]):
                pci_type = line.split()[1]
                if pci_type == 'USB':
                    dev_type = 'USB'
                elif pci_type == 'RAID':
                    dev_type = 'RAID'
                elif pci_type == 'Non-Volatile':
                    dev_type = 'NVMe'

        return dev_type
Example #5
0
 def raid_cache_flush(self):
     res = _exec_pipe(self.cmd + [
         '-GetPreservedCacheList',
         '-aAll',
         '-Nolog'
     ], 0, True)
     res = _exec_pipe(self.cmd + [
         '-AdpCacheFlush',
         '-aAll',
         '-Nolog'
     ], 0, True)
Example #6
0
 def get_hpcmd(self):
     cmd = 'hpssacli'
     res = ''
     fd = _lock_file1("/var/run/fusionstack_raid_hpacucli.lock")
     try:
         res = _exec_pipe([cmd, 'ctrl', 'all', 'show', 'config', 'detail'],
                          0, False)
     except Exception, e:
         cmd = 'hpacucli'
         try:
             res = _exec_pipe(
                 [cmd, 'ctrl', 'all', 'show', 'config', 'detail'], 0, False)
             if 'APPLICATION UPGRADE REQUIRED:' in res:
                 raise Exp(errno.EPERM, "please update raid card tools")
         except Exception, e:
             raise Exp(errno.EPERM, "please install raid card tools")
Example #7
0
    def is_hba(self, dev):
        if not dev.startswith("/dev/"):
            dev = "/dev/" + dev
        if self.is_part(dev):
            dev = re.match('(\D+)(\d*)', dev).group(1)
        if not self.is_block(dev):
            raise Exp(errno.EINVAL, os.strerror(errno.EINVAL))

        dev = os.path.realpath(dev)
        dev_name = dev.split('/')[-1]
        realpath = os.path.realpath('/sys/block/' + dev_name)

        pci_path = re.findall(
            r'[0-9a-fA-F]{4}:([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F])',
            realpath, re.M)
        if len(pci_path) == 0:
            realpath = os.path.realpath(os.path.join(realpath, "device"))
            pci_path = re.findall(
                r'[0-9a-fA-F]{4}:([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F])',
                realpath, re.M)
            if len(pci_path) == 0:
                return False
        if self.ls_pci is None:
            self.ls_pci = _exec_pipe(["lspci"], 0, False)
        for line in self.ls_pci.splitlines():
            if line.startswith(pci_path[-1]):
                if 'Serial Attached SCSI controller: Hewlett-Packard Company Smart Array' in line:
                    return True

        return False
Example #8
0
    def add_raid0(self, disk, force):
        is_new = False
        new_disk = self.get_new_disk()
        for adp, disks in new_disk.iteritems():
            if disk in disks:
                is_new = True
        if not is_new:
            raise Exp(errno.EINVAL, "'" + disk + "' not a new disk")

        disk_info = self.get_disk_info(disk)

        if force:
            self.del_raid_foreign()
        try:
            res = _exec_pipe(self.cmd + [
                '-CfgLdAdd',
                '-r0',
                '['+disk_info['encl']+':'+disk_info['slot']+']',
                'WB',
                'RA',
                'Cached',
                'NoCachedBadBBU',
                '-a'+disk_info['adp'],
                '-Nolog'
            ], 0, True)
        except Exception, e:
            raise Exp(errno.EPERM, 'can not add %s, try use --force' % disk)
Example #9
0
    def get_show_all(self):
        fd = _lock_file1("/var/run/fusionstack_raid_hpacucli.lock")
        res = _exec_pipe([self.cmd, 'ctrl', 'all', 'show', 'config', 'detail'],
                         0, False)
        _unlock_file1(fd)

        return res
Example #10
0
    def __check_raid_env(self):
        host_type = platform.architecture()[0]
        raid_type = []
        ls_pci = None

        try:
            ls_pci = _exec_pipe(["lspci"], 0, False)
        except:
            return None

        for line in ls_pci.splitlines():
            if 'RAID bus controller: LSI Logic / Symbios Logic MegaRAID' in line:
                cmd = "/opt/MegaRAID/MegaCli/MegaCli"
                if host_type == '64bit':
                    cmd += '64'
                try:
                    (out_msg, err_msg) = _exec_pipe1([cmd, "-v", "-Nolog"], 0,
                                                     False, 10)
                except Exception, e:
                    raise Exp(errno.EPERM, cmd + " command execute failed")
                try:
                    (out_msg, err_msg) = _exec_pipe1(["disk2lid"], 0, False)
                except Exception, e:
                    _derror("disk2lid command execute failed")
                    return None
                if 'MegaRAID' not in raid_type:
                    raid_type.append('MegaRAID')
Example #11
0
    def get_dev_raidcard(self, dev):
        if not dev.startswith("/dev/"):
            dev = "/dev/" + dev
        if self.is_part(dev):
            dev = re.match('(\D+)(\d*)', dev).group(1)
        if not self.is_block(dev):
            raise Exp(errno.EINVAL, os.strerror(errno.EINVAL))

        dev = os.path.realpath(dev)
        dev_name = dev.split('/')[-1]

        realpath = os.path.realpath('/sys/block/' + dev_name)

        pci_path = re.findall(
            r'[0-9a-fA-F]{4}:([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F])',
            realpath, re.M)
        if len(pci_path) == 0:
            realpath = os.path.realpath(os.path.join(realpath, "device"))
            pci_path = re.findall(
                r'[0-9a-fA-F]{4}:([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F])',
                realpath, re.M)
            if len(pci_path) == 0:
                return 'UNKNOW'
        if self.ls_pci is None:
            self.ls_pci = _exec_pipe(["lspci"], 0, False)
        for line in self.ls_pci.splitlines():
            if line.startswith(pci_path[-1]):
                pci_type = line.split()[1]
                if pci_type == 'RAID':
                    raidcard = re.search('RAID bus controller:([^\[(]*)',
                                         line).group(1).strip()
                    return raidcard

        raise Exp(errno.EINVAL, os.strerror(errno.EINVAL))
Example #12
0
    def _lun_list(self):
        lun = []
        lun_info = []
        pool = []
        tgt = []

        dir = '/'
        res = _exec_pipe([self.lichfs, '--list', dir], 0, False)
        for r in res.splitlines():
            r = dir + r.split(' ')[-1]
            if r == '/system':
                continue
            res = _exec_pipe([self.lichfs, '--list', r], 0, False)
            for p in res.splitlines():
                p = p.split(' ')[-1]
                pool.append(r + dir + p)

        for p in pool:
            res = _exec_pipe([self.lichfs, '--list', p], 0, False)
            for l in res.splitlines():
                l = l.split(' ')[-1]
                path = p + dir + l
                if self.is_dir(path):
                    tgt.append(path)
                else:
                    lun.append(path)

        for t in tgt:
            res = _exec_pipe([self.lichfs, '--list', t], 0, False)
            res = [x.split(' ')[-1] for x in res.splitlines()]
            for l in res:
                path = t + dir + l
                if (self.is_dir(path)):
                    _dmsg('%s is dir' % path)
                    _derror('list lun fail')
                    #exit(e.errno)
                else:
                    lun.append(path)

        for l in lun:
            size = self.getsize(l)
            size = _human_readable(int(size))
            allocated = self.getallocated(l)
            allocated = _human_readable(int(allocated) * self.chunksize)
            lun_info.append((l, size, allocated))

        return lun_info
Example #13
0
 def del_raid0(self, dev):
     dev_info = self.get_dev_info(dev)
     fd = _lock_file1("/var/run/fusionstack_raid_hpacucli.lock")
     res = _exec_pipe([
         self.cmd, 'ctrl', 'slot=' + dev_info['adp'], 'logicaldrive',
         dev_info['ld'], 'delete', 'forced'
     ], 0, False)
     _unlock_file1(fd)
Example #14
0
 def del_raid0(self, dev):
     (dev_adp, dev_vd) = self.get_dev_vd(dev)
     res = _exec_pipe(self.cmd + [
         '-CfgLdDel',
         '-L' + dev_vd,
         '-a' + dev_adp,
         '-Nolog'
     ], 0, True)
Example #15
0
    def get_dev_bymounted(self, path):
        dev = None
        res = _exec_pipe(["mount"], 0, False)
        for line in res.splitlines():
            mnt = re.search('^(/dev/.+) on %s type' % (path), line)
            if mnt is not None:
                dev = mnt.group(1)

        return dev
Example #16
0
    def dev_format(self, dev, verbose):
        if not dev.startswith("/dev/"):
            dev = "/dev/" + dev

        fd = _lock_file(
            "/var/run/fusionstack_disk_%s.lock" % dev.split('/')[-1], -1,
            False)
        res = _exec_pipe(["mkfs.ext4", dev, '-F'], 0, True)
        if verbose:
            print(res.strip())
Example #17
0
 def del_raid_missing(self):
     raid_missing = self.get_raid_missing()
     for adp in raid_missing:
         for vd in raid_missing[adp]:
             res = _exec_pipe(self.cmd + [
                 '-DiscardPreservedCache',
                 '-L' + vd,
                 '-force',
                 '-a' + adp,
                 '-Nolog'
             ], 0, True)
Example #18
0
    def list_lun(self, v):
        localun = []
        lun = ""
        tgt = ""
        size = ""

        time.sleep(1)
        try:
            res = _exec_pipe([self.lichfs, '--list', self.defaultpath], 0, False)
            for line in res.splitlines():
                pool = line.split(' ')[-1]
                lunres = _exec_pipe([self.lichfs, '--list', self.defaultpath + pool], 0, False)
                for l in lunres.splitlines():
                    lun = l.split(' ')[-1]
                    lunsize = self.getsize(pool+'/'+lun, v)
                    if pool is not None and lun is not None:
                        size = lunsize
                        localun.append((pool + '/' + lun, size))
        except Exp, e:
            _derror('list local lun fail')
            exit(e.errno)
Example #19
0
    def get_part_type(self, part):
        if not part.startswith("/dev/"):
            part = "/dev/" + part
        if not self.is_part(part):
            raise Exp(errno.EINVAL, os.strerror(errno.EINVAL))

        try:
            res = _exec_pipe(["file", "-s", part], 0, False)
            if 'ERROR' not in res:
                return res.split()[4]
        except Exception, e:
            return None
Example #20
0
    def __set_raid_cache(self, prop, l, a):
        res = _exec_pipe(self.cmd + [
            '-LDSetProp',
            prop,
            '-L' + l,
            '-a' + a,
            '-Nolog'
        ], 0, False)

        if "will not come into effect immediately" in res:
            return False

        return True
Example #21
0
    def get_dev_vd(self, dev):
        dev_adp = ''
        dev_vd = ''

        res = _exec_pipe(['disk2lid', dev], 0, False)
        for line in res.splitlines():
            dev_re = re.search('^MEIDISEN_INFO:.*:\s*(\d+)\s*:\s*Logical Drive Number :\s*(\d+)', line)
            if dev_re is not None:
                (dev_adp, dev_vd) = dev_re.group(1, 2)
        if dev_adp == '' or dev_vd == '':
            raise Exp(errno.EPERM, dev + " not found in raid array use disk2lid")

        return (dev_adp, dev_vd)
Example #22
0
    def get_part_uuid(self, part):
        if not part.startswith("/dev/"):
            part = "/dev/" + part

        try:
            res = _exec_pipe(["blkid", "-s", 'UUID', part], 0, False)
            if 'UUID' in res:
                part_uuid = res.split()[1].split('"')[1]
                return part_uuid
            else:
                return None
        except Exp, e:
            return None
Example #23
0
    def __get_used_percent(self, lst=None):
        #lst = ['node4/0', 'node4/1', 'node4/2', 'node4/3', 'node5/0']
        used_percent = []

        res = _exec_pipe([self.lich_admin, '--listnode'], 3, False)[:-1]
        if lst:
            list = [x.strip() for x in res.splitlines() if x.strip() in lst]
        else:
            list = [x.strip() for x in res.splitlines()]

        if len(list) == 0:
            _derror("node is not exists")
            exit(errno.EINVAL)

        for node in list:
            res = _exec_pipe([self.lich_admin, '--stat', node], 3, False)[:-1]
            if (len(res) != 0):
                d = _str2dict(res)
                used = d['used']
                capacity = d['capacity']
                percent = float(used) / float(capacity) * 100
                used_percent.append((node, percent, used, capacity))
        return sorted(used_percent, key=lambda d: d[1], reverse=False)
Example #24
0
    def __set_raid_cache(self, dev_info, smartpath, raid_cache, disk_cache,
                         ratio, badbbu_cache):
        if smartpath:
            fd = _lock_file1("/var/run/fusionstack_raid_hpacucli.lock")
            res = _exec_pipe([
                self.cmd, 'ctrl', 'slot=' + dev_info['adp'], 'array',
                dev_info['array'], 'modify', 'ssdsmartpath=' + smartpath
            ], 0, False)
            _unlock_file1(fd)

        if raid_cache:
            fd = _lock_file1("/var/run/fusionstack_raid_hpacucli.lock")
            try:
                res = _exec_pipe([
                    self.cmd, 'ctrl', 'slot=' + dev_info['adp'],
                    'logicaldrive', dev_info['ld'], 'modify',
                    'caching=' + raid_cache, 'forced'
                ], 0, False)
            except Exp, e:
                raise
                '''
                if e.errno == errno.EPERM and self.cmd == 'hpssacli':
                    res = _exec_pipe([
                        'hpacucli',
                        'ctrl',
                        'slot=' + dev_info['adp'],
                        'logicaldrive',
                        dev_info['ld'],
                        'modify',
                        'caching=' + raid_cache,
                        'forced'
                    ], 0, False)
                else:
                    raise
                '''
            _unlock_file1(fd)
Example #25
0
    def get_dev_fs(self, part):
        if not part.startswith("/dev/"):
            part = "/dev/" + part
        if not self.is_block(part):
            raise Exp(errno.EINVAL, os.strerror(errno.EINVAL))

        try:
            res = _exec_pipe(["blkid", "-s", 'TYPE', part], 0, False)
            if 'TYPE' in res:
                part_fs = res.split()[1].split('"')[1]
                return part_fs
            else:
                return None
        except Exp, e:
            return None
Example #26
0
    def is_dm(self, dev):
        if not dev.startswith("/dev/"):
            dev = "/dev/" + dev
        if not stat.S_ISBLK(os.lstat(dev).st_mode):
            raise Exp(errno.EINVAL, '%s not a block device' % dev)

        res = _exec_pipe(["dmsetup", 'table'], 0, False)
        for line in res.splitlines():
            dms = re.findall(r'\((/dev/\w+)\)', line, re.M)
            for dm in dms:
                (dm_dev, dm_part) = re.match('(\D+)(\d*)', dm).group(1, 2)
                if dev == dm_dev:
                    return True

        return False
Example #27
0
 def del_raid_foreign(self):
     all_pdinfo = self.get_all_pdinfo()
     for adp in all_pdinfo:
         for pd in all_pdinfo[adp]:
             if all_pdinfo[adp][pd]['stat'] == 'Unconfigured(bad)':
                 res = _exec_pipe(self.cmd + [
                     '-PDMakeGood',
                     '-PhysDrv[' + all_pdinfo[adp][pd]['encl'] + ':' + all_pdinfo[adp][pd]['slot'] + ']',
                     '-a' + adp,
                     '-Nolog'
                 ], 0, False)
                 res = _exec_pipe(self.cmd + [
                     '-CfgForeign',
                     '-clear',
                     '-a' + adp,
                     '-Nolog'
                 ], 0, False)
             if all_pdinfo[adp][pd]['foreign'] == 'Foreign':
                 res = _exec_pipe(self.cmd + [
                     '-CfgForeign',
                     '-clear',
                     '-a' + adp,
                     '-Nolog'
                 ], 0, False)
Example #28
0
 def del_raid_missing(self):
     all_raid = self.all_raid
     for adp in all_raid:
         for array in all_raid[adp]:
             if array == 'bbu_info':
                 continue
             if array != 'unassigned':
                 for logical in all_raid[adp][array]['logical']:
                     if all_raid[adp][array]['logical'][logical][
                             'stat'] == 'Failed':
                         fd = _lock_file1(
                             "/var/run/fusionstack_raid_hpacucli.lock")
                         res = _exec_pipe([
                             self.cmd, 'ctrl', 'slot=' + adp,
                             'logicaldrive', logical, 'delete', 'forced'
                         ], 0, False)
                         _unlock_file1(fd)
Example #29
0
    def set_raid_ratio(self, dev, ratio=None):
        raid_info = self.get_dev_info(dev)

        if ratio is None:
            ratio = ['10', '90']
        elif len(ratio) != 2:
            ratio = ['10', '90']
        elif int(ratio[0]) + int(ratio[1]) != 100:
            ratio = ['10', '90']

        #hpacucli ctrl slot=0 modify cacheratio=10/90
        fd = _lock_file1("/var/run/fusionstack_raid_hpacucli.lock")
        res = _exec_pipe([
            self.cmd, 'ctrl', 'slot=' + raid_info['adp'], 'modify',
            'cacheratio=' + ratio[0] + '/' + ratio[1], 'forced'
        ], 0, False)
        _unlock_file1(fd)
Example #30
0
    def get_raid_missing(self, p=True):
        raid_missing = {}
        res = _exec_pipe(self.cmd + [
            '-GetPreservedCacheList',
            '-aAll',
            '-Nolog'
        ], 0, p)

        for line in res.splitlines():
            adp_re = re.search('^Adapter [#]?(\d+)', line)
            if adp_re is not None:
                adp = adp_re.group(1)
                raid_missing[adp] = []
            vd_re = re.search('Virtual Drive\(Target ID (\d+)\):', line)
            if vd_re is not None:
                vd = vd_re.group(1)
                raid_missing[adp].append(str(string.atoi(vd)))

        return raid_missing