def add(self, username, password, port, address, domain_name, libvirt_uri, libvirt_sasl_username, libvirt_sasl_password): # check libvirt's connection and if domain exist prior to adding it utils.check_libvirt_connection_and_domain( libvirt_uri, domain_name, sasl_username=libvirt_sasl_username, sasl_password=libvirt_sasl_password) domain_path = os.path.join(utils.CONFIG_PATH, domain_name) try: os.makedirs(domain_path) except OSError as e: if e.errno == errno.EEXIST: sys.exit('Domain %s already exist' % domain_name) config_path = os.path.join(domain_path, 'config') with open(config_path, 'w') as f: config = configparser.ConfigParser() config.add_section(DEFAULT_SECTION) config.set(DEFAULT_SECTION, 'username', username) config.set(DEFAULT_SECTION, 'password', password) config.set(DEFAULT_SECTION, 'port', port) config.set(DEFAULT_SECTION, 'address', address) config.set(DEFAULT_SECTION, 'domain_name', domain_name) config.set(DEFAULT_SECTION, 'libvirt_uri', libvirt_uri) if libvirt_sasl_username and libvirt_sasl_password: config.set(DEFAULT_SECTION, 'libvirt_sasl_username', libvirt_sasl_username) config.set(DEFAULT_SECTION, 'libvirt_sasl_password', libvirt_sasl_password) config.write(f)
def start(self, domain_name): domain_path = os.path.join(utils.CONFIG_PATH, 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 daemon.DaemonContext(stderr=sys.stderr, files_preserve=[ LOG.handler.stream, ]): # FIXME(lucasagomes): pyghmi start the sockets when the # class is instantiated, therefore we need to create the object # within the daemon context 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(os.getpid())) LOG.info('Virtual BMC for domain %s started', domain_name) vbmc.listen()
def start(self, domain_name): domain_path = os.path.join(utils.CONFIG_PATH, 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 daemon.DaemonContext(stderr=sys.stderr, files_preserve=[LOG.handler.stream, ]): # FIXME(lucasagomes): pyghmi start the sockets when the # class is instantiated, therefore we need to create the object # within the daemon context 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(os.getpid())) LOG.info('Virtual BMC for domain %s started', domain_name) vbmc.listen()