def _update_version(k): update_cmd = "echo %s > /opt/sdfs/%s/%s/status/version " % (version, k[1], k[2]) try: dmsg('update meta %s %s.%s version to %s' % (k[0], k[1], k[2], version)) exec_remote(k[0], update_cmd) except Exp, e: derror("%s : %s" % (k, e))
def _check_vip_isexist(config, host, vip): try: cmd = "%s vipisexist --vip %s" % (config.uss_node, vip) exec_remote(host, cmd) return True except Exp, e: return False
def _put_remote_warp(k): try: #dmsg('update %s to %s' % (src_tar, k)) put_remote(k, src_tar, remote_tmp_path) #dmsg('install %s to %s' % (src_tar, k)) exec_remote(k, cmd_update) except Exp, e: derror("%s : %s" % (k, e))
def _warp(h): try: dmsg("try set vip:%s on host:%s..." % (dic[h], h)) cmd = "%s setvip --vips %s --mask %s" % (config.uss_node, dic[h], mask) exec_remote(h, cmd) dmsg("set vip:%s on host:%s ok..." % (dic[h], h)) except Exp, e: derror("%s : %s" % (h, e))
def _check_dual_mount(): hosts = drbd_hosts() mount = 0 for h in hosts: cmd = "mount|grep '/var/lib/leveldb'" try: exec_remote(h, cmd, exectimeout=7) mount = mount + 1 except Exp, e: pass
def _check_dual_standalone(): states = drbd_cstate() if states.count("Connected") == 2: return None hosts = drbd_hosts() for h in hosts: cmd = "drbdadm connect mds" try: exec_remote(h, cmd, exectimeout=7) except Exp, e: pass
def _collect_mac(host=None): _exec_ls = 'ls %s' % (NET_PATH) try: net_interface, _ = exec_remote(host, _exec_ls) except Exp, e: derror("%s : %s" % (_exec_ls, str(e))) sys.exit(-1)
def _put_remote_warp(k): # backup and update """ try: dmsg('backup %s to %s' % (dist, backup)) exec_remote(k, cmd_backup) except Exp, e: derror("%s : %s" % (k, e)) """ try: #dmsg('update %s to %s' % (src, k)) put_remote(k, src_tar, tmp_update) exec_remote(k, cmd_update) except Exp, e: derror("%s : %s" % (k, e))
def _init_etcd_(self, host, statue, lst): s = '' for i in lst: s = s + "%s," % (i) cmd = "%s etcd --state %s --hosts %s" % (self.config.uss_node, statue, s[:-1]) #dmsg(cmd) (out, err) = exec_remote(host, cmd) """
def _stop_remote_redis(host): while True: try: cmd = "pkill -15 redis-server" exec_remote(host, cmd, exectimeout=7) except Exp, e: dwarn(e) try: cmd = "ps aux|grep -v grep|grep redis-server" exec_remote(host, cmd, exectimeout=7) except Exp, e: dwarn(e) p = ping(host) if p: dwarn("redis-server stopped!") else: dwarn("%s network down!" % (host)) break
def drbd_cstate(): states = [] for h in drbd_hosts(): state = None cmd = "drbdadm cstate mds" try: state, _ = exec_remote(h, cmd, exectimeout=7) except Exp, e: dwarn(e) states.append(state)
def _get_services(self, host): #return services = {"bactl": [], "mdctl": []} services = {} for role in self.config.roles: path = os.path.join(self.config.workdir, role) cmd = "mkdir -p %s;ls %s" % (path, path) stdout, _ = exec_remote(host, cmd) if (stdout != ""): services.update({role: stdout.split()}) return services
def _warp(h): if h == master_vip: cmd = "python2 %s ucarpconf --srcip %s --addr %s --skew %s" % ( self.config.uss_node, h.strip(), vip.strip(), master_skew) else: cmd = "python2 %s ucarpconf --srcip %s --addr %s --skew %s" % ( self.config.uss_node, h.strip(), vip.strip(), slave_skew) x, y = exec_remote(h, cmd) print "ucarp conf host: %s \n%s" % (h, x) if y: print y
def _ad_enable(self, domain, user, passwd): dmsg("enable start") cmd = "/opt/sdfs/app/admin/samba.py reconf" cmd = cmd + " ;pkill -9 winbindd" self._exec_cmd_on_cluster_nodes(cmd, is_raise=0) #切换到AD域模式下获取域信息更新krb5文件 cmd = "rm -f /etc/krb5.conf && python /opt/sdfs/app/admin/kerb.py genconf -f /etc/krb5.conf" #配置nsswitch适配winbind cmd = cmd + " ;python /opt/sdfs/app/admin/nsswitch-conf-update.py" #创建winbind相关的软链接 cmd = cmd + " ;python /opt/sdfs/app/admin/create_access_relation.py" #更新/etc/pam.d/password-auth-ac文件 cmd = cmd + " ;python /opt/sdfs/app/admin/password-auth-ac-config-update.py" #更新/usr/local/samba/etc/ctdb/event.d/50.samba文件 cmd = cmd + " ;python /opt/sdfs/app/admin/samba_config_update.py" #更新/usr/local/samba/etc/ctdb/event.d/00.ctdb文件 cmd = cmd + " ;python /opt/sdfs/app/admin/ctdb_config_update.py" cmd = cmd + " ;ntpdate -b %s" % (domain) self._exec_cmd_on_cluster_nodes(cmd, is_raise=0) dmsg("join AD") #集群节点加入AD域 _exec_join = "/usr/local/samba/bin/net ads join -U '%s%%%s'" % (user, passwd) _exec_check = "/usr/local/samba/bin/net ads testjoin" for host in self.hosts(): out = "" err = "" try: out, err = exec_remote(host, _exec_join) except Exp, e: pass print '%s join ad, out : %s' % (host, out) try: out, err = exec_remote(host, _exec_check) except Exp, e: pass
def _ad_disable(self, domain, user, passwd): dmsg("leave AD") out = "" err = "" #集群节点离开AD域 _exec_leave = "/usr/local/samba/bin/net ads leave -U '%s%%%s'" % ( user, passwd) for host in self.hosts(): out, err = exec_remote(host, _exec_leave) print "%s leave AD, out : %s, err : %s" % (host, out, err) time.sleep(2) #重启集群各个节点samba服务 cmd = "pkill -9 winbindd" self._exec_cmd_on_cluster_nodes(cmd, is_raise=0) _exec_attr_set = "%s -s mode -V user /system" % (self.config.uss_attr) exec_shell(_exec_attr_set)
def _warp(h): try: cmd = "python2 %s getvip --group %s" % ( self.config.uss_node, group) x, y = exec_remote(h, cmd) vips = x.strip() if vips == "": vips = "None" if not json_show: print " host:%s --> vip:%s\n" % (h, vips) else: host_dic[h] = vips except Exp, e: if not json_show: print " host:%s --> vip:None\n" % (h) else: host_dic[h] = "None"
def ucarpconf(self, groups): local_clusterid = "" dst_clusterid = "" try: cmd = "%s | grep 'cluster id' | awk -F':' '{print $2}'| awk '{print $1}'" % ( self.config.uss_mdstat) out, err = exec_shell(cmd, need_return=True, p=False, timeout=30) local_clusterid = out.split("\n")[0] except Exception as e: raise Exp(1, "get local clusterid fail!") for group in groups: hosts = group.split(":")[0].split(",") vip_info = group.split(":")[1].strip() vip = vip_info.split("/")[0] master_vip = vip_info.split("/")[1] master_vip_found = 0 check_ip_valid(vip) for host in hosts: try: cmd = "%s | grep 'cluster id' | awk -F':' '{print $2}'| awk '{print $1}'" % ( self.config.uss_mdstat) x, y = exec_remote(host, cmd) dst_clusterid = x.split('\n')[0] except Exception as e: raise Exp(1, "get host %s cluster id fail!" % (host)) if dst_clusterid != local_clusterid: raise Exp(errno.EINVAL, "host %s not in cluster !" % (host)) if master_vip == host: master_vip_found = 1 if master_vip_found == 0: raise Exp( errno.EINVAL, "master vip %s not avaliable, please check it !" % (master_vip)) self._ucarp_conf_group(hosts, vip, master_vip)
def _warp(h): cmd = "python2 %s dnsdel --name %s" % (self.config.uss_node, name) x, y = exec_remote(h, cmd) print "host: %s \n%s" % (h, x) if y: print y
def _warp(h): cmd = "python2 %s logclean" % (self.config.uss_node) x, y = exec_remote(h, cmd) print "logclean host: %s \n%s" % (h, x) if y: print y
def _warp(h): x, y = exec_remote(h, cmd) #print "stat host: %s \n%s" % (h, x) if y: print y
def _warp(h): cmd = "rm -rf %s" % (self.config.vip_conf) x, y = exec_remote(h, cmd) print "host: %s vip service destroy ok\n" % (h) if y: print y
def _init_env_warp(h): cmd = "python2 %s env_init" % (self.config.uss_node) (out, err) = exec_remote(h, cmd)
def _warp(h): cmd = "python2 %s vipstop" % (self.config.uss_node) x, y = exec_remote(h, cmd) print "host: %s \n%s" % (h, x) if y: print y
def _start_warp(h): cmd = "python2 %s start --op simple" % (self.config.uss_node) exec_remote(h, cmd)
def _init_warp(h, index): cmd = "python2 %s mdctl_init --service %s" % (self.config.uss_node, index) exec_remote(h, cmd)
def _start_srv_warp(h): cmd = "python2 %s start" % (self.config.uss_node) #dmsg(cmd) exec_remote(h, cmd)
def _warp(h): x, y = exec_remote(h, cmd) if y: print "\thost:%s, errmsg:%s" % (h, y)
def _cluster_stop(module_py, host): cmd = "python2 %s stop" % (module_py) x, y = exec_remote(host, cmd) print "stop host: %s \n%s" % (host, x) if y: print y
def _warp(h): cmd = "python2 %s ucarpdestroy" % (self.config.uss_node) x, y = exec_remote(h, cmd) print "destroy ucarp host: %s \n%s" % (h, x) if y: print y
def _warp(h): cmd = "python2 %s ucarpstatus" % (self.config.uss_node) x, y = exec_remote(h, cmd) print "host: %s, status : %s" % (h, x) if y: print y