亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
python ssh
[打印本頁]
作者:
wind1211
時(shí)間:
2014-11-18 11:02
標(biāo)題:
python ssh
本帖最后由 rdcwayx 于 2014-11-19 19:04 編輯
import paramiko
import time
import sys
#Collecting Huawe Storage
#Created by wind1211 2013/07
def ssh2(ip,username,passwd,cmd):
#print ip+","+username+","+passwd+","+cmd.rstrip()
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,22,username,passwd,timeout=8)
stdin,stdout,stderr = ssh.exec_command(cmd)
cmd_output = stdout.read()
ssh.close()
except:
print "connect to "+ip+"failed"
return cmd_output
def _wr_csv(buff,_file):
fb = open(_file,"w")
#argument buff must be list
for item in(buff):
try:
fb.write(item)
except:
print("write"+_file+" info failed")
fb.close()
#define _ocenStoreSys
def _ocenStoreSys():
ost_instinfo = "name,sn,model,hba\n"
_ocenStore_cmd1 = 'license show sys'
ocenStore_output1 = ssh2(ip,username,passwd,_ocenStore_cmd1)
#print(ocenStore_output1)
ocenStore_output = ocenStore_output1.split("\n")
for ost_item in (ocenStore_output):
ost_inst = ost_item.rstrip().split()
ost_inst_len = len(ost_inst)
if( ost_inst_len == 5 and ost_inst[1] == "Serial"):
ocenstor_sn = ost_inst[3]
if(ost_inst_len == 4 and ost_inst[1] == "Model:"):
ocenstor_model = ost_inst[2]
#print(ocenstor_sn)
#print(ocenstor_model)
######OceanStore HBA and array name####
store_file=csv_path+ip+"_array.csv"
_ocenStore_cmd2_hba = 'storage hba'
_ocenStore_output2 =ssh2(ip,username,passwd,_ocenStore_cmd2_hba)
_ocenStore_output = _ocenStore_output2.split("\n")
for ost_hba_item in (_ocenStore_output):
ost_hba_inst = ost_hba_item.rstrip().split()
if(len(ost_hba_inst)>=2 and ost_hba_inst[0] != "Node" and ost_hba_inst[0] != "----"):
#print(ost_hba_inst)
ost_inst_hbainfo = ''.join(ost_hba_inst[1:])
ost_instinfo=ost_instinfo+ip+","+ost_hba_inst[0]+","+ocenstor_sn+","+ocenstor_model+","+ost_inst_hbainfo.replace(",","_")+"\n"
#print(ost_instinfo)
_wr_csv(ost_instinfo,store_file)
def _ocenStoreDiskDetail():
disk_info="name,pool,size,sn\n"
disk_file=csv_path+ip+"_disk.csv"
disk_cmd = 'storage disk list detail'
disk_output1 = ssh2(ip,username,passwd,disk_cmd)
disk_output = disk_output1.split("\n")
for disk_item in (disk_output):
disk_inst = disk_item.rstrip().split()
if(len(disk_inst)>1 and disk_inst[0] != "Disk" and disk_inst[0] != "===="):
disk_info = disk_info +disk_inst[0]+","+disk_inst[1]+","+disk_inst[3]+","+disk_inst[6]+"\n"
#print(disk_info)
_wr_csv(disk_info,disk_file)
def _ocenStoreLun():
lun_info="name,size,raid,poolname\n"
lun_file=csv_path+ip+"_lun.csv"
lun_cmd = 'storage fs list'
lun_output1 = ssh2(ip,username,passwd,lun_cmd)
lun_output = lun_output1.split("\n")
for lun_item in (lun_output):
lun_inst = lun_item.rstrip().split()
if(len(lun_inst)==11 and lun_inst[0] != "FS" and lun_inst[0] != "===="):
lun_info = lun_info+lun_inst[0]+","+lun_inst[2]+","+lun_inst[3]+","+lun_inst[10]+"\n"
#print(lun_info)
_wr_csv(lun_info,lun_file)
if __name__=='__main__':
ip = '1.2.3.4'
username = 'admin'
passwd = '1234'
csv_path="C:\\test\\test3\\remote\\OceanStore\\"
_ocenStoreSys()
#Get disk info and reletive pool name
_ocenStoreDiskDetail()
#get lun info
_ocenStoreLun()
復(fù)制代碼
作者:
rdcwayx
時(shí)間:
2014-11-19 19:07
能給個(gè)代碼備注嗎?
歡迎光臨 Chinaunix (http://72891.cn/)
Powered by Discuz! X3.2