diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/opnfv/deployment/apex/adapter.py | 43 | ||||
-rw-r--r-- | modules/opnfv/deployment/example.py | 15 | ||||
-rw-r--r-- | modules/opnfv/deployment/fuel/adapter.py | 172 | ||||
-rw-r--r-- | modules/opnfv/deployment/manager.py | 70 | ||||
-rw-r--r-- | modules/opnfv/utils/ovs_logger.py | 2 |
5 files changed, 188 insertions, 114 deletions
diff --git a/modules/opnfv/deployment/apex/adapter.py b/modules/opnfv/deployment/apex/adapter.py index 1b81e781b..225e17438 100644 --- a/modules/opnfv/deployment/apex/adapter.py +++ b/modules/opnfv/deployment/apex/adapter.py @@ -25,9 +25,9 @@ class ApexAdapter(manager.DeploymentHandler): installer_pwd=None, pkey_file=pkey_file) - def nodes(self): + def get_nodes(self): nodes = [] - cmd = "source /home/stack/stackrc;nova list 2>/dev/null" + cmd = "source /home/stack/stackrc;openstack server list" output = self.installer_node.run_cmd(cmd) lines = output.rsplit('\n') if len(lines) < 4: @@ -35,28 +35,34 @@ class ApexAdapter(manager.DeploymentHandler): return None for line in lines: - if 'controller' in line: - roles = "controller" - elif 'compute' in line: - roles = "compute" - else: + roles = [] + if any(x in line for x in ['-----', 'Networks']): continue - if 'Daylight' in line: - roles += ", OpenDaylight" + 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]) - name = re.sub('[!| ]', '', fields[2]) - status_node = re.sub('[!| ]', '', fields[3]) - ip = re.sub('[!| ctlplane=]', '', fields[6]) + 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() - if status_node == 'ACTIVE': - status = manager.Node.STATUS_OK + ssh_client = None + if 'active' in status_node: + status = manager.NodeStatus.STATUS_OK ssh_client = ssh_utils.get_ssh_client(hostname=ip, username='heat-admin', 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.Node.STATUS_INACTIVE - ssh_client = None + status = manager.NodeStatus.STATUS_INACTIVE node = manager.Node(id, ip, name, status, roles, ssh_client) nodes.append(node) @@ -73,8 +79,9 @@ class ApexAdapter(manager.DeploymentHandler): "grep Description|sed 's/^.*\: //'") cmd_ver = ("sudo yum info opendaylight 2>/dev/null|" "grep Version|sed 's/^.*\: //'") + description = None for node in self.nodes: - if 'controller' in node.get_attribute('roles'): + if node.is_controller(): description = node.run_cmd(cmd_descr) version = node.run_cmd(cmd_ver) break diff --git a/modules/opnfv/deployment/example.py b/modules/opnfv/deployment/example.py index f45683260..3999a11c6 100644 --- a/modules/opnfv/deployment/example.py +++ b/modules/opnfv/deployment/example.py @@ -3,6 +3,7 @@ from opnfv.deployment import factory +print("########## APEX ##########") handler = factory.Factory.get_handler('apex', '192.168.122.135', 'stack', @@ -19,3 +20,17 @@ for node in nodes: (node.run_cmd('hostname'), node.ip)) print(handler.get_deployment_info()) + + +print("########## FUEL ##########") +handler = factory.Factory.get_handler('fuel', + '10.20.0.2', + 'root', + installer_pwd='r00tme') + +print(handler.get_deployment_info()) + +print("List of nodes in cluster 4:") +nodes = handler.get_nodes({'cluster': '4'}) +for node in nodes: + print(node) diff --git a/modules/opnfv/deployment/fuel/adapter.py b/modules/opnfv/deployment/fuel/adapter.py index d53966e82..aa5ad7a44 100644 --- a/modules/opnfv/deployment/fuel/adapter.py +++ b/modules/opnfv/deployment/fuel/adapter.py @@ -13,7 +13,7 @@ from opnfv.deployment import manager from opnfv.utils import opnfv_logger as logger from opnfv.utils import ssh_utils -logger = logger.Logger("FuelAdapter").getLogger() +logger = logger.Logger(__name__).getLogger() class FuelAdapter(manager.DeploymentHandler): @@ -40,7 +40,7 @@ class FuelAdapter(manager.DeploymentHandler): index_name = -1 index_release_id = -1 - for i in range(len(fields) - 1): + for i in range(len(fields)): if "id" in fields[i]: index_id = i elif "status" in fields[i]: @@ -51,7 +51,7 @@ class FuelAdapter(manager.DeploymentHandler): index_release_id = i # order env info - for i in range(2, len(lines) - 1): + for i in range(2, len(lines)): fields = lines[i].rsplit(' | ') dict = {"id": fields[index_id].strip(), "status": fields[index_status].strip(), @@ -61,88 +61,116 @@ class FuelAdapter(manager.DeploymentHandler): return environments - def nodes(self, options=None): + 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 None - else: - # 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(0, len(fields) - 1): - if "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]: - index_roles = i - elif "online" in fields[i]: - index_online = i - - # order nodes info - for i in range(2, len(lines) - 1): - fields = lines[i].rsplit(' | ') - - id = fields[index_id].strip(), - ip = fields[index_ip].strip() - status_node = fields[index_status].strip() - name = fields[index_name].strip() - roles = fields[index_roles].strip() - - dict = {"cluster": fields[index_cluster].strip(), - "mac": fields[index_mac].strip(), - "online": fields[index_online].strip()} - - if status_node == 'ready': - status = manager.Node.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='root', - proxy=proxy) - else: - status = manager.Node.STATUS_INACTIVE - ssh_client = None - - node = manager.Node( - id, ip, name, status, roles, ssh_client, dict) + 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]: + 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='root', + 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) - # TODO: Add support for Fuel cluster selection - ''' - if options and options['cluster']: - if fields[index_cluster].strip() == options['cluster']: - ''' - + self.get_nodes_called = True return nodes def get_openstack_version(self): cmd = 'source openrc;nova-manage version 2>/dev/null' version = None for node in self.nodes: - if 'controller' in node.get_attribute('roles'): + if node.is_controller(): version = node.run_cmd(cmd) break return version @@ -151,7 +179,7 @@ class FuelAdapter(manager.DeploymentHandler): cmd = "apt-cache show opendaylight|grep Version|sed 's/^.*\: //'" version = None for node in self.nodes: - if 'controller' in node.get_attribute('roles'): + if node.is_controller(): odl_version = node.run_cmd(cmd) if odl_version: version = 'OpenDaylight ' + odl_version diff --git a/modules/opnfv/deployment/manager.py b/modules/opnfv/deployment/manager.py index 9f77ff0a7..43a79488b 100644 --- a/modules/opnfv/deployment/manager.py +++ b/modules/opnfv/deployment/manager.py @@ -89,25 +89,35 @@ class Deployment(object): sdn_controller=self.deployment_info['sdn_controller']) for node in self.deployment_info['nodes']: - s += '\t\t{node_object}\n'.format(node_object=node) + s += '{node_object}\n'.format(node_object=node) return s -class Node(object): +class Role(): + CONTROLLER = 'controller' + COMPUTE = 'compute' + ODL = 'opendaylight' + ONOS = 'onos' + +class NodeStatus(): STATUS_OK = 'active' STATUS_INACTIVE = 'inactive' STATUS_OFFLINE = 'offline' - STATUS_FAILED = 'failed' + STATUS_ERROR = 'error' + STATUS_UNUSED = 'unused' + + +class Node(object): def __init__(self, id, ip, name, status, - roles, - ssh_client, + roles=[], + ssh_client=None, info={}): self.id = id self.ip = ip @@ -121,7 +131,7 @@ class Node(object): ''' SCP file from a node ''' - if self.status is not Node.STATUS_OK: + if self.status is not NodeStatus.STATUS_OK: logger.info("The node %s is not active" % self.ip) return 1 logger.info("Fetching %s from %s" % (src, self.ip)) @@ -137,7 +147,7 @@ class Node(object): ''' SCP file to a node ''' - if self.status is not Node.STATUS_OK: + if self.status is not NodeStatus.STATUS_OK: logger.info("The node %s is not active" % self.ip) return 1 logger.info("Copying %s to %s" % (src, self.ip)) @@ -153,9 +163,9 @@ class Node(object): ''' Run command remotely on a node ''' - if self.status is not Node.STATUS_OK: - logger.info("The node %s is not active" % self.ip) - return 1 + if self.status is not NodeStatus.STATUS_OK: + logger.error("The node %s is not active" % self.ip) + return None _, stdout, stderr = (self.ssh_client.exec_command(cmd)) error = stderr.readlines() if len(error) > 0: @@ -187,7 +197,7 @@ class Node(object): ''' Returns if the node is a controller ''' - if 'controller' in self.get_attribute('roles'): + if 'controller' in self.roles: return True return False @@ -195,12 +205,32 @@ class Node(object): ''' Returns if the node is a compute ''' - if 'compute' in self.get_attribute('roles'): + if 'compute' in self.roles: return True return False + def get_ovs_info(self): + ''' + Returns the ovs version installed + ''' + cmd = "ovs-vsctl --version|head -1| sed 's/^.*) //'" + return self.run_cmd(cmd) + def __str__(self): - return str(self.get_dict()) + return ''' + name: {name} + id: {id} + ip: {ip} + status: {status} + roles: {roles} + ovs: {ovs} + info: {info}'''.format(name=self.name, + id=self.id, + ip=self.ip, + status=self.status, + roles=self.roles, + ovs=self.get_ovs_info(), + info=self.info) class DeploymentHandler(object): @@ -236,14 +266,14 @@ class DeploymentHandler(object): self.installer_node = Node(id='', ip=installer_ip, name=installer, - status='active', + status=NodeStatus.STATUS_OK, ssh_client=self.installer_connection, roles='installer node') else: raise Exception( 'Cannot establish connection to the installer node!') - self.nodes = self.nodes() + self.nodes = self.get_nodes() @abstractmethod def get_openstack_version(self): @@ -267,18 +297,12 @@ class DeploymentHandler(object): raise Exception(DeploymentHandler.FUNCTION_NOT_IMPLEMENTED) @abstractmethod - def nodes(self, options=None): + def get_nodes(self, options=None): ''' Generates a list of all the nodes in the deployment ''' raise Exception(DeploymentHandler.FUNCTION_NOT_IMPLEMENTED) - def get_nodes(self, options=None): - ''' - Returns the list of Node objects - ''' - return self.nodes - def get_installer_node(self): ''' Returns the installer node object @@ -296,4 +320,4 @@ class DeploymentHandler(object): pod=os.getenv('NODE_NAME', 'Unknown'), openstack_version=self.get_openstack_version(), sdn_controller=self.get_sdn_version(), - nodes=self.nodes) + nodes=self.get_nodes()) diff --git a/modules/opnfv/utils/ovs_logger.py b/modules/opnfv/utils/ovs_logger.py index 75b4cec80..d650eb9ab 100644 --- a/modules/opnfv/utils/ovs_logger.py +++ b/modules/opnfv/utils/ovs_logger.py @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import opnfv.utils.OPNFVLogger as OPNFVLogger +import opnfv.utils.opnfv_logger as OPNFVLogger import os import time import shutil |