1 ##############################################################################
2 # Copyright (c) 2016 Ericsson AB and others.
3 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 import opnfv.utils.SSHUtils as ssh_utils
14 import opnfv.utils.OPNFVLogger as logger
19 def __init__(self, installer_ip, pkey_file, user="stack"):
20 self.installer_ip = installer_ip
21 self.installer_user = user
22 self.pkey_file = pkey_file
23 self.installer_connection = ssh_utils.get_ssh_client(
26 pkey_file=self.pkey_file)
27 self.logger = logger.Logger("ApexHandler").getLogger()
29 def runcmd_apex_installer(self, cmd):
30 _, stdout, stderr = (self.installer_connection.exec_command(cmd))
31 error = stderr.readlines()
33 self.logger.error("error %s" % ''.join(error))
35 output = ''.join(stdout.readlines())
40 output = self.runcmd_apex_installer(
41 "source /home/stack/stackrc;nova list")
42 lines = output.rsplit('\n')
44 self.logger.info("No nodes found in the deployment.")
48 if 'controller' in line:
50 elif 'compute' in line:
54 if 'Daylight' in line:
55 roles = + ", OpenDaylight"
56 fields = line.split('|')
57 dict = {"id": re.sub('[!| ]', '', fields[1]),
59 "name": re.sub('[!| ]', '', fields[2]),
60 "status": re.sub('[!| ]', '', fields[3]),
61 "ip": re.sub('[!| ctlplane=]', '', fields[6])}
66 def get_deployment_info(self):
67 str = "Deployment details:\n"
68 str += "\tINSTALLER: Apex\n"
69 str += ("\tSCENARIO: %s\n" %
70 os.getenv('DEPLOY_SCENARIO', 'Unknown'))
73 nodes = self.get_nodes()
75 self.logger.info("No nodes found in the deployment.")
77 num_nodes = len(nodes)
81 if 'controller' in node['roles']:
83 if 'compute' in node['roles']:
85 if 'Daylight' in node['name']:
88 ha = str(num_controllers >= 3)
90 str += "\tHA: %s\n" % ha
91 str += "\tNUM.NODES: %s\n" % num_nodes
92 str += "\tCONTROLLERS: %s\n" % num_controllers
93 str += "\tCOMPUTES: %s\n" % num_computes
94 str += "\tSDN CONTR.: %s\n\n" % sdn
98 str += ("\t ID: %s\n" % node['id'])
99 str += ("\t Name: %s\n" % node['name'])
100 str += ("\t Roles: %s\n" % node['roles'])
101 str += ("\t Status: %s\n" % node['status'])
102 str += ("\t IP: %s\n\n" % node['ip'])
106 def get_controller_ips(self, options=None):
107 nodes = self.get_nodes()
110 if "controller" in node["roles"]:
111 controllers.append(node['ip'])
114 def get_compute_ips(self, options=None):
115 nodes = self.get_nodes()
118 if "compute" in node["roles"]:
119 computes.append(node['ip'])
122 def get_file_from_installer(self, remote_path, local_path, options=None):
123 self.logger.debug("Fetching %s from Undercloud %s" %
124 (remote_path, self.installer_ip))
125 get_file_result = ssh_utils.get_file(self.installer_connection,
128 if get_file_result is None:
129 self.logger.error("SFTP failed to retrieve the file.")
131 self.logger.info("%s successfully copied from Undercloud to %s" %
132 (remote_path, local_path))
134 def get_file_from_controller(self,
140 controllers = self.get_controller_ips()
143 connection = ssh_utils.get_ssh_client(ip,
145 pkey_file=self.pkey_file)
147 get_file_result = ssh_utils.get_file(connection,
150 if get_file_result is None:
151 self.logger.error("SFTP failed to retrieve the file.")
153 self.logger.info("%s successfully copied from %s to %s" %
154 (remote_path, ip, local_path))