Fix bugs around passing master

Was not passing properly and getting stuck sometimes, so modify the
checking and route creation a bit to prevent it. Seems to work.
This commit is contained in:
Joshua Boniface 2019-12-15 00:08:18 -05:00
parent 8202d7e64b
commit 0a94fac407
1 changed files with 11 additions and 8 deletions

View File

@ -41,6 +41,7 @@ class MetadataAPIInstance(object):
self.logger = logger self.logger = logger
self.thread = None self.thread = None
self.md_http_server = None self.md_http_server = None
self.add_routes()
# Add flask routes inside our instance # Add flask routes inside our instance
def add_routes(self): def add_routes(self):
@ -86,7 +87,6 @@ class MetadataAPIInstance(object):
def launch_wsgi(self): def launch_wsgi(self):
try: try:
self.add_routes()
self.md_http_server = gevent.pywsgi.WSGIServer( self.md_http_server = gevent.pywsgi.WSGIServer(
('169.254.169.254', 80), ('169.254.169.254', 80),
self.mdapi, self.mdapi,
@ -106,11 +106,14 @@ class MetadataAPIInstance(object):
self.logger.out('Successfully started Metadata API thread', state='o') self.logger.out('Successfully started Metadata API thread', state='o')
def stop(self): def stop(self):
if not self.md_http_server:
return
self.logger.out('Stopping Metadata API at 169.254.169.254:80', state='i') self.logger.out('Stopping Metadata API at 169.254.169.254:80', state='i')
if self.thread and self.md_http_server:
try: try:
self.md_http_server.stop() self.md_http_server.stop()
self.md_http_server.close() self.md_http_server.close()
self.md_http_server = None
self.logger.out('Successfully stopped Metadata API', state='o') self.logger.out('Successfully stopped Metadata API', state='o')
except Exception as e: except Exception as e:
self.logger.out('Error stopping Metadata API: {}'.format(e), state='e') self.logger.out('Error stopping Metadata API: {}'.format(e), state='e')