From 10eef5153d7d45889f36b330bda20478b7bad8a2 Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Fri, 3 Feb 2017 20:45:46 +0100 Subject: [deployment_handler] Remove current scripts This work has been done from scratch following a better OO approach and better structured. The library is renamed by 'deploment handler' Change-Id: I7af2963ebb4e33d90481e91cabfc015718b0bb68 Signed-off-by: jose.lausuch --- opnfv/installer_adapters/InstallerHandler.py | 85 -------- opnfv/installer_adapters/__init__.py | 0 opnfv/installer_adapters/apex/ApexAdapter.py | 154 -------------- opnfv/installer_adapters/apex/__init__.py | 0 opnfv/installer_adapters/apex/example.py | 16 -- opnfv/installer_adapters/compass/CompassAdapter.py | 32 --- opnfv/installer_adapters/compass/__init__.py | 0 opnfv/installer_adapters/daisy/DaisyAdapter.py | 32 --- opnfv/installer_adapters/daisy/__init__.py | 0 opnfv/installer_adapters/fuel/FuelAdapter.py | 236 --------------------- opnfv/installer_adapters/fuel/__init__.py | 0 opnfv/installer_adapters/fuel/example.py | 22 -- opnfv/installer_adapters/joid/JoidAdapter.py | 32 --- opnfv/installer_adapters/joid/__init__.py | 0 14 files changed, 609 deletions(-) delete mode 100644 opnfv/installer_adapters/InstallerHandler.py delete mode 100644 opnfv/installer_adapters/__init__.py delete mode 100644 opnfv/installer_adapters/apex/ApexAdapter.py delete mode 100644 opnfv/installer_adapters/apex/__init__.py delete mode 100644 opnfv/installer_adapters/apex/example.py delete mode 100644 opnfv/installer_adapters/compass/CompassAdapter.py delete mode 100644 opnfv/installer_adapters/compass/__init__.py delete mode 100644 opnfv/installer_adapters/daisy/DaisyAdapter.py delete mode 100644 opnfv/installer_adapters/daisy/__init__.py delete mode 100644 opnfv/installer_adapters/fuel/FuelAdapter.py delete mode 100644 opnfv/installer_adapters/fuel/__init__.py delete mode 100644 opnfv/installer_adapters/fuel/example.py delete mode 100644 opnfv/installer_adapters/joid/JoidAdapter.py delete mode 100644 opnfv/installer_adapters/joid/__init__.py diff --git a/opnfv/installer_adapters/InstallerHandler.py b/opnfv/installer_adapters/InstallerHandler.py deleted file mode 100644 index 6c43a46..0000000 --- a/opnfv/installer_adapters/InstallerHandler.py +++ /dev/null @@ -1,85 +0,0 @@ -############################################################################## -# 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 -############################################################################## - -from opnfv.installer_adapters.fuel.FuelAdapter import FuelAdapter -from opnfv.installer_adapters.apex.ApexAdapter import ApexAdapter -from opnfv.installer_adapters.compass.CompassAdapter import CompassAdapter -from opnfv.installer_adapters.joid.JoidAdapter import JoidAdapter -from opnfv.installer_adapters.daisy.DaisyAdapter import DaisyAdapter - - -INSTALLERS = ["fuel", "apex", "compass", "joid", "daisy"] - - -class InstallerHandler: - - def __init__(self, - installer, - installer_ip, - installer_user, - installer_pwd=None, - private_key_file=None): - self.installer = installer.lower() - self.installer_ip = installer_ip - self.installer_user = installer_user - self.installer_pwd = installer_pwd - self.private_key_file = private_key_file - - if self.installer == INSTALLERS[0]: - self.InstallerAdapter = FuelAdapter(self.installer_ip, - self.installer_user, - self.installer_pwd) - elif self.installer == INSTALLERS[1]: - self.InstallerAdapter = ApexAdapter(installer_ip=self.installer_ip, - user=self.installer_user, - pkey_file=self.private_key_file) - elif self.installer == INSTALLERS[2]: - self.InstallerAdapter = CompassAdapter(self.installer_ip) - elif self.installer == INSTALLERS[3]: - self.InstallerAdapter = JoidAdapter(self.installer_ip) - elif self.installer == INSTALLERS[4]: - self.InstallerAdapter = DaisyAdapter(self.installer_ip) - else: - print("Installer %s is not valid. " - "Please use one of the followings: %s" - % (self.installer, INSTALLERS)) - exit(1) - - def get_deployment_info(self): - return self.InstallerAdapter.get_deployment_info() - - def get_nodes(self, options=None): - return self.InstallerAdapter.get_nodes(options=options) - - def get_controller_ips(self, options=None): - return self.InstallerAdapter.get_controller_ips(options=options) - - def get_compute_ips(self, options=None): - return self.InstallerAdapter.get_compute_ips(options=options) - - def get_file_from_installer(self, - remote_path, - local_path, - options=None): - return self.InstallerAdapter.get_file_from_installer(remote_path, - local_path, - options=options) - - def get_file_from_controller(self, - remote_path, - local_path, - ip=None, - options=None): - return self.InstallerAdapter.get_file_from_controller(remote_path, - local_path, - ip=ip, - options=options) - - def get_all(self): - pass diff --git a/opnfv/installer_adapters/__init__.py b/opnfv/installer_adapters/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/opnfv/installer_adapters/apex/ApexAdapter.py b/opnfv/installer_adapters/apex/ApexAdapter.py deleted file mode 100644 index 29637d7..0000000 --- a/opnfv/installer_adapters/apex/ApexAdapter.py +++ /dev/null @@ -1,154 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 os -import re - -import opnfv.utils.SSHUtils as ssh_utils -import opnfv.utils.OPNFVLogger as logger - - -class ApexAdapter: - - def __init__(self, installer_ip, pkey_file, user="stack"): - self.installer_ip = installer_ip - self.installer_user = user - self.pkey_file = pkey_file - self.installer_connection = ssh_utils.get_ssh_client( - self.installer_ip, - self.installer_user, - pkey_file=self.pkey_file) - self.logger = logger.Logger("ApexHandler").getLogger() - - def runcmd_apex_installer(self, cmd): - _, stdout, stderr = (self.installer_connection.exec_command(cmd)) - error = stderr.readlines() - if len(error) > 0: - self.logger.error("error %s" % ''.join(error)) - return error - output = ''.join(stdout.readlines()) - return output - - def get_nodes(self): - nodes = [] - output = self.runcmd_apex_installer( - "source /home/stack/stackrc;nova list") - lines = output.rsplit('\n') - if len(lines) < 4: - self.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('|') - dict = {"id": re.sub('[!| ]', '', fields[1]), - "roles": roles, - "name": re.sub('[!| ]', '', fields[2]), - "status": re.sub('[!| ]', '', fields[3]), - "ip": re.sub('[!| ctlplane=]', '', fields[6])} - nodes.append(dict) - - return nodes - - def get_deployment_info(self): - str = "Deployment details:\n" - str += "\tINSTALLER: Apex\n" - str += ("\tSCENARIO: %s\n" % - os.getenv('DEPLOY_SCENARIO', 'Unknown')) - sdn = "None" - - nodes = self.get_nodes() - if nodes is None: - self.logger.info("No nodes found in the deployment.") - return - num_nodes = len(nodes) - num_controllers = 0 - num_computes = 0 - for node in nodes: - if 'controller' in node['roles']: - num_controllers += 1 - if 'compute' in node['roles']: - num_computes += 1 - if 'Daylight' in node['name']: - sdn = 'OpenDaylight' - - ha = str(num_controllers >= 3) - - str += "\tHA: %s\n" % ha - str += "\tNUM.NODES: %s\n" % num_nodes - str += "\tCONTROLLERS: %s\n" % num_controllers - str += "\tCOMPUTES: %s\n" % num_computes - str += "\tSDN CONTR.: %s\n\n" % sdn - - str += "\tNODES:\n" - for node in nodes: - str += ("\t ID: %s\n" % node['id']) - str += ("\t Name: %s\n" % node['name']) - str += ("\t Roles: %s\n" % node['roles']) - str += ("\t Status: %s\n" % node['status']) - str += ("\t IP: %s\n\n" % node['ip']) - - return str - - def get_controller_ips(self, options=None): - nodes = self.get_nodes() - controllers = [] - for node in nodes: - if "controller" in node["roles"]: - controllers.append(node['ip']) - return controllers - - def get_compute_ips(self, options=None): - nodes = self.get_nodes() - computes = [] - for node in nodes: - if "compute" in node["roles"]: - computes.append(node['ip']) - return computes - - def get_file_from_installer(self, remote_path, local_path, options=None): - self.logger.debug("Fetching %s from Undercloud %s" % - (remote_path, self.installer_ip)) - get_file_result = ssh_utils.get_file(self.installer_connection, - remote_path, - local_path) - if get_file_result is None: - self.logger.error("SFTP failed to retrieve the file.") - return 1 - self.logger.info("%s successfully copied from Undercloud to %s" % - (remote_path, local_path)) - - def get_file_from_controller(self, - remote_path, - local_path, - ip=None, - options=None): - if ip is None: - controllers = self.get_controller_ips() - ip = controllers[0] - - connection = ssh_utils.get_ssh_client(ip, - 'heat-admin', - pkey_file=self.pkey_file) - - get_file_result = ssh_utils.get_file(connection, - remote_path, - local_path) - if get_file_result is None: - self.logger.error("SFTP failed to retrieve the file.") - return 1 - self.logger.info("%s successfully copied from %s to %s" % - (remote_path, ip, local_path)) diff --git a/opnfv/installer_adapters/apex/__init__.py b/opnfv/installer_adapters/apex/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/opnfv/installer_adapters/apex/example.py b/opnfv/installer_adapters/apex/example.py deleted file mode 100644 index c8c4737..0000000 --- a/opnfv/installer_adapters/apex/example.py +++ /dev/null @@ -1,16 +0,0 @@ -# This is an example of usage of this Tool -# Author: Jose Lausuch (jose.lausuch@ericsson.com) - -import opnfv.installer_adapters.InstallerHandler as ins_handler - -apex_handler = ins_handler.InstallerHandler(installer='apex', - installer_ip='192.168.122.135', - installer_user='stack', - private_key_file='/root/.ssh/id_rsa') -apex_handler.get_file_from_installer( - '/home/stack/overcloudrc', './overcloudrc') - -print("\n%s\n" % apex_handler.get_deployment_info()) - -apex_handler.get_file_from_controller( - '/etc/resolv.conf', './resolv.conf') diff --git a/opnfv/installer_adapters/compass/CompassAdapter.py b/opnfv/installer_adapters/compass/CompassAdapter.py deleted file mode 100644 index 47cbc64..0000000 --- a/opnfv/installer_adapters/compass/CompassAdapter.py +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 -############################################################################## - - -class CompassAdapter: - - def __init__(self, installer_ip): - self.installer_ip = installer_ip - - def get_deployment_info(self): - pass - - def get_nodes(self): - pass - - def get_controller_ips(self): - pass - - def get_compute_ips(self): - pass - - def get_file_from_installer(self, origin, target, options=None): - pass - - def get_file_from_controller(self, origin, target, ip=None, options=None): - pass diff --git a/opnfv/installer_adapters/compass/__init__.py b/opnfv/installer_adapters/compass/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/opnfv/installer_adapters/daisy/DaisyAdapter.py b/opnfv/installer_adapters/daisy/DaisyAdapter.py deleted file mode 100644 index 9b06f4c..0000000 --- a/opnfv/installer_adapters/daisy/DaisyAdapter.py +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 -############################################################################## - - -class DaisyAdapter: - - def __init__(self, installer_ip): - self.installer_ip = installer_ip - - def get_deployment_info(self): - pass - - def get_nodes(self): - pass - - def get_controller_ips(self): - pass - - def get_compute_ips(self): - pass - - def get_file_from_installer(self, origin, target, options=None): - pass - - def get_file_from_controller(self, origin, target, ip=None, options=None): - pass diff --git a/opnfv/installer_adapters/daisy/__init__.py b/opnfv/installer_adapters/daisy/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/opnfv/installer_adapters/fuel/FuelAdapter.py b/opnfv/installer_adapters/fuel/FuelAdapter.py deleted file mode 100644 index 8ed8f89..0000000 --- a/opnfv/installer_adapters/fuel/FuelAdapter.py +++ /dev/null @@ -1,236 +0,0 @@ -############################################################################## -# Copyright (c) 2016 Ericsson AB and others. -# Author: Jose Lausuch (jose.lausuch@ericsson.com) -# George Paraskevopoulos (geopar@intracom-telecom.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 opnfv.utils.SSHUtils as ssh_utils -import opnfv.utils.OPNFVLogger as logger - - -class FuelAdapter: - - def __init__(self, installer_ip, user="root", password="r00tme"): - self.installer_ip = installer_ip - self.installer_user = user - self.installer_password = password - self.installer_connection = ssh_utils.get_ssh_client( - installer_ip, - self.installer_user, - password=self.installer_password) - self.logger = logger.Logger("FuelHandler").getLogger() - - def runcmd_fuel_installer(self, cmd): - _, stdout, stderr = (self - .installer_connection - .exec_command(cmd)) - error = stderr.readlines() - if len(error) > 0: - self.logger.error("error %s" % ''.join(error)) - return error - output = ''.join(stdout.readlines()) - return output - - def runcmd_fuel_nodes(self): - return self.runcmd_fuel_installer('fuel nodes') - - def runcmd_fuel_env(self): - return self.runcmd_fuel_installer('fuel env') - - def get_clusters(self): - environments = [] - output = self.runcmd_fuel_env() - lines = output.rsplit('\n') - if len(lines) < 2: - self.logger.infp("No environments found in the deployment.") - return None - else: - fields = lines[0].rsplit(' | ') - - index_id = -1 - index_status = -1 - index_name = -1 - index_release_id = -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 "release_id" in fields[i]: - index_release_id = i - - # order env info - for i in range(2, len(lines) - 1): - fields = lines[i].rsplit(' | ') - dict = {"id": fields[index_id].strip(), - "status": fields[index_status].strip(), - "name": fields[index_name].strip(), - "release_id": fields[index_release_id].strip()} - environments.append(dict) - - return environments - - def get_nodes(self, options=None): - nodes = [] - output = self.runcmd_fuel_nodes() - lines = output.rsplit('\n') - if len(lines) < 2: - self.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(' | ') - dict = {"id": fields[index_id].strip(), - "status": fields[index_status].strip(), - "name": fields[index_name].strip(), - "cluster": fields[index_cluster].strip(), - "ip": fields[index_ip].strip(), - "mac": fields[index_mac].strip(), - "roles": fields[index_roles].strip(), - "online": fields[index_online].strip()} - if options and options['cluster']: - if fields[index_cluster].strip() == options['cluster']: - nodes.append(dict) - else: - nodes.append(dict) - - return nodes - - def get_controller_ips(self, options): - nodes = self.get_nodes(options=options) - controllers = [] - for node in nodes: - if "controller" in node["roles"]: - controllers.append(node['ip']) - return controllers - - def get_compute_ips(self, options=None): - nodes = self.get_nodes(options=options) - computes = [] - for node in nodes: - if "compute" in node["roles"]: - computes.append(node['ip']) - return computes - - def get_deployment_info(self): - str = "Deployment details:\n" - str += "\tInstaller: Fuel\n" - str += "\tScenario: Unknown\n" - sdn = "None" - clusters = self.get_clusters() - str += "\tN.Clusters: %s\n" % len(clusters) - for cluster in clusters: - cluster_dic = {'cluster': cluster['id']} - str += "\tCluster info:\n" - str += "\t ID: %s\n" % cluster['id'] - str += "\t NAME: %s\n" % cluster['name'] - str += "\t STATUS: %s\n" % cluster['status'] - nodes = self.get_nodes(options=cluster_dic) - num_nodes = len(nodes) - for node in nodes: - if "opendaylight" in node['roles']: - sdn = "OpenDaylight" - elif "onos" in node['roles']: - sdn = "ONOS" - num_controllers = len( - self.get_controller_ips(options=cluster_dic)) - num_computes = len(self.get_compute_ips(options=cluster_dic)) - ha = False - if num_controllers > 1: - ha = True - - str += "\t HA: %s\n" % ha - str += "\t NUM.NODES: %s\n" % num_nodes - str += "\t CONTROLLERS: %s\n" % num_controllers - str += "\t COMPUTES: %s\n" % num_computes - str += "\t SDN CONTR.: %s\n\n" % sdn - str += self.runcmd_fuel_nodes() - return str - - def get_file_from_installer(self, remote_path, local_path, options=None): - self.logger.debug("Fetching %s from %s" % - (remote_path, self.installer_ip)) - get_file_result = ssh_utils.get_file(self.installer_connection, - remote_path, - local_path) - if get_file_result is None: - self.logger.error("SFTP failed to retrieve the file.") - return 1 - self.logger.info("%s successfully copied from Fuel to %s" % - (remote_path, local_path)) - - def get_file_from_controller(self, - remote_path, - local_path, - ip=None, - user='root', - options=None): - if ip is None: - controllers = self.get_controller_ips(options=options) - if len(controllers) == 0: - self.logger.info("No controllers found in the deployment.") - return 1 - else: - target_ip = controllers[0] - else: - target_ip = ip - - installer_proxy = { - 'ip': self.installer_ip, - 'username': self.installer_user, - 'password': self.installer_password - } - controller_conn = ssh_utils.get_ssh_client( - target_ip, - user, - proxy=installer_proxy) - - self.logger.debug("Fetching %s from %s" % - (remote_path, target_ip)) - - get_file_result = ssh_utils.get_file(controller_conn, - remote_path, - local_path) - if get_file_result is None: - self.logger.error("SFTP failed to retrieve the file.") - return 1 - self.logger.info("%s successfully copied from %s to %s" % - (remote_path, target_ip, local_path)) diff --git a/opnfv/installer_adapters/fuel/__init__.py b/opnfv/installer_adapters/fuel/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/opnfv/installer_adapters/fuel/example.py b/opnfv/installer_adapters/fuel/example.py deleted file mode 100644 index 7fea4df..0000000 --- a/opnfv/installer_adapters/fuel/example.py +++ /dev/null @@ -1,22 +0,0 @@ -# This is an example of usage of this Tool -# Author: Jose Lausuch (jose.lausuch@ericsson.com) - -import opnfv.installer_adapters.InstallerHandler as ins_handler - -fuel_handler = ins_handler.InstallerHandler(installer='fuel', - installer_ip='10.20.0.2', - installer_user='root', - installer_pwd='r00tme') -print("Nodes in cluster 1:\n%s\n" % - fuel_handler.get_nodes(options={'cluster': '1'})) -print("Nodes in cluster 2:\n%s\n" % - fuel_handler.get_nodes(options={'cluster': '2'})) -print("Nodes:\n%s\n" % fuel_handler.get_nodes()) -print("Controller nodes:\n%s\n" % fuel_handler.get_controller_ips()) -print("Compute nodes:\n%s\n" % fuel_handler.get_compute_ips()) -print("\n%s\n" % fuel_handler.get_deployment_info()) -fuel_handler.get_file_from_installer('/root/deploy/dea.yaml', './dea.yaml') -fuel_handler.get_file_from_controller( - '/etc/neutron/neutron.conf', './neutron.conf') -fuel_handler.get_file_from_controller( - '/root/openrc', './openrc') diff --git a/opnfv/installer_adapters/joid/JoidAdapter.py b/opnfv/installer_adapters/joid/JoidAdapter.py deleted file mode 100644 index be8c2eb..0000000 --- a/opnfv/installer_adapters/joid/JoidAdapter.py +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 -############################################################################## - - -class JoidAdapter: - - def __init__(self, installer_ip): - self.installer_ip = installer_ip - - def get_deployment_info(self): - pass - - def get_nodes(self): - pass - - def get_controller_ips(self): - pass - - def get_compute_ips(self): - pass - - def get_file_from_installer(self, origin, target, options=None): - pass - - def get_file_from_controller(self, origin, target, ip=None, options=None): - pass diff --git a/opnfv/installer_adapters/joid/__init__.py b/opnfv/installer_adapters/joid/__init__.py deleted file mode 100644 index e69de29..0000000 -- cgit 1.2.3-korg