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)
35 self.zero_mbr_set_boot_order()
37 self.proceed_with_installation()
39 def custom_install(self):
40 log('Start Custom Fuel Installation')
42 self.dha.node_power_off(self.fuel_node_id)
45 self.dha.node_zero_mbr(self.fuel_node_id)
47 self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso'])
49 self.proceed_with_installation()
51 def proceed_with_installation(self):
53 self.dha.node_eject_iso(self.fuel_node_id)
55 log('Insert ISO %s' % self.iso_file)
56 self.dha.node_insert_iso(self.fuel_node_id, self.iso_file)
58 self.dha.node_power_on(self.fuel_node_id)
60 log('Waiting for Fuel master to accept SSH')
61 self.wait_for_node_up()
63 log('Wait until Fuel menu is up')
64 fuel_menu_pid = self.wait_until_fuel_menu_up()
66 log('Inject our own astute.yaml settings')
67 self.inject_own_astute_yaml()
69 log('Let the Fuel deployment continue')
70 log('Found FUEL menu as PID %s, now killing it' % fuel_menu_pid)
71 self.ssh_exec_cmd('kill %s' % fuel_menu_pid)
73 log('Wait until installation complete')
74 self.wait_until_installation_completed()
76 log('Waiting for one minute for Fuel to stabilize')
80 self.dha.node_eject_iso(self.fuel_node_id)
82 log('Fuel Master installed successfully !')
84 def zero_mbr_set_boot_order(self):
85 if self.dha.node_can_zero_mbr(self.fuel_node_id):
86 log('Fuel Node %s capable of zeroing MBR so doing that...'
88 self.dha.node_zero_mbr(self.fuel_node_id)
89 self.dha.node_set_boot_order(self.fuel_node_id, ['disk', 'iso'])
90 elif self.dha.node_can_set_boot_order_live(self.fuel_node_id):
91 log('Node %s can change ISO boot order live' % self.fuel_node_id)
92 self.dha.node_set_boot_order(self.fuel_node_id, ['iso', 'disk'])
94 err('No way to install Fuel node')
96 def wait_for_node_up(self):
100 for i in range(WAIT_LOOP):
105 except Exception as e:
106 log('EXCEPTION [%s] received when SSH-ing into Fuel VM %s ... '
107 'sleeping %s seconds' % (e, self.fuel_ip, SLEEP_TIME))
108 time.sleep(SLEEP_TIME)
113 err('Could not SSH into Fuel VM %s' % self.fuel_ip)
115 def wait_until_fuel_menu_up(self):
122 for i in range(WAIT_LOOP):
123 ret = self.ssh.exec_cmd(CMD)
124 fuel_menu_pid = self.get_fuel_menu_pid(ret, SEARCH)
125 if not fuel_menu_pid:
126 time.sleep(SLEEP_TIME)
129 if not fuel_menu_pid:
130 err('Could not find the Fuel Menu Process ID')
133 def get_fuel_menu_pid(self, printout, search):
135 for line in printout.splitlines():
137 fuel_menu_pid = clean(line)[1]
141 def ssh_exec_cmd(self, cmd):
143 ret = self.ssh.exec_cmd(cmd)
146 def inject_own_astute_yaml(self):
147 dest ='~/%s/' % self.work_dir
150 s.exec_cmd('rm -rf %s' % self.work_dir, check=False)
151 s.exec_cmd('mkdir ~/%s' % self.work_dir)
152 s.scp_put(self.dea_file, dest)
153 s.scp_put('%s/common.py' % self.file_dir, dest)
154 s.scp_put('%s/dea.py' % self.file_dir, dest)
155 s.scp_put('%s/transplant_fuel_settings.py' % self.file_dir, dest)
156 log('Modifying Fuel astute')
157 s.run('python ~/%s/%s ~/%s/%s'
158 % (self.work_dir, TRANSPLANT_FUEL_SETTINGS,
159 self.work_dir, os.path.basename(self.dea_file)))
161 def wait_until_installation_completed(self):
164 CMD = 'ps -ef | grep %s | grep -v grep' % BOOTSTRAP_ADMIN
166 install_completed = False
168 for i in range(WAIT_LOOP):
169 ret = self.ssh.exec_cmd(CMD)
171 install_completed = True
174 time.sleep(SLEEP_TIME)
176 if not install_completed:
177 err('Fuel installation did not complete')