import logging
import sys

import eventlet
from flask import Flask, request


from ironic_discoverd.discoverd import (CONF, LOG, process, discover,
                                        Firewall, get_client)


eventlet.monkey_patch()

app = Flask(__name__)


@app.route('/v1/continue', methods=['POST'])
def post_continue():
    data = request.get_json(force=True)
    LOG.debug("Got JSON %s, going into processing thread", data)
    eventlet.greenthread.spawn_n(process, data)
    return "{}", 202, {"content-type": "application/json"}


@app.route('/v1/discover', methods=['POST'])
def post_discover():
    data = request.get_json(force=True)
    LOG.debug("Got JSON %s, going into processing thread", data)
    eventlet.greenthread.spawn_n(discover, data)
    return "{}", 202, {"content-type": "application/json"}


def periodic_update():
    ironic = get_client()
    while True:
        LOG.debug('Running periodic update of filters')
        Firewall.update_filters(ironic)
        eventlet.greenthread.sleep(15)


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)
Firewall.init()
eventlet.greenthread.spawn_n(periodic_update)

app.run(debug=debug, host=CONF.get('discoverd', 'listen_address'),
        port=CONF.getint('discoverd', 'listen_port'))

@@ -96,118 +96,25 @@
 verd
-.discoverd import (CONF, LOG, process, discover,%0A                                        Firewall, get_client)
+ import discoverd
 %0A%0A%0Ae
@@ -159,16 +159,36 @@
 name__)%0A
+LOG = discoverd.LOG%0A
 %0A%0A@app.r
@@ -385,16 +385,26 @@
 spawn_n(
+discoverd.
 process,
@@ -667,32 +667,42 @@
 nthread.spawn_n(
+discoverd.
 discover, data)%0A
@@ -798,16 +798,26 @@
 ronic = 
+discoverd.
 get_clie
@@ -901,16 +901,26 @@
         
+discoverd.
 Firewall
@@ -1059,16 +1059,26 @@
 gv%5B0%5D)%0A%0A
+discoverd.
 CONF.rea
@@ -1100,16 +1100,26 @@
 debug = 
+discoverd.
 CONF.get
@@ -1217,16 +1217,26 @@
 g.INFO)%0A
+discoverd.
 Firewall
@@ -1243,16 +1243,16 @@
 .init()%0A
-
 eventlet
@@ -1316,16 +1316,26 @@
 g, host=
+discoverd.
 CONF.get
@@ -1380,16 +1380,26 @@
    port=
+discoverd.
 CONF.get

Refactor __main__ to import only discoverd module, not specific items