Load configuration from file, not env

This commit is contained in:
Dmitry Tantsur 2014-10-03 16:54:23 +02:00
parent edd265e8a3
commit 9143fc7978
3 changed files with 20 additions and 8 deletions

5
example.conf Normal file
View File

@ -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

View File

@ -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()

View File

@ -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):