What is the principle of nova-manage service list detection service status?
In this issue, Xiaobian will bring you about the nova-management service list detection service status principle. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
Environment: centos 6.5 openstack ice version
1、
2、
3、
vim /usr/bin/nova-manage
load_entry_point('nova==2014.1.1', 'console_scripts', 'nova-manage')()
The first argument is directed to/usr/lib/python2.6/site-packages/nova-2014.1.1-py2.6.egg-info/
Then search EGG-INFO/entry_points.txt
vim /usr/lib/python2.6/site-packages/nova-2014.1.1-py2.6.egg-info/entry_points.txt
search
load_entry_point('nova==2014.1.1', 'console_scripts', 'nova-manage')()
Second and third parameters:
console_scripts、nova-manage
Get the entry address:
nova-manage = nova.cmd.manage:main
4、
5、
@args('--host', metavar='', help='Host')
@args('--service', metavar='', help='Nova service')
def list(self, host=None, service=None):
"""Show a list of all running services. Filter by host & service
name
"""
servicegroup_api = servicegroup.API()
ctxt = context.get_admin_context()
services = db.service_get_all(ctxt) #Get all data from nova service database tables
services = availability_zones.set_availability_zones(ctxt, services)
if host:
services = [s for s in services if s['host'] == host]
if service:
services = [s for s in services if s['binary'] == service]
print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
print(print_format % ( #Print Figure 1.1 here
_('Binary'),
_('Host'),
_('Zone'),
_('Status'),
_('State'),
_('Updated_At')))
for svc in services:
alive = servicegroup_api.service_is_up(svc) #Detect whether the service is alive, focus on parsing the code here according to
art = (alive and ":-)") or "XXX"
active = 'enabled'
if svc['disabled']:
active = 'disabled'
print(print_format % (svc['binary'], svc['host'],
svc['availability_zone'], active, art,
svc['updated_at']))
Figure 1.1:
6. service_is_up: (explain the is_up function according to 7)
Note: As you can see in the figure below, there are multiple ways to judge the service status, including db, zookeeper, etc. As can be seen from the above figure, db check service status is used this time.
7. Explain the is_up function:
def is_up(self, service_ref):
"""Moved from nova.utils
Check whether a service is up based on last heartbeat.
"""
last_heartbeat = service_ref <$'updated_at'] or service_ref <$'created_at'] #Get the last update time of the service, or the first creation time, which is the heartbeat time
if isinstance(last_heartbeat, six.string_types): #This code converts the heartbeat time obtained above into datetime time
# NOTE(russellb) If this service_ref came in over rpc via
# conductor, then the timestamp will be a string and needs to be
# converted back to a datetime.
last_heartbeat = timeutils.parse_strtime(last_heartbeat)
else:
# Objects have proper UTC timezones, but the timeutils comparison
# below does not (and will fail)
last_heartbeat = last_heartbeat.replace(tzinfo=None)
# Timestamps in DB are UTC.
elapsed = timeutils.delta_seconds(last_heartbeat, timeutils.utcnow()) #The difference between heartbeat time and current time is calculated here
LOG.debug('DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s',
{'lhb': str(last_heartbeat), 'el': str(elapsed)})
return abs(elapsed)