summaryrefslogtreecommitdiff
path: root/ironic_python_agent/agent.py
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-12-11 21:14:09 +0000
committerGerrit Code Review <review@openstack.org>2017-12-11 21:14:09 +0000
commit893c63f24a2538c4f9209124a028f8dfb249f16e (patch)
tree135186ce4d5f0954985539a356a4c91d9d1500cf /ironic_python_agent/agent.py
parentc03eeea6d0b45c00a1c4d3232eab52f91dd7486f (diff)
parenta659306272542dd38420cb118cc7b04b1e8cf377 (diff)
downloadironic-python-agent-893c63f24a2538c4f9209124a028f8dfb249f16e.tar.gz
Merge "Rescue extension for CoreOS with DHCP tenant networks"
Diffstat (limited to 'ironic_python_agent/agent.py')
-rw-r--r--ironic_python_agent/agent.py45
1 files changed, 27 insertions, 18 deletions
diff --git a/ironic_python_agent/agent.py b/ironic_python_agent/agent.py
index ce313a7b..0df622f8 100644
--- a/ironic_python_agent/agent.py
+++ b/ironic_python_agent/agent.py
@@ -193,6 +193,8 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
self.network_interface = network_interface
self.standalone = standalone
self.hardware_initialization_delay = hardware_initialization_delay
+ # IPA will stop serving requests and exit after this is set to False
+ self.serve_api = True
def get_status(self):
"""Retrieve a serializable status.
@@ -322,6 +324,30 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
LOG.warning("No valid network interfaces found. "
"Node lookup will probably fail.")
+ def serve_ipa_api(self):
+ """Serve the API until an extension terminates it."""
+ if netutils.is_ipv6_enabled():
+ # Listens to both IP versions, assuming IPV6_V6ONLY isn't enabled,
+ # (the default behaviour in linux)
+ simple_server.WSGIServer.address_family = socket.AF_INET6
+ server = simple_server.WSGIServer((self.listen_address.hostname,
+ self.listen_address.port),
+ simple_server.WSGIRequestHandler)
+ server.set_app(self.api)
+
+ if not self.standalone and self.api_url:
+ # Don't start heartbeating until the server is listening
+ self.heartbeater.start()
+
+ while self.serve_api:
+ try:
+ server.handle_request()
+ except BaseException as e:
+ msg = "Failed due to unknow exception. Error %s" % e
+ LOG.exception(msg)
+ raise errors.IronicAPIError(msg)
+ LOG.info('shutting down')
+
def run(self):
"""Run the Ironic Python Agent."""
# Get the UUID so we can heartbeat to Ironic. Raises LookupNodeError
@@ -375,24 +401,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
LOG.error('Neither ipa-api-url nor inspection_callback_url'
'found, please check your pxe append parameters.')
- if netutils.is_ipv6_enabled():
- # Listens to both IP versions, assuming IPV6_V6ONLY isn't enabled,
- # (the default behaviour in linux)
- simple_server.WSGIServer.address_family = socket.AF_INET6
- wsgi = simple_server.make_server(
- self.listen_address.hostname,
- self.listen_address.port,
- self.api,
- server_class=simple_server.WSGIServer)
-
- if not self.standalone and self.api_url:
- # Don't start heartbeating until the server is listening
- self.heartbeater.start()
-
- try:
- wsgi.serve_forever()
- except BaseException:
- LOG.exception('shutting down')
+ self.serve_ipa_api()
if not self.standalone and self.api_url:
self.heartbeater.stop()