diff options
author | jose.lausuch <jose.lausuch@ericsson.com> | 2017-02-06 22:10:00 +0100 |
---|---|---|
committer | jose.lausuch <jose.lausuch@ericsson.com> | 2017-02-09 14:09:03 +0100 |
commit | ba25afb8b30e8f757ea1a6a2819d30dd1644e5d3 (patch) | |
tree | 978efa55bd79a3609db99a998c76e11a56a1ee4e /modules/opnfv/deployment/apex | |
parent | 8c17dd593620d962011cb4e810634182cba1d100 (diff) |
[deployment handler] Refactor the old installer_handler
This is a util library to interact with the
deployment regardless of the installer.
Objects:
- Deployment
- Node
- DeploymentHandler
- ApexAdapter
- FuelAdapter
- Factory
The installer adapters implement some of the
abstract functions of DeploymentHandler class
that can't be generalized.
Printout of example.py:
http://pastebin.com/raw/SF3A1fee
More info: JIRA: RELENG-149
Change-Id: I5c9e94459d5be0bfad6ffac29908a8cfc7ba919c
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
Diffstat (limited to 'modules/opnfv/deployment/apex')
-rw-r--r-- | modules/opnfv/deployment/apex/__init__.py | 0 | ||||
-rw-r--r-- | modules/opnfv/deployment/apex/adapter.py | 93 |
2 files changed, 93 insertions, 0 deletions
diff --git a/modules/opnfv/deployment/apex/__init__.py b/modules/opnfv/deployment/apex/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/modules/opnfv/deployment/apex/__init__.py diff --git a/modules/opnfv/deployment/apex/adapter.py b/modules/opnfv/deployment/apex/adapter.py new file mode 100644 index 000000000..1b81e781b --- /dev/null +++ b/modules/opnfv/deployment/apex/adapter.py @@ -0,0 +1,93 @@ +############################################################################## +# Copyright (c) 2017 Ericsson AB and others. +# Author: Jose Lausuch (jose.lausuch@ericsson.com) +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import re + +from opnfv.deployment import manager +from opnfv.utils import opnfv_logger as logger +from opnfv.utils import ssh_utils + +logger = logger.Logger(__name__).getLogger() + + +class ApexAdapter(manager.DeploymentHandler): + + def __init__(self, installer_ip, installer_user, pkey_file): + super(ApexAdapter, self).__init__(installer='apex', + installer_ip=installer_ip, + installer_user=installer_user, + installer_pwd=None, + pkey_file=pkey_file) + + def nodes(self): + nodes = [] + cmd = "source /home/stack/stackrc;nova list 2>/dev/null" + 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: + if 'controller' in line: + roles = "controller" + elif 'compute' in line: + roles = "compute" + else: + continue + if 'Daylight' in line: + roles += ", OpenDaylight" + 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]) + + if status_node == 'ACTIVE': + status = manager.Node.STATUS_OK + ssh_client = ssh_utils.get_ssh_client(hostname=ip, + username='heat-admin', + pkey_file=self.pkey_file) + else: + status = manager.Node.STATUS_INACTIVE + ssh_client = None + + node = manager.Node(id, ip, name, status, roles, ssh_client) + nodes.append(node) + + return nodes + + def get_openstack_version(self): + cmd = 'source overcloudrc;sudo nova-manage version' + result = self.installer_node.run_cmd(cmd) + return result + + def get_sdn_version(self): + cmd_descr = ("sudo yum info opendaylight 2>/dev/null|" + "grep Description|sed 's/^.*\: //'") + cmd_ver = ("sudo yum info opendaylight 2>/dev/null|" + "grep Version|sed 's/^.*\: //'") + for node in self.nodes: + if 'controller' in node.get_attribute('roles'): + description = node.run_cmd(cmd_descr) + version = node.run_cmd(cmd_ver) + break + + if description is None: + return None + else: + return description + ':' + version + + def get_deployment_status(self): + cmd = 'source stackrc;openstack stack list|grep CREATE_COMPLETE' + result = self.installer_node.run_cmd(cmd) + if result is None or len(result) == 0: + return 'failed' + else: + return 'active' |