def get_nodes(self, options=None): nodes = [] self.deployment_status = None self.nodes_dict = self._get_deployment_nodes() self.deployment_status = self.get_deployment_status() for k, v in self.nodes_dict.iteritems(): node = manager.Node(v['id'], v['ip'], k, v['status'], v['roles'], v['ssh_client'], v['mac']) nodes.append(node) self.get_nodes_called = True return nodes
def _process_nodes(self, raw_nodes): nodes = [] for node in raw_nodes: name = node ip = raw_nodes[node]['ip'] status = 'active' id = None if self.ROLES[node] == 'controller': roles = 'controller' elif self.ROLES[node] == 'compute': roles = 'compute' ssh_client = ssh_utils.get_ssh_client(hostname=ip, username=self.installer_user, pkey_file=self.pkey_file) node = manager.Node(id, ip, name, status, roles, ssh_client) nodes.append(node) return nodes
def get_nodes(self): nodes = [] cmd = "source /home/stack/stackrc;openstack server list" output = self.installer_node.run_cmd(cmd) lines = output.rsplit('\n') if len(lines) < 4: logger.info("No nodes found in the deployment.") return None for line in lines: roles = [] if any(x in line for x in ['-----', 'Networks']): continue if 'controller' in line: roles.append(manager.Role.CONTROLLER) if 'compute' in line: roles.append(manager.Role.COMPUTE) if 'opendaylight' in line.lower(): roles.append(manager.Role.ODL) fields = line.split('|') id = re.sub('[!| ]', '', fields[1]).encode() name = re.sub('[!| ]', '', fields[2]).encode() status_node = re.sub('[!| ]', '', fields[3]).encode().lower() ip = re.sub('[!| ctlplane=]', '', fields[4]).encode() ssh_client = None if 'active' in status_node: status = manager.NodeStatus.STATUS_OK ssh_client = ssh_utils.get_ssh_client(hostname=ip, username='******', pkey_file=self.pkey_file) elif 'error' in status_node: status = manager.NodeStatus.STATUS_ERROR elif 'off' in status_node: status = manager.NodeStatus.STATUS_OFFLINE else: status = manager.NodeStatus.STATUS_INACTIVE node = manager.Node(id, ip, name, status, roles, ssh_client) nodes.append(node) return nodes
def _process_nodes(self, raw_nodes): nodes = [] for node in raw_nodes: name = node ip = raw_nodes[node]['ip'] # TODO when xci provides status and id of nodes add logic status = 'active' id = None if 'controller' in node: roles = 'controller' elif 'compute' in node: roles = 'compute' ssh_client = ssh_utils.get_ssh_client(hostname=ip, username=self.installer_user, pkey_file=self.pkey_file) node = manager.Node(id, ip, name, status, roles, ssh_client) nodes.append(node) return nodes
def get_nodes(self, options=None): if options and options['cluster'] and len(self.nodes) > 0: n = [] for node in self.nodes: if str(node.info['cluster']) == str(options['cluster']): n.append(node) return n try: # if we have retrieved previously all the nodes, don't do it again # This fails the first time when the constructor calls this method # therefore the try/except if len(self.nodes) > 0: return self.nodes except: pass nodes = [] cmd = 'fuel node' output = self.installer_node.run_cmd(cmd) lines = output.rsplit('\n') if len(lines) < 2: logger.info("No nodes found in the deployment.") return nodes # get fields indexes fields = lines[0].rsplit(' | ') index_id = -1 index_status = -1 index_name = -1 index_cluster = -1 index_ip = -1 index_mac = -1 index_roles = -1 index_online = -1 for i in range(len(fields)): if "group_id" in fields[i]: break elif "id" in fields[i]: index_id = i elif "status" in fields[i]: index_status = i elif "name" in fields[i]: index_name = i elif "cluster" in fields[i]: index_cluster = i elif "ip" in fields[i]: index_ip = i elif "mac" in fields[i]: index_mac = i elif "roles " in fields[i] and "pending_roles" not in fields[i]: index_roles = i elif "online" in fields[i]: index_online = i # order nodes info for i in range(2, len(lines)): fields = lines[i].rsplit(' | ') id = fields[index_id].strip().encode() ip = fields[index_ip].strip().encode() status_node = fields[index_status].strip().encode().lower() name = fields[index_name].strip().encode() roles_all = fields[index_roles].strip().encode().lower() roles = [ x for x in [ manager.Role.CONTROLLER, manager.Role.COMPUTE, manager.Role.ODL ] if x in roles_all ] dict = { "cluster": fields[index_cluster].strip().encode(), "mac": fields[index_mac].strip().encode(), "status_node": status_node, "online": fields[index_online].strip().encode() } ssh_client = None if status_node == 'ready': status = manager.NodeStatus.STATUS_OK proxy = { 'ip': self.installer_ip, 'username': self.installer_user, 'password': self.installer_pwd } ssh_client = ssh_utils.get_ssh_client(hostname=ip, username='******', proxy=proxy) elif 'error' in status_node: status = manager.NodeStatus.STATUS_ERROR elif 'off' in status_node: status = manager.NodeStatus.STATUS_OFFLINE elif 'discover' in status_node: status = manager.NodeStatus.STATUS_UNUSED else: status = manager.NodeStatus.STATUS_INACTIVE node = manager.Node(id, ip, name, status, roles, ssh_client, dict) if options and options['cluster']: if fields[index_cluster].strip() == options['cluster']: nodes.append(node) else: nodes.append(node) self.get_nodes_called = True return nodes