1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
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 ##############################################################################
16 from installer.base import BaseInstaller
17 from utils import SSHClient
20 class ApexInstaller(BaseInstaller):
21 node_user_name = 'heat-admin'
22 cm_set_script = 'set_ceilometer.py'
23 cm_restore_script = 'restore_ceilometer.py'
25 def __init__(self, conf, log):
26 super(ApexInstaller, self).__init__(conf, log)
27 self.client = SSHClient(self.conf.installer.ip,
28 self.conf.installer.username,
31 self.controllers = list()
32 self.controller_clients = list()
35 self.log.info('Setup Apex installer start......')
37 self.key_file = self.get_ssh_key_from_installer()
38 self.get_controller_ips()
39 self.set_apply_patches()
42 self.restore_apply_patches()
44 def get_ssh_key_from_installer(self):
45 self.log.info('Get SSH keys from Apex installer......')
47 self.client.scp('/home/stack/.ssh/id_rsa', './instack_key', method='get')
48 user = getpass.getuser()
49 uid = pwd.getpwnam(user).pw_uid
50 gid = grp.getgrnam(user).gr_gid
51 os.chown('./instack_key', uid, gid)
52 os.chmod('./instack_key', stat.S_IREAD)
53 current_dir = sys.path[0]
54 return '{0}/{1}'.format(current_dir, 'instack_key')
56 def get_controller_ips(self):
57 self.log.info('Get controller ips from Apex installer......')
59 command = "source stackrc; " \
60 "nova list | grep ' overcloud-controller-[0-9] ' " \
61 "| sed -e 's/^.*ctlplane=//' |awk '{print $1}'"
62 ret, controllers = self.client.ssh(command)
64 raise Exception('Exec command to get controller ips in Apex installer failed'
65 'ret=%s, output=%s' % (ret, controllers))
66 self.controllers = controllers
68 def set_apply_patches(self):
69 self.log.info('Set apply patches start......')
71 for node_ip in self.controllers:
72 client = SSHClient(node_ip, self.node_user_name, key_filename=self.key_file)
73 self.controller_clients.append(client)
74 self._ceilometer_apply_patches(client, self.cm_set_script)
76 def restore_apply_patches(self):
77 self.log.info('restore apply patches start......')
79 for client in self.controller_clients:
80 self._ceilometer_apply_patches(client, self.cm_restore_script)
82 def _ceilometer_apply_patches(self, ssh_client, script_name):
83 installer_dir = os.path.dirname(os.path.realpath(__file__))
84 script_abs_path = '{0}/{1}/{2}'.format(installer_dir, 'common', script_name)
86 ssh_client.scp(script_abs_path, script_name)
87 cmd = 'sudo python %s' % script_name
88 ret, output = ssh_client.ssh(cmd)
90 raise Exception('Do the ceilometer command in controller node failed....'
91 'ret=%s, cmd=%s, output=%s' % (ret, cmd, output))
92 ssh_client.ssh('sudo systemctl restart openstack-ceilometer-notification.service')