1 ##############################################################################
2 # Copyright (c) 2017 Ericsson AB and others.
3 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
4 # George Paraskevopoulos (geopar@intracom-telecom.com)
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
12 from opnfv.deployment import manager
13 from opnfv.utils import opnfv_logger as logger
14 from opnfv.utils import ssh_utils
16 logger = logger.Logger(__name__).getLogger()
19 class FuelAdapter(manager.DeploymentHandler):
21 def __init__(self, installer_ip, installer_user, installer_pwd):
22 super(FuelAdapter, self).__init__(installer='fuel',
23 installer_ip=installer_ip,
24 installer_user=installer_user,
25 installer_pwd=installer_pwd,
28 def _get_clusters(self):
30 output = self.runcmd_fuel_env()
31 lines = output.rsplit('\n')
33 logger.info("No environments found in the deployment.")
36 fields = lines[0].rsplit(' | ')
43 for i in range(len(fields)):
46 elif "status" in fields[i]:
48 elif "name" in fields[i]:
50 elif "release_id" in fields[i]:
54 for i in range(2, len(lines)):
55 fields = lines[i].rsplit(' | ')
56 dict = {"id": fields[index_id].strip(),
57 "status": fields[index_status].strip(),
58 "name": fields[index_name].strip(),
59 "release_id": fields[index_release_id].strip()}
60 environments.append(dict)
64 def get_nodes(self, options=None):
66 if options and options['cluster'] and len(self.nodes) > 0:
68 for node in self.nodes:
69 if str(node.info['cluster']) == str(options['cluster']):
74 # if we have retrieved previously all the nodes, don't do it again
75 # This fails the first time when the constructor calls this method
76 # therefore the try/except
77 if len(self.nodes) > 0:
84 output = self.installer_node.run_cmd(cmd)
85 lines = output.rsplit('\n')
87 logger.info("No nodes found in the deployment.")
91 fields = lines[0].rsplit(' | ')
102 for i in range(len(fields)):
103 if "group_id" in fields[i]:
105 elif "id" in fields[i]:
107 elif "status" in fields[i]:
109 elif "name" in fields[i]:
111 elif "cluster" in fields[i]:
113 elif "ip" in fields[i]:
115 elif "mac" in fields[i]:
117 elif "roles " in fields[i] and "pending_roles" not in fields[i]:
119 elif "online" in fields[i]:
123 for i in range(2, len(lines)):
124 fields = lines[i].rsplit(' | ')
125 id = fields[index_id].strip().encode()
126 ip = fields[index_ip].strip().encode()
127 status_node = fields[index_status].strip().encode().lower()
128 name = fields[index_name].strip().encode()
129 roles_all = fields[index_roles].strip().encode().lower()
131 roles = [x for x in [manager.Role.CONTROLLER,
132 manager.Role.COMPUTE,
133 manager.Role.ODL] if x in roles_all]
135 dict = {"cluster": fields[index_cluster].strip().encode(),
136 "mac": fields[index_mac].strip().encode(),
137 "status_node": status_node,
138 "online": fields[index_online].strip().encode()}
141 if status_node == 'ready':
142 status = manager.NodeStatus.STATUS_OK
143 proxy = {'ip': self.installer_ip,
144 'username': self.installer_user,
145 'password': self.installer_pwd}
146 ssh_client = ssh_utils.get_ssh_client(hostname=ip,
149 elif 'error' in status_node:
150 status = manager.NodeStatus.STATUS_ERROR
151 elif 'off' in status_node:
152 status = manager.NodeStatus.STATUS_OFFLINE
153 elif 'discover' in status_node:
154 status = manager.NodeStatus.STATUS_UNUSED
156 status = manager.NodeStatus.STATUS_INACTIVE
159 id, ip, name, status, roles, ssh_client, dict)
160 if options and options['cluster']:
161 if fields[index_cluster].strip() == options['cluster']:
166 self.get_nodes_called = True
169 def get_openstack_version(self):
170 cmd = 'source openrc;nova-manage version 2>/dev/null'
172 for node in self.nodes:
173 if node.is_controller() and node.is_active():
174 version = node.run_cmd(cmd)
178 def get_sdn_version(self):
179 cmd = "apt-cache policy opendaylight|grep Installed"
181 for node in self.nodes:
182 if manager.Role.ODL in node.roles and node.is_active():
183 odl_version = node.run_cmd(cmd)
185 version = 'OpenDaylight ' + odl_version.split(' ')[-1]
189 def get_deployment_status(self):
190 cmd = "fuel env|tail -1|awk '{print $3}'"
191 result = self.installer_node.run_cmd(cmd)
192 if result is None or len(result) == 0:
194 elif 'operational' in result:
196 elif 'deploy' in result: