def vbmc_runner(bmc_config): show_passwords = CONF['default']['show_passwords'] if show_passwords: show_options = bmc_config else: show_options = utils.mask_dict_password(bmc_config) try: vbmc = VirtualBMC(**bmc_config) except Exception as ex: LOG.error( 'Error running vBMC with configuration ' '%(opts)s: %(error)s', { 'opts': show_options, 'error': ex }) return try: vbmc.listen(timeout=CONF['ipmi']['session_timeout']) except Exception as ex: LOG.info( 'Shutdown vBMC for domain %(domain)s, cause ' '%(error)s', { 'domain': show_options['domain_name'], 'error': ex }) return
def vbmc_runner(bmc_config): # The manager process installs a signal handler for SIGTERM to # propagate it to children. Return to the default handler. signal.signal(signal.SIGTERM, signal.SIG_DFL) show_passwords = CONF['default']['show_passwords'] if show_passwords: show_options = bmc_config else: show_options = utils.mask_dict_password(bmc_config) try: vbmc = VirtualBMC(**bmc_config) except Exception as ex: LOG.exception( 'Error running vBMC with configuration ' '%(opts)s: %(error)s', {'opts': show_options, 'error': ex} ) return try: vbmc.listen(timeout=CONF['ipmi']['session_timeout']) except Exception as ex: LOG.exception( 'Shutdown vBMC for domain %(domain)s, cause ' '%(error)s', {'domain': show_options['domain_name'], 'error': ex} ) return
def start(self, domain_name): domain_path = os.path.join(self.config_dir, domain_name) if not os.path.exists(domain_path): raise exception.DomainNotFound(domain=domain_name) bmc_config = self._parse_config(domain_name) # check libvirt's connection and domain prior to starting the BMC utils.check_libvirt_connection_and_domain( bmc_config['libvirt_uri'], domain_name, sasl_username=bmc_config['libvirt_sasl_username'], sasl_password=bmc_config['libvirt_sasl_password']) # mask the passwords if requested log_config = bmc_config.copy() if not CONF['default']['show_passwords']: log_config = utils.mask_dict_password(bmc_config) LOG.debug( 'Starting a Virtual BMC for domain %(domain)s with the ' 'following configuration options: %(config)s', { 'domain': domain_name, 'config': ' '.join(['%s="%s"' % (k, log_config[k]) for k in log_config]) }) with utils.detach_process() as pid_num: try: vbmc = VirtualBMC(**bmc_config) except Exception as e: msg = ('Error starting a Virtual BMC for domain %(domain)s. ' 'Error: %(error)s' % { 'domain': domain_name, 'error': e }) LOG.error(msg) raise exception.VirtualBMCError(msg) # Save the PID number pidfile_path = os.path.join(domain_path, 'pid') with open(pidfile_path, 'w') as f: f.write(str(pid_num)) LOG.info('Virtual BMC for domain %s started', domain_name) vbmc.listen(timeout=CONF['ipmi']['session_timeout'])
def _show(self, domain_name): bmc_config = self._parse_config(domain_name) show_passwords = CONF['default']['show_passwords'] if show_passwords: show_options = bmc_config else: show_options = utils.mask_dict_password(bmc_config) instance = self._running_domains.get(domain_name) if instance and instance.is_alive(): show_options['status'] = RUNNING else: show_options['status'] = DOWN return show_options
def _show(self, domain_name): running = False try: pidfile_path = os.path.join(self.config_dir, domain_name, 'pid') with open(pidfile_path, 'r') as f: pid = int(f.read()) running = utils.is_pid_running(pid) except (IOError, ValueError): pass bmc_config = self._parse_config(domain_name) bmc_config['status'] = RUNNING if running else DOWN # mask the passwords if requested if not CONF['default']['show_passwords']: bmc_config = utils.mask_dict_password(bmc_config) return bmc_config
def test_mask_dict_password(self): input_dict = {'foo': 'bar', 'password': '******'} output_dict = utils.mask_dict_password(input_dict) expected = {'foo': 'bar', 'password': '******'} self.assertEqual(expected, output_dict)