def application_info_user_add(request): vhost_id_req = request.POST.get('vhost_id', '').split(',') middleware_req = request.POST.get('middleware', '') username_req = request.POST.get('username', '') package_req = request.POST.get('package_name', '') password = username_req + '#Pass' logging.info(vhost_id_req, middleware_req, username_req, package_req, password) create_host_user_cmd = 'useradd -g app -md /app/'+ username_req +' -s /bin/csh '+ username_req +';echo '+ password +'|passwd --stdin '+ username_req +';'\ 'mkdir -p /data;cd /data;mkdir -p '+ username_req +'/logs;chmod 755 '+ username_req +';chown -R '+ username_req +':app '+ username_req +';' host_user = [] for host_id in vhost_id_req[:len(vhost_id_req)]: host_user.append( app_user(username=username_req, password=password, middleware=middleware_req, package=package_req, host_id=host_id)) #ip = vhost.objects.all().filter(host_id=host_id).distinct().values('vhost_name'); hostname = vhost.objects.get(host_id=host_id).vhost_name ssh2(hostname, create_host_user_cmd) app_user.objects.bulk_create(host_user) return HttpResponse('Already created user!')
def nbu_startjob_byhand(request): master = request.REQUEST.get('master', '').split() client = request.REQUEST.get('client', '').split() policy = request.REQUEST.get('policy', '').split() status = 'redoing' if client: client = client[0].encode('utf-8') if policy: policy = policy[0].encode('utf-8') if master: master = master[0].encode('utf-8') cmd_backup = "bpbackup -i -p "+ policy +" -h " + client +" -S " + master +" ;sleep 15;bpdbjobs -report -M "+master+"|awk '/Active/&&/"+policy+"/&&/"+client+"/{print $1}'|head -1;" print(cmd_backup) jobid = ssh2(cmd_backup) if jobid: jobid = jobid[0].encode('utf-8').strip() else: cmd_check = "bpdbjobs -report -M "+master+"|awk '/Done/&&/"+policy+"/&&/"+client+"/{print $1}'|head -1;" jobid = ssh2(cmd_check)[0].encode('utf-8').strip() cmd_status = "bpdbjobs -report -M "+master+" -jobid "+jobid+"|awk '/Done/{print $4}'" status = ssh2(cmd_status)[0].encode('utf-8').strip() if status == '0' : status = 'success' else: status = 'failed' job = nbu_jobs_byhand(jobid=jobid,client=client,policy=policy,master=master,status=status,start_date=datetime.now().strftime("%Y-%m-%d %H:%M:%S")) job.save() return HttpResponse('update success')
def nbu_jobs_problem(): cmd4zjbjbak_svc = "bpdbjobs -most_columns -M zjbjbak_svc|awk -F , '($2==0)&&($3==3)&&($4 > 0){print $1,$4,$5,$6,$7,$8}'|grep -v test|sort -k 5 |uniq -f 1 -f 2 -f 4" cmd4zjdamaster1 = "bpdbjobs -most_columns |awk -F , '($2==0)&&($3==3)&&($4 > 0){print $1,$4,$5,$6,$7,$8}'|grep -v test|sort -k 5 |uniq -f 1 -f 2 -f 4" out_zjbjbak_svc = ssh2(cmd4zjbjbak_svc) out_zjdamaster1 = ssh2(cmd4zjdamaster1) return out_zjbjbak_svc, out_zjdamaster1
def nbu_device(): media = {} cmd_mediatotal = "ssh -A -t zjbjbak1 \"/usr/openv/volmgr/bin/vmquery -bx -a|grep -v -E 'NONE|CLN'|wc -l\"" cmd_availmedia = "ssh -A -t zjbjbak1 \"/usr/openv/volmgr/bin/vmquery -bx -a|grep -E '\\-\\-\\-'|grep -v -E 'NONE|CLN'|wc -l\"" cmd_mediascratch = "ssh -A -t zjbjbak1 \"/usr/openv/volmgr/bin/vmquery -bx -a|grep ScratchPool|grep -v -E 'NONE|CLN'|wc -l\"" cmd_mediaexpired = "ssh -A -t zjbjbak1 \"/usr/openv/volmgr/bin/vmquery -bx -a|grep Expired_media|grep -v -E 'NONE|CLN'|wc -l\"" cmd_mediaforzen = "ssh -A -t -v zjbjbak1 \"/usr/openv/netbackup/bin/admincmd/bpmedialist |grep -i frozen|wc -l\"" media['mediatotal'] = ssh2(cmd_mediatotal)[0].strip('\n') media['availmedia'] = ssh2(cmd_availmedia)[0].strip('\n') media['mediascratch'] = ssh2(cmd_mediascratch)[0].strip('\n') media['mediaexpired'] = ssh2(cmd_mediaexpired)[0].strip('\n') media['mediaforzen'] = ssh2(cmd_mediaforzen)[0].strip('\n') return media
def nbu_ajax_jobs(request): master = request.REQUEST.get('master', '').split() jobid = request.REQUEST.get('jobid', '').split() client = request.REQUEST.get('client', '').split() policy = request.REQUEST.get('policy', '').split() redo_jobid = request.REQUEST.get('redo_jobid', '').split() jobid = jobid[0] redo_jobid = redo_jobid[0].encode('utf-8') if redo_jobid !='None': jobid = redo_jobid print(jobid) error_info = '' oracle_type = 'db' ploicy_name = policy[0] if 'arch' in ploicy_name: oracle_type = 'arch' print(ploicy_name) if ( 'oracle' in ploicy_name): print('hello') if (master[0] == 'zjbjbak_svc'): cmd = r"ssh -A -t -l root "+master[0]+" \"scp /tmp/nbu_rmanerr.sh root@" + client[0] + ":/tmp/;\" ssh -A -t -l root "+ client[0] + " \"sh /tmp/nbu_rmanerr.sh " + oracle_type + ";\"" print(cmd) error_info = ssh2(cmd) if error_info : print("error_info_zj"+error_info[0]) else: cmd = r"scp /tmp/nbu_rmanerr.sh root@" + client[0] + ":/tmp/;\" ssh -A -t -l root "+ client[0] + " \"sh /tmp/nbu_rmanerr.sh " + oracle_type + ";\"" #print(cmd) error_info = ssh2(cmd) if error_info : print("error_info_master"+error_info[0]) else: cmd = "bperror -problems -backstat -L -M " + master[0] +" -jobid " + jobid print(cmd) error_info = ssh2(cmd) line_error_info = '' if len(error_info) > 0 : for error in error_info: line_error_info += error +'\n' error_info = line_error_info else: error_info = "Nothing" return HttpResponse(error_info)
def addprojectauto(request): projecthostinfo = getdatafromcmdb() putdatatodb(projecthostinfo) for host in projecthostinfo: host_info = host[1].split('_') host_name = host_info[2] host_ip = host[2] establishtrust(host_ip, host_name) if (len(host_info) == 5): if (int(host_info[4]) != 0): username = host_name[4:len(host_info) - 2] + host_info[3] password = username + '#Pass' create_deploy_user = r'/usr/sbin/useradd -g app -md /app/'+ username +' -s /bin/csh '+ username +';/bin/echo '+ password +'|/usr/bin/passwd --stdin '+ username +';'\ '/bin/mkdir -p /data;cd /data;/bin/mkdir -p '+ username +'/logs;/bin/chmod 755 '+ username +';/bin/chown -R '+ username +':app '+ username +';' userexist = ssh2(host_ip, r'grep ' + username + ' /etc/passwd') if (userexist): break else: logging.info(create_deploy_user) #ssh2(host_ip,create_deploy_user) return HttpResponse(u'数据获取成功!')
def addprojectauto(request): projecthostinfo = getdatafromcmdb() putdatatodb(projecthostinfo) for host in projecthostinfo: host_info = host[1].split('_') host_name = host_info[2] host_ip = host[2] establishtrust(host_ip,host_name) if(len(host_info)==5): if(int(host_info[4])!=0): username = host_name[4:len(host_info)-2] + host_info[3] password = username + '#Pass' create_deploy_user = r'/usr/sbin/useradd -g app -md /app/'+ username +' -s /bin/csh '+ username +';/bin/echo '+ password +'|/usr/bin/passwd --stdin '+ username +';'\ '/bin/mkdir -p /data;cd /data;/bin/mkdir -p '+ username +'/logs;/bin/chmod 755 '+ username +';/bin/chown -R '+ username +':app '+ username +';' userexist = ssh2(host_ip,r'grep '+username+' /etc/passwd') if(userexist): break; else: logging.info(create_deploy_user) #ssh2(host_ip,create_deploy_user) return HttpResponse(u'数据获取成功!')
def application_info_user_add(request): vhost_id_req = request.POST.get("vhost_id", "").split(",") middleware_req = request.POST.get("middleware", "") username_req = request.POST.get("username", "") package_req = request.POST.get("package_name", "") password = username_req + "#Pass" logging.info(vhost_id_req, middleware_req, username_req, package_req, password) create_host_user_cmd = ( "useradd -g app -md /app/" + username_req + " -s /bin/csh " + username_req + ";echo " + password + "|passwd --stdin " + username_req + ";" "mkdir -p /data;cd /data;mkdir -p " + username_req + "/logs;chmod 755 " + username_req + ";chown -R " + username_req + ":app " + username_req + ";" ) host_user = [] for host_id in vhost_id_req[: len(vhost_id_req)]: host_user.append( app_user( username=username_req, password=password, middleware=middleware_req, package=package_req, host_id=host_id, ) ) # ip = vhost.objects.all().filter(host_id=host_id).distinct().values('vhost_name'); hostname = vhost.objects.get(host_id=host_id).vhost_name ssh2(hostname, create_host_user_cmd) app_user.objects.bulk_create(host_user) return HttpResponse("Already created user!")
def check_policy(): policy_zjbjbak_svc = ssh2("bppllist -M zjbjbak_svc") policy_zjdamaster1 = ssh2("bppllist") #INSERT_policy = "INSERT INTO daily_nbu_policy (policy,master,active) VALUES (%s,%s,%s)" INSERT_client_policy = "INSERT INTO daily_nbu_client_policy (client,policy,master,active) VALUES (%s,%s,%s,%s)" try: conn = mysql.connector.connect(host='10.70.219.10',user='******',password='******',database='ops') cur=conn.cursor() # For simple bussiness logic ,we trancat table and insert the laster data whcih collect from master server cur.execute("truncate daily_nbu_client_policy;") if policy_zjbjbak_svc : for policy in policy_zjbjbak_svc: policy = policy.strip('\n') result = ssh2("bppllist "+policy+" -M zjbjbak_svc -L|awk '/^Active|^Client\//{print $2}'") print(policy,result[0].strip('\n')) if result : if len(result)>1: client_cmd = result[1:len(result)] for client in client_cmd : cur.execute(INSERT_client_policy,(client.strip('\n'),policy,'zjbjbak_svc',result[0].strip('\n'))) else: cur.execute(INSERT_client_policy,('NoClient',policy,'zjbjbak_svc',result[0].strip('\n'))) conn.commit() if policy_zjdamaster1 : for policy in policy_zjdamaster1: policy = policy.strip('\n') result = ssh2("bppllist "+policy+" -L|awk '/^Active|^Client\//{print $2}'") if result : if len(result)>1: client_cmd = result[1:len(result)] for client in client_cmd : cur.execute(INSERT_client_policy,(client.strip('\n'),policy,'zjdamaster1',result[0].strip('\n'))) else: cur.execute(INSERT_client_policy,('NoClient',policy,'zjdamaster1',result[0].strip('\n'))) conn.commit() cur.close() conn.close() except mysql.connector.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1])
def application_info_user_add(request): vhost_id_req = request.POST.get('vhost_id', '').split(',') middleware_req = request.POST.get('middleware', '') username_req = request.POST.get('username', '') package_req = request.POST.get('package_name', '') password= username_req + '#Pass' logging.info(vhost_id_req,middleware_req,username_req,package_req,password) create_host_user_cmd = 'useradd -g app -md /app/'+ username_req +' -s /bin/csh '+ username_req +';echo '+ password +'|passwd --stdin '+ username_req +';'\ 'mkdir -p /data;cd /data;mkdir -p '+ username_req +'/logs;chmod 755 '+ username_req +';chown -R '+ username_req +':app '+ username_req +';' host_user = [] for host_id in vhost_id_req[:len(vhost_id_req)]: host_user.append(app_user(username=username_req,password=password,middleware=middleware_req,package=package_req,host_id=host_id)) #ip = vhost.objects.all().filter(host_id=host_id).distinct().values('vhost_name'); hostname = vhost.objects.get(host_id=host_id).vhost_name ssh2(hostname,create_host_user_cmd) app_user.objects.bulk_create(host_user) return HttpResponse('Already created user!')
def addprojectauto(request): projecthostinfo = getdatafromcmdb() putdatatodb(projecthostinfo) for host in projecthostinfo: host_info = host[1].split("_") host_name = host_info[2] host_ip = host[2] establishtrust(host_ip, host_name) if len(host_info) == 5: if int(host_info[4]) != 0: username = host_name[4 : len(host_info) - 2] + host_info[3] password = username + "#Pass" create_deploy_user = ( r"/usr/sbin/useradd -g app -md /app/" + username + " -s /bin/csh " + username + ";/bin/echo " + password + "|/usr/bin/passwd --stdin " + username + ";" "/bin/mkdir -p /data;cd /data;/bin/mkdir -p " + username + "/logs;/bin/chmod 755 " + username + ";/bin/chown -R " + username + ":app " + username + ";" ) userexist = ssh2(host_ip, r"grep " + username + " /etc/passwd") if userexist: break else: logging.info(create_deploy_user) # ssh2(host_ip,create_deploy_user) return HttpResponse(u"数据获取成功!")
def check_handjobs(request): redoingjobs = nbu_jobs_byhand.objects.all().filter(start_date__range=(yesterday,tomorrow),status='redoing').values(); if redoingjobs : for jobs in redoingjobs: master = jobs['master'].encode('utf-8') jobid = int(jobs['jobid']) cmd_status = "bpdbjobs -report -M "+master+" -jobid "+str(jobid)+"|awk '/Done/{print $4}'" status = ssh2(cmd_status) if status : status = status[0].encode('utf-8').strip('\n') else : continue if status == '0' : status = 'success' else: status = 'failed' jobs_byhand = nbu_jobs_byhand.objects.get(jobid=jobid) jobs_byhand.status = status jobs_byhand.save() return HttpResponse('已经检查,稍后自动刷新页面!'.decode('gbk'))
def addproject(request): projectname_req = request.POST.get('project_name', '') package_req = request.POST.get('deploy_package', '') middleware_req = request.POST.get('middleware', '') hostnames_req = request.POST.get('hostname', '').split(',') hostnames_cl = hostnames_req[0:len(hostnames_req) - 1] order_name = vhost.objects.filter( order_name=projectname_req).values('order_no') if (order_name): return HttpResponse(u'项目已经存在!') logging.info(hostnames_cl) vhosts = [] app_users = [] order_no = 'DL' + (datetime.now()).strftime('%Y%m%d%H%M%S') # hostname like : 10.78.200.062_suse_vq12zdfb01_web01_4 increatment = 1 for host in hostnames_cl: logging.info(host) host_info = host.split('_') vhost_ip_tmp = host_info[0].split('.') logging.info(vhost_ip_tmp) vhost_ip = str(vhost_ip_tmp[0]) + '.' + str( vhost_ip_tmp[1]) + '.' + str(vhost_ip_tmp[2]) + '.' + str( int(vhost_ip_tmp[3])) ip_exist = vhost.objects.filter(host_ip=vhost_ip).values('host_ip') if (ip_exist): return HttpResponse('Host IP :' + vhost_ip + ' Already exist!') vhost_name = host_info[2] order_name = projectname_req hosted_id_db = vhost.objects.order_by('host_id').values( 'host_id').last() hosted_id = int(hosted_id_db['host_id']) + increatment logging.info(hosted_id) increatment = increatment + 1 vhosts.append( vhost(host_id=hosted_id, host_name=host, vhost_name=vhost_name, host_ip=vhost_ip, order_no=order_no, order_name=order_name, create_date=today, status='hosted')) username = vhost_name[4:len(vhost_name) - 2] + host_info[3] password = username + '!Pass' app_users.append( app_user(username=username, password=password, middleware=middleware_req, host_id=hosted_id, package=package_req, instance_num=host_info[4])) vhost.objects.bulk_create(vhosts) app_user.objects.bulk_create(app_users) #establish trust for deploy server and create deploy user for host in vhosts: host_name = host.vhost_name host_ip = host.host_ip establishtrust(host_ip, host_name) userinfo = app_user.objects.filter(host_id=host.host_id).values( 'username', 'password') for auser in userinfo: username = auser['username'] if (host_name[4:len(host_name) - 2] in username): create_deploy_user = r'/usr/sbin/useradd -g app -md /app/'+ username +' -s /bin/csh '+ username +';/bin/echo '+ auser['password'] +'|/usr/bin/passwd --stdin '+ username +';'\ '/bin/mkdir -p /data;cd /data;/bin/mkdir -p '+ username +'/logs;/bin/chmod 755 '+ username +';/bin/chown -R '+ username +':app '+ username +';' ssh2(host_ip, create_deploy_user) return HttpResponse('Already added project information!')
def addproject(request): projectname_req = request.POST.get("project_name", "") package_req = request.POST.get("deploy_package", "") middleware_req = request.POST.get("middleware", "") hostnames_req = request.POST.get("hostname", "").split(",") hostnames_cl = hostnames_req[0 : len(hostnames_req) - 1] order_name = vhost.objects.filter(order_name=projectname_req).values("order_no") if order_name: return HttpResponse(u"项目已经存在!") logging.info(hostnames_cl) vhosts = [] app_users = [] order_no = "DL" + (datetime.now()).strftime("%Y%m%d%H%M%S") # hostname like : 10.78.200.062_suse_vq12zdfb01_web01_4 increatment = 1 for host in hostnames_cl: logging.info(host) host_info = host.split("_") vhost_ip_tmp = host_info[0].split(".") logging.info(vhost_ip_tmp) vhost_ip = ( str(vhost_ip_tmp[0]) + "." + str(vhost_ip_tmp[1]) + "." + str(vhost_ip_tmp[2]) + "." + str(int(vhost_ip_tmp[3])) ) ip_exist = vhost.objects.filter(host_ip=vhost_ip).values("host_ip") if ip_exist: return HttpResponse("Host IP :" + vhost_ip + " Already exist!") vhost_name = host_info[2] order_name = projectname_req hosted_id_db = vhost.objects.order_by("host_id").values("host_id").last() hosted_id = int(hosted_id_db["host_id"]) + increatment logging.info(hosted_id) increatment = increatment + 1 vhosts.append( vhost( host_id=hosted_id, host_name=host, vhost_name=vhost_name, host_ip=vhost_ip, order_no=order_no, order_name=order_name, create_date=today, status="hosted", ) ) username = vhost_name[4 : len(vhost_name) - 2] + host_info[3] password = username + "!Pass" app_users.append( app_user( username=username, password=password, middleware=middleware_req, host_id=hosted_id, package=package_req, instance_num=host_info[4], ) ) vhost.objects.bulk_create(vhosts) app_user.objects.bulk_create(app_users) # establish trust for cloudops server and create cloudops user for host in vhosts: host_name = host.vhost_name host_ip = host.host_ip establishtrust(host_ip, host_name) userinfo = app_user.objects.filter(host_id=host.host_id).values("username", "password") for auser in userinfo: username = auser["username"] if host_name[4 : len(host_name) - 2] in username: create_deploy_user = ( r"/usr/sbin/useradd -g app -md /app/" + username + " -s /bin/csh " + username + ";/bin/echo " + auser["password"] + "|/usr/bin/passwd --stdin " + username + ";" "/bin/mkdir -p /data;cd /data;/bin/mkdir -p " + username + "/logs;/bin/chmod 755 " + username + ";/bin/chown -R " + username + ":app " + username + ";" ) ssh2(host_ip, create_deploy_user) return HttpResponse("Already added project information!")
def addproject(request): projectname_req = request.POST.get('project_name','') package_req = request.POST.get('deploy_package','') middleware_req = request.POST.get('middleware','') hostnames_req = request.POST.get('hostname','').split(',') hostnames_cl = hostnames_req[0:len(hostnames_req)-1] order_name = vhost.objects.filter(order_name = projectname_req).values('order_no') if(order_name): return HttpResponse(u'项目已经存在!') logging.info(hostnames_cl) vhosts = [] app_users = [] order_no = 'DL'+(datetime.now()).strftime('%Y%m%d%H%M%S') # hostname like : 10.78.200.062_suse_vq12zdfb01_web01_4 increatment = 1; for host in hostnames_cl: logging.info(host) host_info = host.split('_') vhost_ip_tmp = host_info[0].split('.') logging.info(vhost_ip_tmp) vhost_ip = str(vhost_ip_tmp[0])+'.'+str(vhost_ip_tmp[1])+'.'+str(vhost_ip_tmp[2])+'.' +str(int(vhost_ip_tmp[3])) ip_exist = vhost.objects.filter(host_ip = vhost_ip).values('host_ip') if(ip_exist): return HttpResponse('Host IP :'+vhost_ip+' Already exist!') vhost_name = host_info[2] order_name = projectname_req hosted_id_db = vhost.objects.order_by('host_id').values('host_id').last() hosted_id = int(hosted_id_db['host_id']) + increatment logging.info(hosted_id) increatment = increatment + 1 vhosts.append(vhost(host_id=hosted_id,host_name=host,vhost_name=vhost_name,host_ip=vhost_ip,order_no=order_no,order_name=order_name,create_date=today,status='hosted')) username = vhost_name[4:len(vhost_name)-2] + host_info[3] password= username + '!Pass' app_users.append(app_user(username=username,password=password,middleware=middleware_req,host_id=hosted_id,package=package_req,instance_num=host_info[4])) vhost.objects.bulk_create(vhosts) app_user.objects.bulk_create(app_users) #establish trust for deploy server and create deploy user for host in vhosts: host_name = host.vhost_name host_ip = host.host_ip establishtrust(host_ip,host_name) userinfo = app_user.objects.filter(host_id=host.host_id).values('username','password') for auser in userinfo: username = auser['username'] if(host_name[4:len(host_name)-2] in username): create_deploy_user = r'/usr/sbin/useradd -g app -md /app/'+ username +' -s /bin/csh '+ username +';/bin/echo '+ auser['password'] +'|/usr/bin/passwd --stdin '+ username +';'\ '/bin/mkdir -p /data;cd /data;/bin/mkdir -p '+ username +'/logs;/bin/chmod 755 '+ username +';/bin/chown -R '+ username +':app '+ username +';' ssh2(host_ip,create_deploy_user) return HttpResponse('Already added project information!')
def fixjob_auto(): try: conn = mysql.connector.connect(host='10.70.219.10',user='******',password='******',database='ops') cur=conn.cursor() status = [23,25,48,58,59] cur.execute("SELECT jobid,status,policy,master,media,client FROM daily_nbu_jobs WHERE redo_status='' and policy not like '%oracle%' and date_format(check_date,'%Y-%m-%d') = '"+today+"' and status in(" + ",".join(("%s",) * len(status)) + ")",tuple(status)) UPDATE = ("UPDATE daily_nbu_jobs SET redo_status = 'success_auto' WHERE jobid=%s") UPDATE_message = ("UPDATE daily_nbu_jobs SET redo_message = %s WHERE jobid=%s") if(cur): for jobid,status,policy,master,media,client in cur.fetchall(): print(jobid,status,policy,master,media,client) master_status = ssh2("bptestbpcd -M "+master+" -host "+client+" ") media_status = ssh2(" ssh -A -t -l root zjbjbak2 ssh -A -t -l root "+ media + " bptestbpcd -host "+client+" ") print('bptest',master_status,media_status) server_check = ssh2(" ssh zjbjbak2 ping "+ client + " -n 1 -m 5|grep -E '100%|0%|unknown' ") if(master_status=='' and media_status ==''): cur.execute(UPDATE, (jobid)) continue if(server_check): server_check = server_check[0] if('100%' in server_check or 'unknown' in server_check): print("please client") cur.execute(UPDATE_message, ('Please check the client.',jobid)) continue else: # add host /etc/hosts if master =='zjbjbak_svc' : master_ip_host = '10.70.213.135 zjbjbak_svc' elif master =='zjdamaster1' : master_ip_host = '10.70.219.11 zjdamaster1' media_ip_host = ssh2("ssh zjbjbak2 \"grep "+media+" /etc/hosts|grep -v '^#'|awk '/10.7/{print \$1,\$2}'|head -1 \"") client_ip_host = ssh2("ssh zjbjbak2 \"grep "+client+" /etc/hosts|grep -v '^#'|awk '/10.7/{print \$1,\$2}'|head -1 \"") print('bk2',media_ip_host,client_ip_host) if media_ip_host : media_ip_host = media_ip_host[0].strip('\n') else: cur.execute(UPDATE_message, ('Please check the media server.',jobid)) continue if client_ip_host : client_ip_host = client_ip_host[0].strip('\n') else: cur.execute(UPDATE_message, ('Please check the client.',jobid)) continue #master_server if(not master_status): media_ip_host_master = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+master+" \"grep " + media +" /etc/hosts|grep -v '^#'|head -1 |awk '{print \$0}' \"") client_ip_host_master = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+master+" \"grep " + client +" /etc/hosts|grep -v '^#'|head -1 |awk '{print \$0}' \"") if( not media_ip_host_master): ssh2("ssh -A -t zjbjbak2 ssh -A -t "+master+" \" echo "+media_ip_host+" \>\>/etc/hosts \" ") if( not client_ip_host_master): ssh2("ssh -A -t zjbjbak2 ssh -A -t "+master+" \" echo "+client_ip_host+" \>\>/etc/hosts \" ") #media_server if(not media_status): master_ip_host_media = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+media+" \"grep " + master +" /etc/hosts|grep -v '^#'|head -1 |awk '{print \$0}' \"") client_ip_host_media = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+media+" \"grep " + client +" /etc/hosts|grep -v '^#'|head -1 |awk '{print \$0}' \"") if(not client_ip_host_media) : ssh2("ssh -A -t zjbjbak2 ssh -A -t "+media+" \"echo "+client_ip_host+" \>\>/etc/hosts\" ") if(not master_ip_host_media) : ssh2("ssh -A -t zjbjbak2 ssh -A -t "+media+" \"echo "+master_ip_host+" \>\> /etc/hosts\" ") #client master_ip_host_client = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"grep " + master +" /etc/hosts|grep -v '^#'|head -1 |awk '{print \$0}' \"") media_ip_host_client = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"grep " + media +" /etc/hosts|grep -v '^#'|head -1 |awk '{print \$0}' \"") master_ip_host_conf = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"grep " + master +" /usr/openv/netbackup/bp.conf|grep -v '^#'|head -1 |awk '{print \$0}' \"") media_ip_host_conf = ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"grep " + media +" /usr/openv/netbackup/bp.conf|grep -v '^#'|head -1 |awk '{print \$0}' \"") print('client check',master_ip_host_client,media_ip_host_client,master_ip_host_conf,media_ip_host_conf) if(not master_ip_host_client): ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"echo "+master_ip_host+" \>\>/etc/hosts \"") if(not media_ip_host_client): ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"echo "+media_ip_host+" \>\>/etc/hosts \"") if(not master_ip_host_conf): ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"echo SERVER = "+master+ " \>\>/usr/openv/netbackup/bp.conf \"") if(not media_ip_host_conf): ssh2("ssh -A -t zjbjbak2 ssh -A -t "+client+" \"echo SERVER = "+media+ " \>\>/usr/openv/netbackup/bp.conf \"") #clean cache ssh2(" ssh -A -t zjbjbak2 ssh -A -t "+master+" \"/usr/openv/netbackup/bin/bpclntcmd -clear_host_cache\"") ssh2(" ssh -A -t zjbjbak2 ssh -A -t "+media+" \"/usr/openv/netbackup/bin/bpclntcmd -clear_host_cache\"") ssh2(" ssh -A -t zjbjbak2 ssh -A -t "+master+" \"/usr/openv/netbackup/bin/admincmd/bptestbpcd -host "+client+"\"") ssh2(" ssh -A -t zjbjbak2 ssh -A -t "+media+" \"/usr/openv/netbackup/bin/admincmd/bptestbpcd -host "+client+"\"") conn.commit() cur.close() conn.close() except mysql.connector.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1])