From a659306272542dd38420cb118cc7b04b1e8cf377 Mon Sep 17 00:00:00 2001 From: Mario Villaplana Date: Wed, 18 Jan 2017 16:48:01 +0000 Subject: Rescue extension for CoreOS with DHCP tenant networks This patch adds support for rescue mode with DHCP tenant networks in CoreOS. Applying network config from a configdrive is not yet supported but will be in a future patch. Co-Authored-By: Jay Faulkner Co-Authored-By: Taku Izumi Co-Authored-By: Annie Lezil Co-Authored-By: Aparna Co-Authored-By: Shivanand Tendulker Change-Id: I7898ff22800dedba73d7fbfb3801378867abe183 Partial-Bug: 1526449 --- ironic_python_agent/agent.py | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'ironic_python_agent/agent.py') diff --git a/ironic_python_agent/agent.py b/ironic_python_agent/agent.py index c3d81e1b..cf1d84f2 100644 --- a/ironic_python_agent/agent.py +++ b/ironic_python_agent/agent.py @@ -192,6 +192,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. @@ -316,6 +318,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 @@ -369,24 +395,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() -- cgit v1.2.1