Best Python code snippet using localstack_python
dcxunjian_v2.py
Source:dcxunjian_v2.py
1# -*- coding:utf-8 -*-2#ä½è
sikx@dcits.com3#v2çæ¹è¿ï¼4#å·²å®æï¼å¯¹æ æ³è·åæ°æ®æ°æ®æ示è·å失败ï¼ä¿®æ¹é误çstale计ç®æ¹å¼ï¼ä¿®æ¹åªè½è·å第ä¸æ¡ipçé®é¢5#ä»éæ¹è¿ï¼topas没ææ¶éè¦å
¶ä»å½ä»¤ä»£æ¿ï¼å¤æ¬¡è¿åç»æåºä½¿ç¨å¹³åå¼è®¡ç®ï¼6import re7print(" ******************************************")8print(" TOPç³»ç»å·¡æ£å¡«åå°å©æV2.0")9print(" ******************************************")10print(" ")11#æ¬ç¨åºä»
ç¨äºè·åAIXç³»ç»å·¡æ£æå
ä¸TOPç³»ç»æéå¡«åçä¿¡æ¯ã12#æå
ä¸éè¦æå½ä»¤prtconf,ifconfig,topas,iostat,df -g,errpt,lsvgç13print(" ")14#log = open(name,'r')15#è·åä¿¡æ¯éç¨å½æ°16def check_func(zz):17 get_data = re.findall(r'%s'%zz,logt,re.S)18 try:19 get_data[0]20 return get_data21 except:22 return ('è·å失败ï¼')23#读åæ件24def readfile():25 name = raw_input("请è¾å
¥å½åç®å½ä¸æ¥å¿æ件å(å
æ¬æ©å±å): ")26 try:27 log = open('/tmp/%s'%name,'r')28 logt = log.read()29 log.close()30 return logt31 except:32 print("æ件读å失败!请æ£æ¥åéè¯ï¼")33 return readfile()34logt = readfile()35def get_func(logt):36 #è·ååºåå·37 get_machine_id = check_func('Machine Serial Number\:\ (\w{5,10})')38 try:39 if get_machine_id[0] == get_machine_id[1]:40 machine_id = get_machine_id[0]41 else:42 machine_id = get_machine_id43 except:44 try:45 machine_id = get_machine_id[0]46 except:47 machine_id = 'è·å失败ï¼'48 #è·åIP49 get_ip = check_func('inet\ ((?:\d{1,3}\.){3}\d{1,3})')50 #æ¥çrootvgéåç¶æ51 get_rootvg = check_func('lsvg \-l rootvg(.*?)\#')[0]52 get_rootnum = re.findall(r' {2,20}(\d{1,5}) {2,20}(\d{1,5}) {2,20}(\d{1,5})',get_rootvg,re.S)53 x = 054 y = 055 for ii in get_rootnum:56 if int(ii[1]) == 2*int(ii[0]):57 x = x + 158 else:59 if int(ii[1]) == int(ii[0]):60 y = y + 161 if x > y:62 rootvgmi = "æ¯"63 else:64 if x==0 and y==0:65 rootvgmi = "è·å失败"66 else:67 rootvgmi = "å¦"68 #å¤ææ¬æºæ¯å¦æstaleç¶æé»è¾å·69 get_stale = check_func('STALE\ PVs\:\s*(\d)')[0]70 if int(get_stale) == 0:71 stale = "æ£å¸¸"72 else:73 stale = "å¼å¸¸"74 #å¤ææ¯å¦æTOPAS75 try:76 get_topas = re.findall(r'(topas\: *not)',logt)[0]77 cpu = get_memory = get_pagingspace = "è·å失败ï¼"78 #å¦ææè·å以ä¸ä¿¡æ¯79 except:80 get_cpu= check_func('topas.*?Kernel\ {4,10}\d.*?Idle\ {4,10}([1-9]\S*)')[0]81 cpu = 100 - float(get_cpu)82 get_memory = check_func('topas.*?MEMORY.*?Comp\ {4,10}(\d\S*)')[0]83 get_pagingspace = check_func('topas.*?PAGING\ SPACE.*?Used\ {4,10}(\d\S*)')[0]84 get_iostat = check_func('iostat.*?tty.*?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)')[0]85 iostat = 100 - float(get_iostat[4])86 try:87 get_errpt = re.findall(r'errpt.*?DESCRIPTION(.*?)\#',logt,re.S)[0]88 except:89 get_errpt = None90 #get_df = re.findall(r'sort.*?(\d{1,3}%)',logt,re.S)[0]91 #get_df = re.findall(r'sort\ \-rn\ \+3(.*?)\#',logt,re.S)[0]92 get_df = re.findall(r'(df -.*?)\#',logt,re.S)[0]93 print(" ")94 print(" ")95 print("æ¬æºIPæ¯ï¼%s"%get_ip)96 print("æ¬æºåºåå·æ¯ï¼%s"%machine_id)97 print("********************************************")98 print("æ¬æºæ¯å¦ææä½ç³»ç»éåï¼ %s"%rootvgmi)99 print("æ¬æºæ¯å¦æstaleç¶æé»è¾å·ï¼ %s"%stale)100 print("********************************************")101 print("æ¬æºCPU使ç¨ï¼ %s"%cpu)102 print("æ¬æºIO使ç¨ï¼ %s"%iostat)103 print("æ¬æºå
å使ç¨ï¼ %s"%get_memory)104 print("æ¬æºPAGING SPACEï¼ %s"%get_pagingspace)105 print("********************************************")106 print("æ¬æºç©ºé´å ç¨ï¼ %s"%get_df)107 print("********************************************")108 print("æ¬æºæ¥éï¼ %s"%get_errpt)109 Choicenum =raw_input('è¾å
¥1继ç»ç¨åºï¼è¾å
¥å
¶ä»éåºï¼è¯·è¾å
¥ä»£ç ï¼ ')110 if Choicenum == str(1):111 logt = readfile()112 get_func(logt)...
dcxunjian.py
Source:dcxunjian.py
1# -*- coding:gbk -*-2#ä½è
sikx@dcits.com3import re4print(" ******************************************")5print(" TOPç³»ç»å·¡æ£å¡«åå°å©æV1")6print(" ******************************************")7print(" ")8#æ¬ç¨åºä»
ç¨äºè·åAIXç³»ç»å·¡æ£æå
ä¸TOPç³»ç»æéå¡«åçä¿¡æ¯ã9#æå
ä¸éè¦æå½ä»¤prtconf,ifconfig,topas,iostat,df -g,errpt,lsvgç10print(" ")11#log = open(name,'r')12def readfile():13 name = raw_input("请è¾å
¥å½åç®å½ä¸æ¥å¿æ件å(å
æ¬æ©å±å): ")14 try:15 log = open(name,'r')16 logt = log.read()17 log.close()18 return logt19 except:20 print("æ件读å失败!请æ£æ¥åéè¯ï¼")21 return readfile()22## finally:23## if log:24## log.close()25## #print logt26logt = readfile()27get_machine_id = re.findall(r'Machine Serial Number\:\ (\w{5,10})',logt,re.S)28try:29 if get_machine_id[0] == get_machine_id[1]:30 machine_id = get_machine_id[0]31 else:32 machine_id = get_machine_id33except:34 try:35 machine_id = get_machine_id[0]36 except:37 machine_id = None38get_ip = re.findall(r'ifconfig.*?inet\ ((?:\d{1,3}\.){3}\d{1,3})',logt,re.S)39#get_topas = re.match(r'topas.*?Kernel.*?Idle\ {4,6}(\d{1,3}\.{0,1}\d{0,1}).*?MEMORY.*?Comp\ {4,7}(\d{1,3}\.{0,1}\d{0,1})PAGING\ SPACE.*?Used\ {4,7}(\d{1,3}\.{0,1}\d{0,1})',logt,re.S)40#print get_topas41#get_CPU = get_topas[0]42#get_memory = get_topas[1]43#get_pagingspace = get_topas[2]44get_rootvg = re.findall(r'lsvg \-l rootvg(.*?)\#',logt,re.S)[0]45get_rootnum = re.findall(r' {2,20}(\d{1,5}) {2,20}(\d{1,5}) {2,20}(\d{1,5})',get_rootvg,re.S)46x = 047y = 048for ii in get_rootnum:49 if int(ii[1]) == 2*int(ii[0]):50 x = x + 151 else:52 if int(ii[1]) == int(ii[0]):53 y = y + 154if x > y:55 rootvgmi = "æ¯"56else:57 if x==0 and y==0:58 rootvgmi = "è·å失败"59 else:60 rootvgmi = "å¦"61get_stale = re.findall(r'lsvg -o\s*(.*?)#',logt,re.S)62if get_stale == []:63 stale = "å¦"64else:65 stale = "æ¯"66get_cpu= re.findall(r'topas.*?Kernel\ {4,10}\d.*?Idle\ {4,10}([1-9]\S*)',logt,re.S)[0]67cpu = 100 - float(get_cpu)68get_memory = re.findall(r'topas.*?MEMORY.*?Comp\ {4,10}(\d\S*)',logt,re.S)[0]69#print get_memory70get_pagingspace = re.findall(r'topas.*?PAGING\ SPACE.*?Used\ {4,10}(\d\S*)',logt,re.S)[0]71#print get_pagingspace72#get_iostat = re.findall(r'iostat.*?idle.*?((?:\d{1,3}\.{0,1}\d{0,1}\ {1,20}){6})',logt,re.S)[0]73get_iostat = re.findall(r'iostat.*?tty.*?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)\ *?(\d\S*)',logt,re.S)[0]74#print get_iostat75iostat = 100 - float(get_iostat[4])76try:77 get_errpt = re.findall(r'errpt.*?DESCRIPTION(.*?)\#',logt,re.S)[0]78except:79 get_errpt = None80#get_df = re.findall(r'sort.*?(\d{1,3}%)',logt,re.S)[0]81#get_df = re.findall(r'sort\ \-rn\ \+3(.*?)\#',logt,re.S)[0]82get_df = re.findall(r'(df -.*?)\#',logt,re.S)[0] 83print(" ")84print(" ")85print("æ¬æºIPæ¯ï¼%s"%get_ip)86print("æ¬æºåºåå·æ¯ï¼%s"%machine_id)87print("********************************************")88print("æ¬æºæ¯å¦ææä½ç³»ç»éåï¼ %s"%rootvgmi)89print("æ¬æºæ¯å¦æstaleç¶æé»è¾å·ï¼ %s"%stale)90print("********************************************")91print("æ¬æºCPU使ç¨ï¼ %s"%cpu)92print("æ¬æºIO使ç¨ï¼ %s"%iostat)93print("æ¬æºå
å使ç¨ï¼ %s"%get_memory)94print("æ¬æºPAGING SPACEï¼ %s"%get_pagingspace)95print("********************************************")96print("æ¬æºç©ºé´å ç¨ï¼ %s"%get_df)97print("********************************************")98print("æ¬æºæ¥éï¼ %s"%get_errpt)...
pin.py
Source:pin.py
...36 'Flask',37 '/usr/local/lib/python2.7/dist-packages/flask/app.pyc'38 ]39# uuid.getnode() -> /sys/class/net/<interface>/address40# get_machine_id() -> /etc/machine-id41# private_bits = [str(uuid.getnode()), get_machine_id()]42private_bits = [43 get_node,44 get_machine_id45 ]46h = md5()47for bit in chain(probably_public_bits, private_bits):48 if not bit:49 continue50 if isinstance(bit, str):51 bit = bit.encode('utf-8')52 h.update(bit)53h.update(b'cookiesalt')54#h.update(b'shittysalt')55cookie_name = '__wzd' + h.hexdigest()[:20]...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!