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
def get_capacity_stand(self): percent = self.__get_used_percent() percent = sorted(percent, key=lambda d: d[3], reverse=False) aver = sum([float(x[3]) for x in percent]) / len(percent) list = [(float(x[3]) - aver) for x in percent] total = sum([float(i) * float(i) for i in list]) stdev = math.sqrt(total / len(percent)) _dmsg("aver %s stdev %f" % (_human_readable(int(aver)), stdev)) return (aver, stdev)
def get_dev_size_syscall(self, dev): if not dev.startswith("/dev/"): dev = "/dev/" + dev if not self.is_block(dev): raise Exp(errno.EINVAL, os.strerror(errno.EINVAL)) fd = open(dev) fd.seek(0, 2) dev_size = fd.tell() fd.close() return _human_readable(dev_size)
try: (out_msg, err_msg) = _exec_pipe1(["parted", dev, "print", "-s"], 0, False, 5) except Exp, e: raise self.dev_check[dev] = out_msg lst = re.findall(r'^.+ Free Space\n', out_msg, re.M) free = 0 for i in lst: lst1 = re.findall(r'[\d.]+[kMG]B', i, 0) free += _human_unreadable(lst1[2]) return _human_readable(free) def get_dev_free(self, dev): if self.disktool == 'sgdisk': return self.get_dev_free_sgdisk(dev) elif self.disktool == 'parted': return self.get_dev_free_parted(dev) def get_dev_speed(self, dev, verbose=False): """ 针对移动集采,暂时不做磁盘测速 """ return 0 fd = os.open(dev, os.O_RDONLY) disk_size = os.lseek(fd, 0, os.SEEK_END) count = 0
def get_used_percent(self, lst=None): percent = self.__get_used_percent(lst) for i in percent: _dmsg("%s used %2.0f%% capacity %s" % (i[0], i[1], _human_readable(int(i[3]))))