summaryrefslogtreecommitdiffstats
path: root/modules/opnfv
diff options
context:
space:
mode:
Diffstat (limited to 'modules/opnfv')
-rw-r--r--modules/opnfv/deployment/__init__.py (renamed from modules/opnfv/installer_adapters/__init__.py)0
-rw-r--r--modules/opnfv/deployment/apex/__init__.py (renamed from modules/opnfv/installer_adapters/apex/__init__.py)0
-rw-r--r--modules/opnfv/deployment/apex/adapter.py100
-rw-r--r--modules/opnfv/deployment/example.py36
-rw-r--r--modules/opnfv/deployment/factory.py45
-rw-r--r--modules/opnfv/deployment/fuel/__init__.py (renamed from modules/opnfv/installer_adapters/compass/__init__.py)0
-rw-r--r--modules/opnfv/deployment/fuel/adapter.py199
-rw-r--r--modules/opnfv/deployment/manager.py386
-rw-r--r--modules/opnfv/installer_adapters/InstallerHandler.py81
-rw-r--r--modules/opnfv/installer_adapters/apex/ApexAdapter.py32
-rw-r--r--modules/opnfv/installer_adapters/compass/CompassAdapter.py32
-rw-r--r--modules/opnfv/installer_adapters/daisy/DaisyAdapter.py32
-rw-r--r--modules/opnfv/installer_adapters/daisy/__init__.py0
-rw-r--r--modules/opnfv/installer_adapters/fuel/FuelAdapter.py236
-rw-r--r--modules/opnfv/installer_adapters/fuel/__init__.py0
-rw-r--r--modules/opnfv/installer_adapters/fuel/example.py22
-rw-r--r--modules/opnfv/installer_adapters/joid/JoidAdapter.py32
-rw-r--r--modules/opnfv/installer_adapters/joid/__init__.py0
-rw-r--r--modules/opnfv/utils/Credentials.py2
-rw-r--r--modules/opnfv/utils/constants.py1
-rw-r--r--modules/opnfv/utils/opnfv_logger.py (renamed from modules/opnfv/utils/OPNFVLogger.py)0
-rw-r--r--modules/opnfv/utils/ovs_logger.py27
-rw-r--r--modules/opnfv/utils/ssh_utils.py (renamed from modules/opnfv/utils/SSHUtils.py)40
23 files changed, 805 insertions, 498 deletions
diff --git a/modules/opnfv/installer_adapters/__init__.py b/modules/opnfv/deployment/__init__.py
index e69de29bb..e69de29bb 100644
--- a/modules/opnfv/installer_adapters/__init__.py
+++ b/modules/opnfv/deployment/__init__.py
diff --git a/modules/opnfv/installer_adapters/apex/__init__.py b/modules/opnfv/deployment/apex/__init__.py
index e69de29bb..e69de29bb 100644
--- a/modules/opnfv/installer_adapters/apex/__init__.py
+++ 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..225e17438
--- /dev/null
+++ b/modules/opnfv/deployment/apex/adapter.py
@@ -0,0 +1,100 @@
+##############################################################################
+# 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 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='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.NodeStatus.STATUS_INACTIVE
+
+ 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/^.*\: //'")
+ description = None
+ for node in self.nodes:
+ if node.is_controller():
+ 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'
diff --git a/modules/opnfv/deployment/example.py b/modules/opnfv/deployment/example.py
new file mode 100644
index 000000000..3999a11c6
--- /dev/null
+++ b/modules/opnfv/deployment/example.py
@@ -0,0 +1,36 @@
+# This is an example of usage of this Tool
+# Author: Jose Lausuch (jose.lausuch@ericsson.com)
+
+from opnfv.deployment import factory
+
+print("########## APEX ##########")
+handler = factory.Factory.get_handler('apex',
+ '192.168.122.135',
+ 'stack',
+ pkey_file='/root/.ssh/id_rsa')
+
+
+installer_node = handler.get_installer_node()
+print("Hello, I am node '%s'" % installer_node.run_cmd('hostname'))
+installer_node.get_file('/home/stack/overcloudrc', './overcloudrc')
+
+nodes = handler.get_nodes()
+for node in nodes:
+ print("Hello, I am node '%s' and my ip is %s." %
+ (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/factory.py b/modules/opnfv/deployment/factory.py
new file mode 100644
index 000000000..1ccee4e80
--- /dev/null
+++ b/modules/opnfv/deployment/factory.py
@@ -0,0 +1,45 @@
+##############################################################################
+# 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.deployment.apex import adapter as apex_adapter
+from opnfv.deployment.fuel import adapter as fuel_adapter
+from opnfv.utils import opnfv_logger as logger
+
+logger = logger.Logger(__name__).getLogger()
+
+
+class Factory(object):
+
+ INSTALLERS = ["fuel", "apex", "compass", "joid", "daisy"]
+
+ def __init__(self):
+ pass
+
+ @staticmethod
+ def get_handler(installer,
+ installer_ip,
+ installer_user,
+ installer_pwd=None,
+ pkey_file=None):
+
+ if installer not in Factory.INSTALLERS:
+ raise Exception("This is not an OPNFV installer.")
+
+ if installer.lower() == "apex":
+ return apex_adapter.ApexAdapter(installer_ip=installer_ip,
+ installer_user=installer_user,
+ pkey_file=pkey_file)
+ elif installer.lower() == "fuel":
+ return fuel_adapter.FuelAdapter(installer_ip=installer_ip,
+ installer_user=installer_user,
+ installer_pwd=installer_pwd)
+ else:
+ raise Exception("Installer adapter is not implemented for "
+ "the given installer.")
diff --git a/modules/opnfv/installer_adapters/compass/__init__.py b/modules/opnfv/deployment/fuel/__init__.py
index e69de29bb..e69de29bb 100644
--- a/modules/opnfv/installer_adapters/compass/__init__.py
+++ b/modules/opnfv/deployment/fuel/__init__.py
diff --git a/modules/opnfv/deployment/fuel/adapter.py b/modules/opnfv/deployment/fuel/adapter.py
new file mode 100644
index 000000000..a217767ba
--- /dev/null
+++ b/modules/opnfv/deployment/fuel/adapter.py
@@ -0,0 +1,199 @@
+##############################################################################
+# Copyright (c) 2017 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
+##############################################################################
+
+
+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 FuelAdapter(manager.DeploymentHandler):
+
+ def __init__(self, installer_ip, installer_user, installer_pwd):
+ super(FuelAdapter, self).__init__(installer='fuel',
+ installer_ip=installer_ip,
+ installer_user=installer_user,
+ installer_pwd=installer_pwd,
+ pkey_file=None)
+
+ def _get_clusters(self):
+ environments = []
+ output = self.runcmd_fuel_env()
+ lines = output.rsplit('\n')
+ if len(lines) < 2:
+ logger.info("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(len(fields)):
+ 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)):
+ 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):
+
+ 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='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)
+
+ 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 node.is_controller() and node.is_active():
+ version = node.run_cmd(cmd)
+ break
+ return version
+
+ def get_sdn_version(self):
+ cmd = "apt-cache policy opendaylight|grep Installed"
+ version = None
+ for node in self.nodes:
+ if manager.Role.ODL in node.roles and node.is_active():
+ odl_version = node.run_cmd(cmd)
+ if odl_version:
+ version = 'OpenDaylight ' + odl_version.split(' ')[-1]
+ break
+ return version
+
+ def get_deployment_status(self):
+ cmd = "fuel env|tail -1|awk '{print $3}'"
+ result = self.installer_node.run_cmd(cmd)
+ if result is None or len(result) == 0:
+ return 'unknown'
+ elif 'operational' in result:
+ return 'active'
+ elif 'deploy' in result:
+ return 'deploying'
+ else:
+ return 'active'
diff --git a/modules/opnfv/deployment/manager.py b/modules/opnfv/deployment/manager.py
new file mode 100644
index 000000000..df735f157
--- /dev/null
+++ b/modules/opnfv/deployment/manager.py
@@ -0,0 +1,386 @@
+##############################################################################
+# 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 abc import abstractmethod
+import os
+
+
+from opnfv.utils import opnfv_logger as logger
+from opnfv.utils import ssh_utils
+
+logger = logger.Logger(__name__).getLogger()
+
+
+class Deployment(object):
+
+ def __init__(self,
+ installer,
+ installer_ip,
+ scenario,
+ pod,
+ status,
+ openstack_version,
+ sdn_controller,
+ nodes=None):
+
+ self.deployment_info = {
+ 'installer': installer,
+ 'installer_ip': installer_ip,
+ 'scenario': scenario,
+ 'pod': pod,
+ 'status': status,
+ 'openstack_version': openstack_version,
+ 'sdn_controller': sdn_controller,
+ 'nodes': nodes
+ }
+
+ def _get_openstack_release(self):
+ '''
+ Translates an openstack version into the release name
+ '''
+ os_versions = {
+ '12': 'Liberty',
+ '13': 'Mitaka',
+ '14': 'Newton',
+ '15': 'Ocata',
+ '16': 'Pike',
+ '17': 'Queens'
+ }
+ try:
+ version = self.deployment_info['openstack_version'].split('.')[0]
+ name = os_versions[version]
+ return name
+ except Exception:
+ return 'Unknown release'
+
+ def get_dict(self):
+ '''
+ Returns a dictionary will all the attributes
+ '''
+ return self.deployment_info
+
+ def __str__(self):
+ '''
+ Override of the str method
+ '''
+ s = '''
+ INSTALLER: {installer}
+ SCENARIO: {scenario}
+ INSTALLER IP: {installer_ip}
+ POD: {pod}
+ STATUS: {status}
+ OPENSTACK: {openstack_version} ({openstack_release})
+ SDN: {sdn_controller}
+ NODES:
+ '''.format(installer=self.deployment_info['installer'],
+ scenario=self.deployment_info['scenario'],
+ installer_ip=self.deployment_info['installer_ip'],
+ pod=self.deployment_info['pod'],
+ status=self.deployment_info['status'],
+ openstack_version=self.deployment_info[
+ 'openstack_version'],
+ openstack_release=self._get_openstack_release(),
+ sdn_controller=self.deployment_info['sdn_controller'])
+
+ for node in self.deployment_info['nodes']:
+ s += '{node_object}\n'.format(node_object=node)
+
+ return s
+
+
+class Role():
+ INSTALLER = 'installer'
+ CONTROLLER = 'controller'
+ COMPUTE = 'compute'
+ ODL = 'opendaylight'
+ ONOS = 'onos'
+
+
+class NodeStatus():
+ STATUS_OK = 'active'
+ STATUS_INACTIVE = 'inactive'
+ STATUS_OFFLINE = 'offline'
+ STATUS_ERROR = 'error'
+ STATUS_UNUSED = 'unused'
+
+
+class Node(object):
+
+ def __init__(self,
+ id,
+ ip,
+ name,
+ status,
+ roles=None,
+ ssh_client=None,
+ info=None):
+ self.id = id
+ self.ip = ip
+ self.name = name
+ self.status = status
+ self.ssh_client = ssh_client
+ self.roles = roles
+ self.info = info
+
+ self.cpu_info = 'unknown'
+ self.memory = 'unknown'
+ self.ovs = 'unknown'
+
+ if ssh_client and Role.INSTALLER not in self.roles:
+ sys_info = self.get_system_info()
+ self.cpu_info = sys_info['cpu_info']
+ self.memory = sys_info['memory']
+ self.ovs = self.get_ovs_info()
+
+ def get_file(self, src, dest):
+ '''
+ SCP file from a node
+ '''
+ 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))
+ get_file_result = ssh_utils.get_file(self.ssh_client, src, dest)
+ if get_file_result is None:
+ logger.error("SFTP failed to retrieve the file.")
+ else:
+ logger.info("Successfully copied %s:%s to %s" %
+ (self.ip, src, dest))
+ return get_file_result
+
+ def put_file(self, src, dest):
+ '''
+ SCP file to a node
+ '''
+ 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))
+ put_file_result = ssh_utils.put_file(self.ssh_client, src, dest)
+ if put_file_result is None:
+ logger.error("SFTP failed to retrieve the file.")
+ else:
+ logger.info("Successfully copied %s to %s:%s" %
+ (src, dest, self.ip))
+ return put_file_result
+
+ def run_cmd(self, cmd):
+ '''
+ Run command remotely on a node
+ '''
+ if self.status is not NodeStatus.STATUS_OK:
+ logger.error(
+ "Error running command %s. The node %s is not active"
+ % (cmd, self.ip))
+ return None
+ _, stdout, stderr = (self.ssh_client.exec_command(cmd))
+ error = stderr.readlines()
+ if len(error) > 0:
+ logger.error("error %s" % ''.join(error))
+ return None
+ output = ''.join(stdout.readlines()).rstrip()
+ return output
+
+ def get_dict(self):
+ '''
+ Returns a dictionary with all the attributes
+ '''
+ return {
+ 'id': self.id,
+ 'ip': self.ip,
+ 'name': self.name,
+ 'status': self.status,
+ 'roles': self.roles,
+ 'cpu_info': self.cpu_info,
+ 'memory': self.memory,
+ 'ovs': self.ovs,
+ 'info': self.info
+ }
+
+ def is_active(self):
+ '''
+ Returns if the node is active
+ '''
+ if self.status == NodeStatus.STATUS_OK:
+ return True
+ return False
+
+ def is_controller(self):
+ '''
+ Returns if the node is a controller
+ '''
+ return Role.CONTROLLER in self.roles
+
+ def is_compute(self):
+ '''
+ Returns if the node is a compute
+ '''
+ return Role.COMPUTE in self.roles
+
+ def is_odl(self):
+ '''
+ Returns if the node is an opendaylight
+ '''
+ return Role.ODL in self.roles
+
+ def get_ovs_info(self):
+ '''
+ Returns the ovs version installed
+ '''
+ if self.is_active():
+ cmd = "ovs-vsctl --version|head -1| sed 's/^.*) //'"
+ return self.run_cmd(cmd)
+ return None
+
+ def get_system_info(self):
+ '''
+ Returns the ovs version installed
+ '''
+ cmd = 'grep MemTotal /proc/meminfo'
+ memory = self.run_cmd(cmd).partition('MemTotal:')[-1].strip().encode()
+
+ cpu_info = {}
+ cmd = 'lscpu'
+ result = self.run_cmd(cmd)
+ for line in result.splitlines():
+ if line.startswith('CPU(s)'):
+ cpu_info['num_cpus'] = line.split(' ')[-1].encode()
+ elif line.startswith('Thread(s) per core'):
+ cpu_info['threads/core'] = line.split(' ')[-1].encode()
+ elif line.startswith('Core(s) per socket'):
+ cpu_info['cores/socket'] = line.split(' ')[-1].encode()
+ elif line.startswith('Model name'):
+ cpu_info['model'] = line.partition(
+ 'Model name:')[-1].strip().encode()
+ elif line.startswith('Architecture'):
+ cpu_info['arch'] = line.split(' ')[-1].encode()
+
+ return {'memory': memory, 'cpu_info': cpu_info}
+
+ def __str__(self):
+ return '''
+ name: {name}
+ id: {id}
+ ip: {ip}
+ status: {status}
+ roles: {roles}
+ cpu: {cpu_info}
+ memory: {memory}
+ ovs: {ovs}
+ info: {info}'''.format(name=self.name,
+ id=self.id,
+ ip=self.ip,
+ status=self.status,
+ roles=self.roles,
+ cpu_info=self.cpu_info,
+ memory=self.memory,
+ ovs=self.ovs,
+ info=self.info)
+
+
+class DeploymentHandler(object):
+
+ EX_OK = os.EX_OK
+ EX_ERROR = os.EX_SOFTWARE
+ FUNCTION_NOT_IMPLEMENTED = "Function not implemented by adapter!"
+
+ def __init__(self,
+ installer,
+ installer_ip,
+ installer_user,
+ installer_pwd=None,
+ pkey_file=None):
+
+ self.installer = installer.lower()
+ self.installer_ip = installer_ip
+ self.installer_user = installer_user
+ self.installer_pwd = installer_pwd
+ self.pkey_file = pkey_file
+
+ if pkey_file is not None and not os.path.isfile(pkey_file):
+ raise Exception(
+ 'The private key file %s does not exist!' % pkey_file)
+
+ self.installer_connection = ssh_utils.get_ssh_client(
+ hostname=self.installer_ip,
+ username=self.installer_user,
+ password=self.installer_pwd,
+ pkey_file=self.pkey_file)
+
+ if self.installer_connection:
+ self.installer_node = Node(id='',
+ ip=installer_ip,
+ name=installer,
+ status=NodeStatus.STATUS_OK,
+ ssh_client=self.installer_connection,
+ roles=Role.INSTALLER)
+ else:
+ raise Exception(
+ 'Cannot establish connection to the installer node!')
+
+ self.nodes = self.get_nodes()
+
+ @abstractmethod
+ def get_openstack_version(self):
+ '''
+ Returns a string of the openstack version (nova-compute)
+ '''
+ raise Exception(DeploymentHandler.FUNCTION_NOT_IMPLEMENTED)
+
+ @abstractmethod
+ def get_sdn_version(self):
+ '''
+ Returns a string of the sdn controller and its version, if exists
+ '''
+ raise Exception(DeploymentHandler.FUNCTION_NOT_IMPLEMENTED)
+
+ @abstractmethod
+ def get_deployment_status(self):
+ '''
+ Returns a string of the status of the deployment
+ '''
+ raise Exception(DeploymentHandler.FUNCTION_NOT_IMPLEMENTED)
+
+ @abstractmethod
+ def get_nodes(self, options=None):
+ '''
+ Generates a list of all the nodes in the deployment
+ '''
+ raise Exception(DeploymentHandler.FUNCTION_NOT_IMPLEMENTED)
+
+ def get_installer_node(self):
+ '''
+ Returns the installer node object
+ '''
+ return self.installer_node
+
+ def get_arch(self):
+ '''
+ Returns the architecture of the first compute node found
+ '''
+ arch = None
+ for node in self.nodes:
+ if node.is_compute():
+ arch = node.cpu_info.get('arch', None)
+ if arch:
+ break
+ return arch
+
+ def get_deployment_info(self):
+ '''
+ Returns an object of type Deployment
+ '''
+ return Deployment(installer=self.installer,
+ installer_ip=self.installer_ip,
+ scenario=os.getenv('DEPLOY_SCENARIO', 'Unknown'),
+ status=self.get_deployment_status(),
+ pod=os.getenv('NODE_NAME', 'Unknown'),
+ openstack_version=self.get_openstack_version(),
+ sdn_controller=self.get_sdn_version(),
+ nodes=self.get_nodes())
diff --git a/modules/opnfv/installer_adapters/InstallerHandler.py b/modules/opnfv/installer_adapters/InstallerHandler.py
deleted file mode 100644
index dc5bdb9d6..000000000
--- a/modules/opnfv/installer_adapters/InstallerHandler.py
+++ /dev/null
@@ -1,81 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 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):
- self.installer = installer.lower()
- self.installer_ip = installer_ip
- self.installer_user = installer_user
- self.installer_pwd = installer_pwd
-
- 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(self.installer_ip)
- 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/modules/opnfv/installer_adapters/apex/ApexAdapter.py b/modules/opnfv/installer_adapters/apex/ApexAdapter.py
deleted file mode 100644
index 17a27b10a..000000000
--- a/modules/opnfv/installer_adapters/apex/ApexAdapter.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 ApexAdapter:
-
- 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/modules/opnfv/installer_adapters/compass/CompassAdapter.py b/modules/opnfv/installer_adapters/compass/CompassAdapter.py
deleted file mode 100644
index 47cbc646d..000000000
--- a/modules/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/modules/opnfv/installer_adapters/daisy/DaisyAdapter.py b/modules/opnfv/installer_adapters/daisy/DaisyAdapter.py
deleted file mode 100644
index 9b06f4c3c..000000000
--- a/modules/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/modules/opnfv/installer_adapters/daisy/__init__.py b/modules/opnfv/installer_adapters/daisy/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/modules/opnfv/installer_adapters/daisy/__init__.py
+++ /dev/null
diff --git a/modules/opnfv/installer_adapters/fuel/FuelAdapter.py b/modules/opnfv/installer_adapters/fuel/FuelAdapter.py
deleted file mode 100644
index 8ed8f8937..000000000
--- a/modules/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/modules/opnfv/installer_adapters/fuel/__init__.py b/modules/opnfv/installer_adapters/fuel/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/modules/opnfv/installer_adapters/fuel/__init__.py
+++ /dev/null
diff --git a/modules/opnfv/installer_adapters/fuel/example.py b/modules/opnfv/installer_adapters/fuel/example.py
deleted file mode 100644
index 7fea4dfd7..000000000
--- a/modules/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/modules/opnfv/installer_adapters/joid/JoidAdapter.py b/modules/opnfv/installer_adapters/joid/JoidAdapter.py
deleted file mode 100644
index be8c2ebac..000000000
--- a/modules/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/modules/opnfv/installer_adapters/joid/__init__.py b/modules/opnfv/installer_adapters/joid/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/modules/opnfv/installer_adapters/joid/__init__.py
+++ /dev/null
diff --git a/modules/opnfv/utils/Credentials.py b/modules/opnfv/utils/Credentials.py
index 6441b841c..141ecbd93 100644
--- a/modules/opnfv/utils/Credentials.py
+++ b/modules/opnfv/utils/Credentials.py
@@ -77,7 +77,7 @@ class Credentials(object):
creds_file = '/root/openrc'
try:
self.handler.get_file_from_controller(creds_file, target_path)
- except Exception, e:
+ except Exception as e:
self.logger.error(
"Cannot get %s from controller. %e" % (creds_file, e))
pass
diff --git a/modules/opnfv/utils/constants.py b/modules/opnfv/utils/constants.py
index ed83488d4..56008c37f 100644
--- a/modules/opnfv/utils/constants.py
+++ b/modules/opnfv/utils/constants.py
@@ -14,6 +14,7 @@ EXIT_OK = 0
EXIT_RUN_ERROR = -1
EXIT_PUSH_TO_TEST_DB_ERROR = -2
+
class Constants(object):
INSTALLERS = ['apex', 'fuel', 'compass', 'joid', "daisy"]
VERSIONS = ['arno', 'brahmaputra', 'colorado', 'danube']
diff --git a/modules/opnfv/utils/OPNFVLogger.py b/modules/opnfv/utils/opnfv_logger.py
index 6fa4ef2e2..6fa4ef2e2 100644
--- a/modules/opnfv/utils/OPNFVLogger.py
+++ b/modules/opnfv/utils/opnfv_logger.py
diff --git a/modules/opnfv/utils/ovs_logger.py b/modules/opnfv/utils/ovs_logger.py
index 3159609f1..7777a9a16 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
@@ -16,6 +16,7 @@ logger = OPNFVLogger.Logger('ovs_logger').getLogger()
class OVSLogger(object):
+
def __init__(self, basedir, ft_resdir):
self.ovs_dir = basedir
self.ft_resdir = ft_resdir
@@ -32,7 +33,7 @@ class OVSLogger(object):
hosts = stdout.readline().strip().split(' ')
found_host = [h for h in hosts if h.startswith(host_prefix)][0]
return found_host
- except Exception, e:
+ except Exception as e:
logger.error(e)
def __dump_to_file(self, operation, host, text, timestamp=None):
@@ -55,7 +56,7 @@ class OVSLogger(object):
.format(cmd, host))
output = ''.join(stdout.readlines())
return output
- except Exception, e:
+ except Exception as e:
logger.error('[__remote_command(ssh_client, {0})]: {1}'
.format(cmd, e))
return None
@@ -78,7 +79,7 @@ class OVSLogger(object):
host = self.__ssh_host(ssh_conn)
self.__dump_to_file(operation, host, output, timestamp=timestamp)
return output
- except Exception, e:
+ except Exception as e:
logger.error('[ofctl_dump_flows(ssh_client, {0}, {1})]: {2}'
.format(br, choose_table, e))
return None
@@ -91,7 +92,7 @@ class OVSLogger(object):
host = self.__ssh_host(ssh_conn)
self.__dump_to_file(operation, host, output, timestamp=timestamp)
return output
- except Exception, e:
+ except Exception as e:
logger.error('[vsctl_show(ssh_client)]: {0}'.format(e))
return None
@@ -100,19 +101,13 @@ class OVSLogger(object):
if timestamp is None:
timestamp = time.strftime("%Y%m%d-%H%M%S")
- for controller_client in controller_clients:
- self.ofctl_dump_flows(controller_client,
- timestamp=timestamp)
- self.vsctl_show(controller_client,
- timestamp=timestamp)
-
- for compute_client in compute_clients:
- self.ofctl_dump_flows(compute_client,
- timestamp=timestamp)
- self.vsctl_show(compute_client,
- timestamp=timestamp)
+ clients = controller_clients + compute_clients
+ for client in clients:
+ self.ofctl_dump_flows(client, timestamp=timestamp)
+ self.vsctl_show(client, timestamp=timestamp)
if related_error is not None:
dumpdir = os.path.join(self.ovs_dir, timestamp)
+ self.__mkdir_p(dumpdir)
with open(os.path.join(dumpdir, 'error'), 'w') as f:
f.write(related_error)
diff --git a/modules/opnfv/utils/SSHUtils.py b/modules/opnfv/utils/ssh_utils.py
index 16e34c3e5..d17f5ae81 100644
--- a/modules/opnfv/utils/SSHUtils.py
+++ b/modules/opnfv/utils/ssh_utils.py
@@ -9,14 +9,19 @@
##############################################################################
-import paramiko
-import opnfv.utils.OPNFVLogger as OPNFVLogger
import os
+import paramiko
-logger = OPNFVLogger.Logger('SSHUtils').getLogger()
+from opnfv.utils import opnfv_logger as logger
+logger = logger.Logger("SSH utils").getLogger()
-def get_ssh_client(hostname, username, password=None, proxy=None):
+
+def get_ssh_client(hostname,
+ username,
+ password=None,
+ proxy=None,
+ pkey_file=None):
client = None
try:
if proxy is None:
@@ -26,16 +31,23 @@ def get_ssh_client(hostname, username, password=None, proxy=None):
client.configure_jump_host(proxy['ip'],
proxy['username'],
proxy['password'])
-
if client is None:
raise Exception('Could not connect to client')
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(hostname,
- username=username,
- password=password)
+ if pkey_file is not None:
+ key = paramiko.RSAKey.from_private_key_file(pkey_file)
+ client.load_system_host_keys()
+ client.connect(hostname,
+ username=username,
+ pkey=key)
+ else:
+ client.connect(hostname,
+ username=username,
+ password=password)
+
return client
- except Exception, e:
+ except Exception as e:
logger.error(e)
return None
@@ -45,7 +57,7 @@ def get_file(ssh_conn, src, dest):
sftp = ssh_conn.open_sftp()
sftp.get(src, dest)
return True
- except Exception, e:
+ except Exception as e:
logger.error("Error [get_file(ssh_conn, '%s', '%s']: %s" %
(src, dest, e))
return None
@@ -56,7 +68,7 @@ def put_file(ssh_conn, src, dest):
sftp = ssh_conn.open_sftp()
sftp.put(src, dest)
return True
- except Exception, e:
+ except Exception as e:
logger.error("Error [put_file(ssh_conn, '%s', '%s']: %s" %
(src, dest, e))
return None
@@ -66,8 +78,8 @@ class ProxyHopClient(paramiko.SSHClient):
'''
Connect to a remote server using a proxy hop
'''
+
def __init__(self, *args, **kwargs):
- self.logger = OPNFVLogger.Logger("ProxyHopClient").getLogger()
self.proxy_ssh = None
self.proxy_transport = None
self.proxy_channel = None
@@ -116,5 +128,5 @@ class ProxyHopClient(paramiko.SSHClient):
pkey=proxy_key,
sock=self.proxy_channel)
os.remove(self.local_ssh_key)
- except Exception, e:
- self.logger.error(e)
+ except Exception as e:
+ logger.error(e)