3 # Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
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
10 from opnfv.deployment import manager
11 from opnfv.utils import opnfv_logger as logger
12 from opnfv.utils import ssh_utils
17 logger = logger.Logger(__name__).getLogger()
20 class ContainerizedCompassAdapter():
22 def __init__(self, installer_ip, installer_user, pkey_file):
24 self.installer = 'compass'
25 self.installer_ip = installer_ip
26 self.installer_user = installer_user
27 self.pkey_file = pkey_file
28 self.DST_PATH_UC = "/tmp/openstack_user_config.yml"
32 if pkey_file is not None and not os.path.isfile(pkey_file):
34 'The private key file %s does not exist!' % pkey_file)
36 def _find_nodes(self, file):
37 nodes = file['compute_hosts']
39 self.ROLES[compute] = 'compute'
40 controllers = file['haproxy_hosts']
41 for controller in controllers:
42 nodes[controller] = controllers[controller]
43 self.ROLES[controller] = 'controller'
46 def _process_nodes(self, raw_nodes):
49 for node in raw_nodes:
51 ip = raw_nodes[node]['ip']
54 if self.ROLES[node] == 'controller':
56 elif self.ROLES[node] == 'compute':
58 ssh_client = ssh_utils.get_ssh_client(hostname=ip,
59 username=self.installer_user,
60 pkey_file=self.pkey_file)
61 node = manager.Node(id, ip, name, status, roles, ssh_client)
66 def get_nodes(self, options=None):
68 # if we have retrieved previously all the nodes, don't do it again
69 # This fails the first time when the constructor calls this method
70 # therefore the try/except
71 if len(self.nodes) > 0:
76 with open(self.DST_PATH_UC, 'r') as stream:
78 file = yaml.load(stream)
79 raw_nodes = self._find_nodes(file)
80 except yaml.YAMLError as exc:
82 self.nodes = self._process_nodes(raw_nodes)