Change service plugin to choose an alternate ip if needed.
Change-Id: Ia9f107b7993236bc4b30aa149d2765e9e465acbd Closes-Bug: #1461307
This commit is contained in:
parent
b5c441bd36
commit
3eaf9d8afe
|
@ -1,4 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
import psutil
|
||||||
|
from urlparse import urlparse
|
||||||
|
|
||||||
from plugin import Plugin
|
from plugin import Plugin
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ class ServicePlugin(Plugin):
|
||||||
def __init__(self, kwargs):
|
def __init__(self, kwargs):
|
||||||
self.service_name = kwargs['service_name']
|
self.service_name = kwargs['service_name']
|
||||||
self.process_names = kwargs['process_names']
|
self.process_names = kwargs['process_names']
|
||||||
self.service_api_url = kwargs['service_api_url']
|
self.service_api_url = kwargs.get('service_api_url')
|
||||||
self.search_pattern = kwargs['search_pattern']
|
self.search_pattern = kwargs['search_pattern']
|
||||||
|
|
||||||
super(ServicePlugin, self).__init__(kwargs['template_dir'], kwargs['overwrite'])
|
super(ServicePlugin, self).__init__(kwargs['template_dir'], kwargs['overwrite'])
|
||||||
|
@ -49,10 +51,28 @@ class ServicePlugin(Plugin):
|
||||||
config.merge(watch_process([process], self.service_name, process, exact_match=False))
|
config.merge(watch_process([process], self.service_name, process, exact_match=False))
|
||||||
|
|
||||||
if self.service_api_url and self.search_pattern:
|
if self.service_api_url and self.search_pattern:
|
||||||
# Setup an active http_status check on the API
|
# Check if there is something listening on the host/port
|
||||||
log.info("\tConfiguring an http_check for the {0} API.".format(self.service_name))
|
parsed = urlparse(self.service_api_url)
|
||||||
config.merge(service_api_check(self.service_name + '-api', self.service_api_url,
|
host, port = parsed.netloc.split(':')
|
||||||
|
listening = []
|
||||||
|
for connection in psutil.net_connections():
|
||||||
|
if connection.status == psutil.CONN_LISTEN and connection.laddr[1] == int(port):
|
||||||
|
listening.append(connection.laddr[0])
|
||||||
|
|
||||||
|
if len(listening) > 0:
|
||||||
|
# If not listening on localhost or ips then use another local ip
|
||||||
|
if host == 'localhost' and len(set(['0.0.0.0', '::', '::1']) & set(listening)) == 0:
|
||||||
|
api_url = listening[0] + ':' + port
|
||||||
|
else:
|
||||||
|
api_url = self.service_api_url
|
||||||
|
|
||||||
|
# Setup an active http_status check on the API
|
||||||
|
log.info("\tConfiguring an http_check for the {0} API.".format(self.service_name))
|
||||||
|
config.merge(service_api_check(self.service_name + '-api', api_url,
|
||||||
self.search_pattern, self.service_name))
|
self.search_pattern, self.service_name))
|
||||||
|
else:
|
||||||
|
log.info("\tNo process found listening on {0} ".format(port) +
|
||||||
|
"skipping setup of http_check for the {0} API." .format(self.service_name))
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ httplib2
|
||||||
ntplib
|
ntplib
|
||||||
pymongo
|
pymongo
|
||||||
pylint
|
pylint
|
||||||
psutil>=2.0
|
psutil>=2.2.1
|
||||||
python-memcached
|
python-memcached
|
||||||
PyYAML
|
PyYAML
|
||||||
redis
|
redis
|
||||||
simplejson
|
simplejson
|
||||||
supervisor
|
supervisor
|
||||||
tornado
|
tornado
|
||||||
python-monascaclient
|
python-monascaclient
|
||||||
|
|
Loading…
Reference in New Issue