1 ##############################################################################
2 # Copyright (c) 2017 SUSE Linux GmbH
3 # Author: Manuel Buil (mbuil@suse.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 ##############################################################################
11 from opnfv.deployment import manager
12 from opnfv.utils import opnfv_logger as logger
13 from opnfv.utils import ssh_utils
16 logger = logger.Logger(__name__).getLogger()
19 class OSAAdapter(manager.DeploymentHandler):
21 def __init__(self, installer_ip, installer_user, pkey_file):
22 self.SOURCE_PATH_UC = "/etc/openstack_deploy/openstack_user_config.yml"
23 self.DEST_PATH_UC = "/tmp/openstack_user_config.yml"
24 super(OSAAdapter, self).__init__(installer='osa',
25 installer_ip=installer_ip,
26 installer_user=installer_user,
30 def _find_nodes(self, file):
31 nodes = file['compute_hosts']
32 controllers = file['haproxy_hosts']
33 for controller in controllers:
34 nodes[controller] = controllers[controller]
37 def _process_nodes(self, raw_nodes):
40 for node in raw_nodes:
42 ip = raw_nodes[node]['ip']
43 # TODO when xci provides status and id of nodes add logic
46 if 'controller' in node:
48 elif 'compute' in node:
50 ssh_client = ssh_utils.get_ssh_client(hostname=ip,
51 username=self.installer_user,
52 pkey_file=self.pkey_file)
53 node = manager.Node(id, ip, name, status, roles, ssh_client)
58 def get_nodes(self, options=None):
60 # if we have retrieved previously all the nodes, don't do it again
61 # This fails the first time when the constructor calls this method
62 # therefore the try/except
63 if len(self.nodes) > 0:
68 self.installer_node.get_file(self.SOURCE_PATH_UC, self.DEST_PATH_UC)
69 with open(self.DEST_PATH_UC, 'r') as stream:
71 file = yaml.load(stream)
72 raw_nodes = self._find_nodes(file)
73 except yaml.YAMLError as exc:
75 nodes = self._process_nodes(raw_nodes)