def __init__(self, verbose=0): """ Class constructor """ self.verbose = verbose # Object to do dashboard call self.dashcall = DashboardCaller(verbose=1) # Object shared to do server calls self.servercall = Caller(verbose=1) self.config_file = None self.config = []
class Broker(object): """ Broker object to control regression system along Gitlab push/issue/merge requests """ def __init__(self, verbose=0): """ Class constructor """ self.verbose = verbose # Object to do dashboard call self.dashcall = DashboardCaller(verbose=1) # Object shared to do server calls self.servercall = Caller(verbose=1) self.config_file = None self.config = [] def set_config_file(self, config): """ Configuration file setter """ self.config_file = config def setup(self): """ Function to setup the server from configuration file """ self.config = [] tree = etree.parse(self.config_file) root = tree.getroot() # Read from xml configuration file all # the available resources for server in root.find("servers"): srv = {} srv["namespace"] = server.attrib['namespace'] srv["version"] = server.attrib['version'] srv["name"] = server.attrib['name'] srv["ip"] = server.attrib['ip'] srv["port"] = server.attrib['port'] srv["type"] = server.attrib['type'] srv["place"] = server.attrib['place'] srv["vendor"] = server.attrib['vendor'] srv["board"] = server.attrib['board'] self.config.append(srv) # Configure the dashboard caller for server in self.config: if server["namespace"] == "dashboard": self.dashcall.setup(server) if self.verbose: print "info - broker.py - Configuration loaded:" for server in self.config: print server def filter_hooks(self): """ Function to filter hooks and launch them after a mean time to avoid multiple useless runs """ pass def get_dashboard(self): """ Read all server status """ return self.dashcall.read_dashboard() def get_dashboard_help(self): """ Read all server status """ return self.dashcall.read_help() def get_server_status(self): """ Read all server status """ status = [] for server in self.config: stat = {} self.servercall = Caller() self.servercall.set_cfg(server) stat["status"] = self.servercall.call(route="status", verb="GET", data=None) stat["name"] = server.name["name"] status.append(stat) return status