亚洲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 編輯
  1. import paramiko
  2. import time
  3. import sys
  4. #Collecting Huawe Storage
  5. #Created by wind1211 2013/07
  6. def ssh2(ip,username,passwd,cmd):
  7.     #print ip+","+username+","+passwd+","+cmd.rstrip()
  8.     try:
  9.         ssh = paramiko.SSHClient()
  10.         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  11.         ssh.connect(ip,22,username,passwd,timeout=8)
  12.         stdin,stdout,stderr = ssh.exec_command(cmd)
  13.         cmd_output = stdout.read()
  14.         ssh.close()
  15.     except:
  16.         print "connect to "+ip+"failed"
  17.     return cmd_output

  18. def _wr_csv(buff,_file):
  19.     fb = open(_file,"w")
  20.     #argument buff must be list
  21.     for item in(buff):
  22.         try:
  23.             fb.write(item)
  24.         except:
  25.             print("write"+_file+" info failed")
  26.     fb.close()

  27. #define _ocenStoreSys
  28. def _ocenStoreSys():
  29.     ost_instinfo = "name,sn,model,hba\n"
  30.     _ocenStore_cmd1 = 'license show sys'
  31.     ocenStore_output1 = ssh2(ip,username,passwd,_ocenStore_cmd1)
  32.     #print(ocenStore_output1)
  33.     ocenStore_output = ocenStore_output1.split("\n")
  34.     for ost_item in (ocenStore_output):
  35.         ost_inst = ost_item.rstrip().split()
  36.         ost_inst_len = len(ost_inst)
  37.         if( ost_inst_len == 5 and ost_inst[1] == "Serial"):
  38.             ocenstor_sn = ost_inst[3]
  39.         if(ost_inst_len == 4 and ost_inst[1] == "Model:"):
  40.             ocenstor_model = ost_inst[2]
  41.     #print(ocenstor_sn)
  42.     #print(ocenstor_model)
  43.     ######OceanStore HBA and array name####
  44.     store_file=csv_path+ip+"_array.csv"
  45.     _ocenStore_cmd2_hba = 'storage hba'
  46.     _ocenStore_output2 =ssh2(ip,username,passwd,_ocenStore_cmd2_hba)
  47.     _ocenStore_output = _ocenStore_output2.split("\n")
  48.     for ost_hba_item in (_ocenStore_output):
  49.         ost_hba_inst = ost_hba_item.rstrip().split()
  50.         if(len(ost_hba_inst)>=2 and ost_hba_inst[0] != "Node" and ost_hba_inst[0] != "----"):
  51.             #print(ost_hba_inst)
  52.             ost_inst_hbainfo = ''.join(ost_hba_inst[1:])
  53.             ost_instinfo=ost_instinfo+ip+","+ost_hba_inst[0]+","+ocenstor_sn+","+ocenstor_model+","+ost_inst_hbainfo.replace(",","_")+"\n"
  54.     #print(ost_instinfo)
  55.     _wr_csv(ost_instinfo,store_file)


  56. def _ocenStoreDiskDetail():
  57.     disk_info="name,pool,size,sn\n"
  58.     disk_file=csv_path+ip+"_disk.csv"
  59.     disk_cmd = 'storage disk list detail'
  60.     disk_output1 = ssh2(ip,username,passwd,disk_cmd)
  61.     disk_output = disk_output1.split("\n")
  62.     for disk_item in (disk_output):
  63.         disk_inst = disk_item.rstrip().split()
  64.         if(len(disk_inst)>1 and disk_inst[0] != "Disk" and disk_inst[0] != "===="):
  65.             disk_info = disk_info +disk_inst[0]+","+disk_inst[1]+","+disk_inst[3]+","+disk_inst[6]+"\n"
  66.     #print(disk_info)
  67.     _wr_csv(disk_info,disk_file)

  68. def _ocenStoreLun():
  69.     lun_info="name,size,raid,poolname\n"
  70.     lun_file=csv_path+ip+"_lun.csv"
  71.     lun_cmd = 'storage fs list'
  72.     lun_output1 = ssh2(ip,username,passwd,lun_cmd)
  73.     lun_output = lun_output1.split("\n")
  74.     for lun_item in (lun_output):
  75.         lun_inst = lun_item.rstrip().split()
  76.         if(len(lun_inst)==11 and lun_inst[0] != "FS" and lun_inst[0] != "===="):
  77.             lun_info = lun_info+lun_inst[0]+","+lun_inst[2]+","+lun_inst[3]+","+lun_inst[10]+"\n"
  78.     #print(lun_info)
  79.     _wr_csv(lun_info,lun_file)
  80.    
  81. if __name__=='__main__':
  82.     ip = '1.2.3.4'
  83.     username = 'admin'
  84.     passwd = '1234'
  85.     csv_path="C:\\test\\test3\\remote\\OceanStore\\"
  86.     _ocenStoreSys()

  87.     #Get disk info and reletive pool name
  88.     _ocenStoreDiskDetail()

  89.     #get lun info
  90.     _ocenStoreLun()
復(fù)制代碼

作者: rdcwayx    時(shí)間: 2014-11-19 19:07
能給個(gè)代碼備注嗎?




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2