def test(): testnode = node(691,'HLR1') try: assert str(testnode.ipList[0]) == '172.17.100.13' print('node ...... pass') except: print('node ...... failed')
def __init__(self,name): ipListAll = [] query=("SELECT DISTINCT " "fiauser.signum," "asset.id," "asset.name " "FROM " "booking_stakeholder " "left join fiauser on fiauser.id = booking_stakeholder.user_id " "left join assignment on assignment.booking_id = booking_stakeholder.booking_id " "left join asset on asset.id = assignment.asset_id " "left join booking on booking.id = assignment.booking_id " "WHERE 1=1 " "AND assignment.status = 'ACTIVE' " "AND booking.status = 'ACTIVE' " "AND fiauser.signum = %s ") queryArg = (name,) logger.info('Lookup booking information for ' + name) database = fia() result = database.lookup(query,queryArg) nodeList = [] for (username, assetid, assetname) in result: item = node(assetid,assetname) nodeList.append(item) for item in nodeList: ipListAll += item.ipList #Dirty code to add immune IP ipListAll.append('127.0.0.1') #Fetch fixip query=("SELECT * FROM fia.fixed_ip ") queryArg = () logger.info('Lookup fix IP for ' + name) result = database.lookup(query,queryArg) fixIPList = [] for (id, ip, comment) in result: fixIPList.append(ip) ipListAll += fixIPList self.ipList = list(set(ipListAll))