def get_used_stand(self, lst): percent = self.__get_used_percent(lst) aver = sum([float(x[1]) for x in percent]) / len(percent) list = [(float(x[1]) - aver) for x in percent] total = sum([float(i) * float(i) for i in list]) stdev = math.sqrt(total / len(percent)) _dmsg("aver %2.0f%% stdev %f" % (aver, stdev)) return (aver, stdev)
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 set_lun(self, path, ext): if ext == 'ssd': num = 0 elif ext == 'hdd': num = 1 cmd = [self.config.inspect, "--tier", path, str(num)] try: (out, err) = _exec_pipe1(cmd, 0, False) ret = _exec_system("echo $?", False, False) if ret == 0: _dmsg('set %s %s successful' % (path, ext)) except Exp, e: if e.err: _derror(str(e.err)) exit(e.errno)
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 _etcd_try_start_as_proxy(cls): is_running = False member_list = cls._get_members_from_conf() if len(member_list) == 0: raise Exp(errno.EPERM, "etcd service start fail, not find init cluster!") for host in member_list: meta_list = [] meta_list.append(host) cls.etcd_set(meta_list, "existing", proxy=True) if cls._etcd_check_running(): is_running = True break else: continue if is_running: _dmsg("etcd run as proxy ok !") else: _syserror("start as proxy mode fail .") raise Exp(errno.EPERM, "etcd try to run as proxy fail, please check it !")
def member_del(self, hosts, proxy=False): origin_cluster_list = self._etcd_get_init_cluster().keys() del_list = hosts.split(',') new_cluster_list = origin_cluster_list new_del_list = [] for host in del_list: if host not in new_cluster_list: _dwarn("host:%s is not in etcd cluster, please check it!" % (host)) del_list.remove(host) continue else: #etcd member remove host new_cluster_list.remove(host) for host in del_list: if len(host) == 0: continue _dmsg("wait etcd for health, host:%s" % (host)) self._etcd_health_wait() _dmsg("etcd is health, begin check is permit to remove... host:%s" % (host)) if not self.etcd_check_member_remove_permition(host): _dwarn("host:%s not permit to remove. pelease check it!\n" % (host)) new_cluster_list.append(host) continue _dmsg("host:%s permit to remove, begin remove..." % (host)) try: cmd = "etcdctl member list | grep %s | awk '{print $1}' | awk -F':' '{print $1}'| awk -F'[' '{print $1}'| xargs etcdctl member remove" % (host) self._exec_node(new_cluster_list[0], cmd) _sysinfo("etcd member remove %s ok !" % (host)) new_del_list.append(host) except Exp, e: _syserror("etcd member remove %s fail ! errmsg:%s" % (host, e.err)) raise Exp(errno.EPERM, "etcd member remove %s fail, %s" % (host, e.err))
def _exec_node(self, h, cmd): (out, err, stat) = _exec_remote(h, cmd) if (out): _dmsg(h + ":\n" + out) if (err): _dwarn(h + ":\n" + err)
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]))))
def check_lun(self): lun_info = [] lun_info = self._lun_list() if len(lun_info): lun = [l[0] for l in lun_info] else: _dmsg('There is no lun ') exit(0) for l in lun: res = self.getstat(l) _dmsg('success lun : %d' % (self.success)) _dmsg('fail lun : %d' % (self.fail)) fail_lun = list(set(self.fail_lun)) if len(fail_lun): _dmsg('fail lun : ') for l in fail_lun: _dmsg('\t%s' % l) else: _dmsg('the cluster is ready. ')