diff --git a/example.conf b/example.conf new file mode 100644 index 000000000..b2257f247 --- /dev/null +++ b/example.conf @@ -0,0 +1,5 @@ +[discoverd] +os_auth_url = http://127.0.0.1:5000/v2.0 +os_username = admin +os_password = password +os_tenant_name = admin diff --git a/ironic_discoverd/__main__.py b/ironic_discoverd/__main__.py index a9f31c466..6d8b9b6a2 100644 --- a/ironic_discoverd/__main__.py +++ b/ironic_discoverd/__main__.py @@ -1,10 +1,11 @@ import logging +import sys import threading import time from flask import Flask, request -from ironic_discoverd.discoverd import (LOG, process, start, +from ironic_discoverd.discoverd import (CONF, LOG, process, start, Firewall, get_client) @@ -37,13 +38,19 @@ def periodic_update(event, ironic): time.sleep(1) -logging.basicConfig(level=logging.INFO) +if len(sys.argv) < 2: + sys.exit("Usage: %s config-file" % sys.argv[0]) + +CONF.read(sys.argv[1]) +debug = CONF.getboolean('discoverd', 'debug') + +logging.basicConfig(level=logging.DEBUG if debug else logging.INFO) ironic = get_client() Firewall.init() event = threading.Event() threading.Thread(target=periodic_update, args=(event, ironic)).start() try: - app.run(debug=True, host='0.0.0.0', port=5050) + app.run(debug=debug, host='0.0.0.0', port=5050) finally: LOG.info('Waiting for background thread to shutdown') event.set() diff --git a/ironic_discoverd/discoverd.py b/ironic_discoverd/discoverd.py index 4250bc408..f9be30fb1 100644 --- a/ironic_discoverd/discoverd.py +++ b/ironic_discoverd/discoverd.py @@ -1,5 +1,5 @@ +import ConfigParser import logging -import os import re from subprocess import call, check_call import threading @@ -8,14 +8,14 @@ from ironicclient import client, exceptions LOG = logging.getLogger("discoverd") -OS_ARGS = dict((k.lower(), v) - for (k, v) in os.environ.items() - if k.startswith('OS_')) ALLOW_SEARCH_BY_MAC = True +CONF = ConfigParser.ConfigParser(defaults={'debug': 'false'}) +OS_ARGS = ('os_password', 'os_username', 'os_auth_url', 'os_tenant_name') def get_client(): - return client.get_client(1, **OS_ARGS) + args = dict((k, CONF.get('discoverd', k)) for k in OS_ARGS) + return client.get_client(1, **args) def is_valid_mac(address):