def __init__(self, defaultPrivateKey): self.queue = deque() self.defaultPrivateKey = defaultPrivateKey self.agents = dict([(c.item_type, c()) for c in all_subclasses(BaseDiscovery) if hasattr(c, 'item_type')]) self._hosts = {} self._clients = {}
def discover(self, initial_nodes, private_key): "Takes a list of node addresses " "and returns discovered openstack installation info" agents = dict([(c.item_type, c()) for c in all_subclasses(BaseDiscovery) if hasattr(c, 'item_type')]) driver = DiscoveryDriver(private_key) # Set connection info and queue initial nodes for info in parse_nodes_info(initial_nodes, private_key): driver.setHostConnectionInfo( host=info['host'], port=info['port'], username=info['username'], password=info['password'], privateKey=info['private_key']) driver.enqueue('host', info['host']) items = [] while len(driver.queue) > 0: task = driver.queue.popleft() self.logger.info('Processing item of type %s, host = %s' % (task.type, task.host)) if task.type in agents.keys(): agent = agents[task.type] if agent.seen(driver, task.host, **task.data): continue item = agent.discover(driver, task.host, **task.data) if item: items.append(item) else: self.logger.error('Unknown item type: %s' % task.type) # Rebuild model tree openstack = Openstack() for host in filter(lambda i: isinstance(i, Host), items): openstack.add_host(host) for service in filter(lambda i: isinstance(i, Service), items): host = find(openstack.hosts, lambda h: h.id == service.host_id) if not host: continue host.add_component(service) return openstack