def main(): # pragma: no cover old_args = config_shim(sys.argv) parser = argparse.ArgumentParser(description='''Hardware introspection service for OpenStack Ironic. ''') parser.add_argument('--config-file', dest='config', required=True) # if parse_args is passed None it uses sys.argv instead. args = parser.parse_args(old_args) conf.read(args.config) debug = conf.getboolean('discoverd', 'debug') logging.basicConfig(level=logging.DEBUG if debug else logging.INFO) for third_party in ('urllib3.connectionpool', 'keystonemiddleware.auth_token', 'requests.packages.urllib3.connectionpool'): logging.getLogger(third_party).setLevel(logging.WARNING) if old_args: LOG.warning('"daisy-discoverd <config-file>" syntax is deprecated use' ' "daisy-discoverd --config-file <config-file>" instead') init() app.run(debug=debug, host=conf.get('discoverd', 'listen_address'), port=conf.getint('discoverd', 'listen_port'))
def before_processing(self, node_info): """Validate information about network interfaces.""" bmc_address = node_info.get('ipmi_address') compat = conf.getboolean('discoverd', 'ports_for_inactive_interfaces') if 'interfaces' not in node_info and 'macs' in node_info: LOG.warning('Using "macs" field is deprecated, please ' 'update your discovery ramdisk') node_info['interfaces'] = { 'dummy%d' % i: {'mac': m} for i, m in enumerate(node_info['macs'])} compat = True valid_interfaces = { n: iface for n, iface in node_info['interfaces'].items() if (netutils.is_valid_mac(iface.get('mac')) and (compat or iface.get('ip'))) } valid_macs = [iface['mac'] for iface in valid_interfaces.values()] if valid_interfaces != node_info['interfaces']: LOG.warning( 'The following interfaces were invalid or not eligible in ' 'introspection data for node with BMC %(ipmi_address)s and ' 'were excluded: %(invalid)s', {'invalid': {n: iface for n, iface in node_info['interfaces'].items() if n not in valid_interfaces}, 'ipmi_address': bmc_address}) LOG.info('Eligible interfaces are %s', valid_interfaces) node_info['interfaces'] = valid_interfaces node_info['macs'] = valid_macs
def before_update(self, node, ports, node_info): """Update node with scheduler properties.""" overwrite = conf.getboolean('discoverd', 'overwrite_existing') patch = [{'op': 'add', 'path': '/properties/%s' % key, 'value': str(node_info[key])} for key in self.KEYS if overwrite or not node.properties.get(key)] return patch, {}
def before_update(self, node, ports, node_info): """Update node with scheduler properties.""" overwrite = conf.getboolean('discoverd', 'overwrite_existing') patch = [{ 'op': 'add', 'path': '/properties/%s' % key, 'value': str(node_info[key]) } for key in self.KEYS if overwrite or not node.properties.get(key)] return patch, {}
def init(): if conf.getboolean('discoverd', 'authenticate'): utils.add_auth_middleware(app) else: LOG.warning('Starting unauthenticated, please check configuration') node_cache.init() if conf.getint('discoverd', 'timeout') > 0: period = conf.getint('discoverd', 'clean_up_period') eventlet.greenthread.spawn_n(periodic_clean_up, period) else: LOG.warning('Timeout is disabled in configuration')
def check_auth(request): """Check authentication on request. :param request: Flask request :raises: utils.Error if access is denied """ if not conf.getboolean('discoverd', 'authenticate'): return if request.headers.get('X-Identity-Status').lower() == 'invalid': raise Error('Authentication required', code=401) roles = (request.headers.get('X-Roles') or '').split(',') if 'admin' not in roles: LOG.error('Role "admin" not in user role list %s', roles) raise Error('Access denied', code=403)
def before_processing(self, node_info): """Validate information about network interfaces.""" bmc_address = node_info.get('ipmi_address') compat = conf.getboolean('discoverd', 'ports_for_inactive_interfaces') if 'interfaces' not in node_info and 'macs' in node_info: LOG.warning('Using "macs" field is deprecated, please ' 'update your discovery ramdisk') node_info['interfaces'] = { 'dummy%d' % i: { 'mac': m } for i, m in enumerate(node_info['macs']) } compat = True valid_interfaces = { n: iface for n, iface in node_info['interfaces'].items() if (netutils.is_valid_mac(iface.get('mac')) and ( compat or iface.get('ip'))) } valid_macs = [iface['mac'] for iface in valid_interfaces.values()] if valid_interfaces != node_info['interfaces']: LOG.warning( 'The following interfaces were invalid or not eligible in ' 'introspection data for node with BMC %(ipmi_address)s and ' 'were excluded: %(invalid)s', { 'invalid': { n: iface for n, iface in node_info['interfaces'].items() if n not in valid_interfaces }, 'ipmi_address': bmc_address }) LOG.info('Eligible interfaces are %s', valid_interfaces) node_info['interfaces'] = valid_interfaces node_info['macs'] = valid_macs