4 from ssh_client import SSHClient
5 from dha_adapters.libvirt_adapter import LibvirtAdapter
11 TRANSPLANT_FUEL_SETTINGS = 'transplant_fuel_settings.py'
12 BOOTSTRAP_ADMIN = '/usr/local/sbin/bootstrap_admin_node'
14 class InstallFuelMaster(object):
16 def __init__(self, dea_file, dha_file, fuel_ip, fuel_username, fuel_password,
17 fuel_node_id, iso_file, work_dir):
18 self.dea_file = dea_file
19 self.dha = LibvirtAdapter(dha_file)
20 self.fuel_ip = fuel_ip
21 self.fuel_username = fuel_username
22 self.fuel_password = fuel_password
23 self.fuel_node_id = fuel_node_id
24 self.iso_file = iso_file
25 self.work_dir = work_dir
26 self.file_dir = os.path.dirname(os.path.realpath(__file__))
27 self.ssh = SSHClient(self.fuel_ip, self.fuel_username,
31 log('Start Fuel Installation')
33 self.dha.node_power_off(self.fuel_node_id)
36 self.dha.node_zero_mbr(self.fuel_node_id)
38 self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso'])
40 self.proceed_with_installation()
42 def proceed_with_installation(self):
44 self.dha.node_eject_iso(self.fuel_node_id)
46 log('Insert ISO %s' % self.iso_file)
47 self.dha.node_insert_iso(self.fuel_node_id, self.iso_file)
49 self.dha.node_power_on(self.fuel_node_id)
51 log('Waiting for Fuel master to accept SSH')
52 self.wait_for_node_up()
54 log('Wait until Fuel menu is up')
55 fuel_menu_pid = self.wait_until_fuel_menu_up()
57 log('Inject our own astute.yaml settings')
58 self.inject_own_astute_yaml()
60 log('Let the Fuel deployment continue')
61 log('Found FUEL menu as PID %s, now killing it' % fuel_menu_pid)
62 self.ssh_exec_cmd('kill %s' % fuel_menu_pid, False)
64 log('Wait until installation complete')
65 self.wait_until_installation_completed()
67 log('Waiting for one minute for Fuel to stabilize')
71 self.dha.node_eject_iso(self.fuel_node_id)
73 log('Fuel Master installed successfully !')
75 def wait_for_node_up(self):
79 for i in range(WAIT_LOOP):
84 except Exception as e:
85 log('Trying to SSH into Fuel VM %s ... sleeping %s seconds'
86 % (self.fuel_ip, SLEEP_TIME))
87 time.sleep(SLEEP_TIME)
92 err('Could not SSH into Fuel VM %s' % self.fuel_ip)
94 def wait_until_fuel_menu_up(self):
101 for i in range(WAIT_LOOP):
102 ret = self.ssh.exec_cmd(CMD)
103 fuel_menu_pid = self.get_fuel_menu_pid(ret, SEARCH)
104 if not fuel_menu_pid:
105 time.sleep(SLEEP_TIME)
108 if not fuel_menu_pid:
109 err('Could not find the Fuel Menu Process ID')
112 def get_fuel_menu_pid(self, printout, search):
114 for line in printout.splitlines():
116 fuel_menu_pid = clean(line)[1]
120 def ssh_exec_cmd(self, cmd, check=True):
122 ret = self.ssh.exec_cmd(cmd, check=check)
125 def inject_own_astute_yaml(self):
126 dest ='~/%s/' % self.work_dir
129 s.exec_cmd('rm -rf %s' % self.work_dir, check=False)
130 s.exec_cmd('mkdir ~/%s' % self.work_dir)
131 s.scp_put(self.dea_file, dest)
132 s.scp_put('%s/common.py' % self.file_dir, dest)
133 s.scp_put('%s/dea.py' % self.file_dir, dest)
134 s.scp_put('%s/transplant_fuel_settings.py' % self.file_dir, dest)
135 log('Modifying Fuel astute')
136 s.run('python ~/%s/%s ~/%s/%s'
137 % (self.work_dir, TRANSPLANT_FUEL_SETTINGS,
138 self.work_dir, os.path.basename(self.dea_file)))
140 def wait_until_installation_completed(self):
143 CMD = 'ps -ef | grep %s | grep -v grep' % BOOTSTRAP_ADMIN
145 install_completed = False
147 for i in range(WAIT_LOOP):
148 ret = self.ssh.exec_cmd(CMD)
150 install_completed = True
153 time.sleep(SLEEP_TIME)
155 if not install_completed:
156 err('Fuel installation did not complete')