import os
import importlib
import time
+import distutils.util
from yaml import load
from netaddr import IPNetwork
pass
class Installer(object):
- SSH_OPTS = '-o StrictHostKeyChecking=no \
- -o UserKnownHostsFile=/dev/null \
- -o ServerAliveInterval=60'
+ SSH_OPTS = ('-o StrictHostKeyChecking=no '
+ '-o UserKnownHostsFile=/dev/null '
+ '-o ServerAliveInterval=60')
def __init__(self, callback_server, callback_uuid, yaml, logdir, args=None):
self._callback_server = callback_server
self._ca_cert = None
self._own_ip = None
self._tag = None
- if args:
- self._set_arguments(args)
-
- # TODO
self._disable_bmc_initial_reset = False
self._disable_other_bmc_reset = True
+ if args:
+ self._set_arguments(args)
+
self._vip = None
self._first_controller = None
self._first_controller_ip = None
self._define_first_controller()
+ def _get_bool_arg(self, args, arg, default):
+ if hasattr(args, arg):
+ arg_value = vars(args)[arg]
+ if not isinstance(arg_value, bool):
+ if isinstance(arg_value, basestring):
+ try:
+ arg_value = bool(distutils.util.strtobool(arg_value))
+ return arg_value
+ except ValueError:
+ logging.warning('Invalid value for %s: %s', arg, arg_value)
+ else:
+ return arg_value
+
+ return default
+
def _set_arguments(self, args):
+ self._disable_bmc_initial_reset = self._get_bool_arg(args, 'disable_bmc_initial_reset', self._disable_bmc_initial_reset)
+ self._disable_other_bmc_reset = self._get_bool_arg(args, 'disable_other_bmc_reset', self._disable_other_bmc_reset)
+
self._boot_iso_path = args.boot_iso
self._iso_url = args.iso
self._callback_url = args.callback_url
host = self._uc['hosts'][hw]['hwmgmt']['address']
user = self._uc['hosts'][hw]['hwmgmt']['user']
passwd = self._uc['hosts'][hw]['hwmgmt']['password']
+ priv_level = self._uc['hosts'][hw]['hwmgmt'].get('priv_level', 'ADMINISTRATOR')
try:
- hw_data = hw_detect.get_hw_data(host, user, passwd, False)
+ hw_data = hw_detect.get_hw_data(host, user, passwd, priv_level, False)
except HWException as e:
- error = "Harware not detected for {}: {}".format(hw, str(e))
+ error = "Hardware not detected for {}: {}".format(hw, str(e))
logging.error(error)
raise BMCException(error)
bmc_mod_name = 'remoteinstaller.installer.bmc_management.{}'.format(hw_data['product_family'].lower())
bmc_mod = importlib.import_module(bmc_mod_name)
bmc_class = getattr(bmc_mod, hw_data['product_family'])
- bmc = bmc_class(host, user, passwd, bmc_log_path)
+ bmc = bmc_class(host, user, passwd, priv_level, bmc_log_path)
bmc.set_host_name(hw)
return bmc
pre_allocated_ips = self._uc['hosts'][self._first_controller].get('pre_allocated_ips', None)
if pre_allocated_ips:
pre_allocated_infra_external_ip = pre_allocated_ips.get('infra_external', None)
- self._first_controller_ip = str(IPAddress(pre_allocated_infra_external_ip))
+ if pre_allocated_infra_external_ip:
+ self._first_controller_ip = str(IPAddress(pre_allocated_infra_external_ip))
if not self._first_controller_ip:
self._first_controller_ip = str(IPAddress(first_ip)+1)
file_name,
self._logdir), 'get file')
+ def _run_node_command(self, ip, user, passwd, command):
+ self._execute_shell('sshpass -p {} ssh {} {}@{} {}'.format(passwd,
+ Installer.SSH_OPTS,
+ user,
+ ip,
+ command), 'run command: {}'.format(command))
+
def _get_node_logs(self, ip, user, passwd):
self._get_file(ip, user, passwd, '/srv/deployment/log/cm.log')
self._get_file(ip, user, passwd, '/srv/deployment/log/bootstrap.log')
self._get_file(ip, user, passwd, '/var/log/ironic', recursive=True)
+ def _create_hosts_file(self, file_name):
+ with open(file_name, 'w') as hosts_file:
+ for host in self._uc['hosts'].keys():
+ hosts_file.write('{}\n'.format(host))
+
def _get_journal_logs(self, ip, user, passwd):
+ hosts_file_name = 'host_names'
+ hosts_file_path = '{}/{}'.format(self._logdir, hosts_file_name)
+ self._create_hosts_file(hosts_file_name)
+
+ host_list = ' '.join(self._uc['hosts'].keys())
+
+ self._put_file(ip, user, passwd, hosts_file_name)
self._put_file(ip, user, passwd, '/opt/scripts/get_journals.sh')
- self._put_file(ip, user, passwd, '/opt/scripts/print_hosts.py')
- self._execute_shell('sh ./get_journals.sh', 'run get_journals.sh')
+ self._run_node_command(ip, user, passwd, 'sh ./get_journals.sh {}'.format(hosts_file_name))
self._get_file(ip, user, passwd, '/tmp/node_journals.tgz')
bmc_host = bmc.get_host()
bmc_user = bmc.get_user()
bmc_passwd = bmc.get_passwd()
-
+ bmc_priv_level = bmc.get_priv_level()
+
log_file = '{}/cat_bootstrap.log'.format(self._logdir)
try:
- cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, admin_user, admin_passwd)
+ cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, bmc_priv_level, admin_user, admin_passwd)
cat_file.cat('/srv/deployment/log/bootstrap.log', log_file)
except CatFileException as ex:
logging.info('Could not cat file from console: %s', str(ex))
- cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, 'root', 'root')
+ cat_file = CatFile(bmc_host, bmc_user, bmc_passwd, bmc_priv_level, 'root', 'root')
cat_file.cat('/srv/deployment/log/bootstrap.log', log_file)
def get_logs(self, admin_passwd):
self._set_progress('Wait for bootup')
self._first_controller_bmc.wait_for_bootup()
+ self._set_progress('Wait deployment start')
+
self._first_controller_bmc.close()
except BMCException as ex:
logging.error('Installation failed: %s', str(ex))