def getUPSTypeFromProvider(provider): if provider is None: return None if provider.building is None or provider.TR is None: raise AttributeError( "getUPSTypeFromProvider requires a valid building and room") buildingList = Hosts.getBuildings(provider.building) if provider.building not in buildingList: raise ValueError("Invalid Building, unable to get host") # search by room and switch filtered = Hosts.filter(buildingList, str(provider.TR), ups=True) if filtered[provider.building] is None: return None # convert host (stew-115b-apc5000rm-01.tcom.purdue.edu) to device (apc5000rm) return Hosts.hostToUPSDevice(filtered[provider.building][0])
def getHostFromProvider(provider): if provider is None: return None if provider.building is None or provider.TR is None or provider.switchType is None: raise AttributeError( "getHostFromProvider requires a valid building, room, and switchType" ) buildingList = Hosts.getBuildings(provider.building) if provider.building not in buildingList: raise ValueError("Invalid Building, unable to get host") # search by room and switch filtered = Hosts.filter(buildingList, str(provider.TR), switches=True) for host in filtered[provider.building]: if Hosts.isEqual(host, provider.building, provider.TR, provider.switchType, provider.stack): return host return None
def getHostsFromPatch(patch): if patch is None: return None if patch.building is None or patch.room is None: raise AttributeError( "getHostsFromPatch requires a valid building and room") buildingList = Hosts.getBuildings(patch.building) if patch.building not in buildingList: raise ValueError("Invalid Building, unable to get host") # search by room and switch filtered = Hosts.filter(buildingList, str(patch.room), switches=True) hosts = [] for host in filtered[patch.building]: if Hosts.isEqual(host, patch.building, patch.room, None, None): hosts.append(host) if len(hosts) == 0: return None else: return hosts