Exemple #1
0
    def _parse_config(self, domain_name):
        config_path = os.path.join(self.config_dir, domain_name, 'config')
        if not os.path.exists(config_path):
            raise exception.DomainNotFound(domain=domain_name)

        try:
            config = configparser.ConfigParser()
            config.read(config_path)

            bmc = {}
            for item in self.VBMC_OPTIONS:
                try:
                    value = config.get(DEFAULT_SECTION, item)
                except configparser.NoOptionError:
                    value = None

                bmc[item] = value

            # Port needs to be int
            bmc['port'] = config.getint(DEFAULT_SECTION, 'port')

            return bmc

        except OSError:
            raise exception.DomainNotFound(domain=domain_name)
Exemple #2
0
    def delete(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)

        try:
            self.stop(domain_name)
        except exception.VirtualBMCError:
            pass

        shutil.rmtree(domain_path)
Exemple #3
0
    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'])
Exemple #4
0
    def stop(self, domain_name):
        LOG.debug('Stopping Virtual BMC for domain %s', 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)

        pidfile_path = os.path.join(domain_path, 'pid')
        pid = None
        try:
            with open(pidfile_path, 'r') as f:
                pid = int(f.read())
        except (IOError, ValueError):
            raise exception.VirtualBMCError(
                'Error stopping the domain %s: PID file not '
                'found' % domain_name)
        else:
            os.remove(pidfile_path)

        try:
            os.kill(pid, signal.SIGKILL)
        except OSError:
            pass
Exemple #5
0
    def _parse_config(self, domain_name):
        config_path = os.path.join(self.config_dir, domain_name, 'config')
        if not os.path.exists(config_path):
            raise exception.DomainNotFound(domain=domain_name)

        config = configparser.ConfigParser()
        config.read(config_path)

        bmc = {}
        for item in ('username', 'password', 'address', 'domain_name',
                     'libvirt_uri', 'libvirt_sasl_username',
                     'libvirt_sasl_password'):
            try:
                value = config.get(DEFAULT_SECTION, item)
            except configparser.NoOptionError:
                value = None

            bmc[item] = value

        # Port needs to be int
        bmc['port'] = config.getint(DEFAULT_SECTION, 'port')

        return bmc
Exemple #6
0
def get_libvirt_domain(conn, domain):
    try:
        return conn.lookupByName(domain)
    except libvirt.libvirtError:
        raise exception.DomainNotFound(domain=domain)