所以我在名为pycontrol.py的python脚本文件中创建了名为BigIPLTM的类。我还有一个python服务器页面,它导入脚本并创建一个对象。我在尝试调用此对象的方法时遇到了问题。错误是BigIPLTM没有 get_pool_name 的实例。这是我的代码:对我班级的任何反馈都很棒,因为它是我用python编写的第一堂课。
pycontrol.py:
import pycontrol.pycontrol as pycontrol
class BigIPLTM:
def __init__(self, host, user="xxxx", passwd="xxxx",
content = ['LocalLB.VirtualServer', 'LocalLB.Pool',
'LocalLB.VirtualAddress', 'LocalLB.PoolMember',
'LocalLB.Monitor', 'System.SystemInfo']):
self.host = host
self.b = pycontrol.BIGIP(hostname = host, username = user,
password = passwd, fromurl = True, wsdls = content)
def get_destination(self, vipName):
destination = self.b.LocalLB.VirtualServer.get_destination(vipName)
return destination
def get_pool_name(self, vipName):
#needs to be a list
vip = list()
vip.append(vipName)
poolName = self.b.LocalLB.VirtualServer.get_default_pool_name(vip)
return poolName
def get_vip_state(self, vipName):
'''Returns a data structure containing a vip config, status and statistics'''
vip = list()
vip.append(vipName)
state = self.b.LocalLB.VirtualServer.get_enabled_state(vip)
return state
def get_members(self, poolName):
'''Returns array of members in a pool'''
pool = list()
pool.append(poolName)
members = self.b.LocalLB.Pool.get_member(pool)
#returns 3 dimensional array(default,member_number, address/port)
return members
test.psp
def get_vip_properties(vip, env):
import pycontrol
tempDict ={}
vipList = list()
vipList.append(vip)
#get pool name
b = pycontrol.BigIPLTM(env)
tempDict['pool'] = b.get_pool_name(vipList)
#get destination address and port
tempDict['destination'] = b.get_destination(vipList)
tempDict['port'] = b.get_destination(vipList)
tempDict['vipState'] = b.get_vip_state(vipList)
#get members is a 3dimensional array (default, membernumber, address/port)
tempArray = b.get_members(b.get_pool_name(vipList))
members = list()
for row in tempArray:
for entry in row:
members.append(entry[0])
tempDict['members'] = members
tempDict['member_port'] = b.get_members(b.get_pool_name(vipList))[0][0][1]
return tempDict