查看服务器wwn是否在交换机侧
判断port_state是否为Online状态,是的话,读取出port_name,即为wwn。
1 #!/usr/bin/env python3 2 3 # -*- coding: UTF-8 -*- 4 5 import glob 6 import operator 7 import os 8 9 if __name__ == "__main__": 10 work_dir='/sys/class/fc_host/host*/port_state' 11 12 for item in glob.glob(work_dir): 13 f = open(item) 14 for line in f: 15 if line == 'Online\n': 16 wwn_item = item.replace("state", "name") 17 fn = open(wwn_item) 18 for wwn in fn: 19 print wwn, 20 fn.close() 21 f.close()
用集合来存放从交换机上获取的wwn信息,把从服务器上获取的wwn逐行读取,进行比对,看是否在集合内。
为True的话,说明可以从交换机上看到此台服务器。
1 #!/usr/bin/env python3 2 3 # -*- coding: UTF-8 -*- 4 5 if __name__ == "__main__": 6 f = open("112wwn") 7 wwn_set=set() 8 for line in f: 9 wwn_set.add(line) 10 f.close() 11 print(wwn_set.__len__()) 12 13 f_host = open("172wwn") 14 for wwn in f_host: 15 if wwn in wwn_set: 16 print('True') 17 else: 18 print('False') 19 f_host.close()