這期內(nèi)容當中小編將會給大家?guī)碛嘘P(guān) 關(guān)于nova-manage service list檢測服務狀態(tài)原理 是什么,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)是一家專業(yè)提供乳山企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司、H5建站、小程序制作等業(yè)務。10年已為乳山眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進行中。
環(huán)境:centos6.5 openstack ice版
1、
2、
3、
vim /usr/bin/nova-manage
load_entry_point('nova==2014.1.1', 'console_scripts', 'nova-manage')()
第一個參數(shù)定向到 /usr/lib/python2.6/site-packages/nova-2014.1.1-py2.6.egg-info/
然后搜索EGG-INFO/entry_points.txt
vim /usr/lib/python2.6/site-packages/nova-2014.1.1-py2.6.egg-info/entry_points.txt |
搜索
load_entry_point('nova==2014.1.1', 'console_scripts', 'nova-manage')() |
第二、第三個參數(shù):
console_scripts、nova-manage
得到入口地址為:
nova-manage = nova.cmd.manage:main |
4、
5、
@args('--host', metavar='<host>', help='Host')
@args('--service', metavar='<service>', 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) #獲取nova service數(shù)據(jù)庫表所有數(shù)據(jù)
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 % ( #此處打印出圖1.1
_('Binary'),
_('Host'),
_('Zone'),
_('Status'),
_('State'),
_('Updated_At')))
for svc in services:
alive = servicegroup_api.service_is_up(svc) #檢測服務是否為alive 、重點解析此處的代碼根據(jù)
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']))
圖1.1:
6、 service_is_up:(根據(jù)到7講解is_up函數(shù))
注:大家可以再下圖中看到,判斷服務狀態(tài),可以有多重方式,有db、還有zookeeper等。從上圖可知本次中使用的為db檢查服務狀態(tài)。
7、講解is_up函數(shù):
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'] #獲取服務最后一次更新時間,或者第一次創(chuàng)建時間,最為心跳時間
if isinstance(last_heartbeat, six.string_types): #此處代碼就是將上面獲取的心跳時間,轉(zhuǎn)換成datetime時間
# 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()) #此處計算出心跳時間與當前時間的差值
LOG.debug('DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s',
{'lhb': str(last_heartbeat), 'el': str(elapsed)})
return abs(elapsed) <= CONF.service_down_time#此處根據(jù)差值來判斷服務是否正常(比較時間為配置文件配置。如下圖:)
nova.conf中:
所以最近更新時間,或者第一次創(chuàng)建時間與當前時間間隔少于CONF.service_down_time(60秒),則認為服務alive
從這里也可以得知為什么控制節(jié)點和計算節(jié)點的時間要一致。
接下來試驗驗證一下:
現(xiàn)在強制修改數(shù)據(jù)庫表中nova-compute的update_at時間:
由2014-08-04 23:51:24修改為:2014-08-04 22:51:24
再來查看狀態(tài):
上述就是小編為大家分享的 關(guān)于nova-manage service list檢測服務狀態(tài)原理 是什么了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享題目:關(guān)于nova-manageservicelist檢測服務狀態(tài)原理是什么
URL分享:http://bm7419.com/article48/psseep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、做網(wǎng)站、搜索引擎優(yōu)化、網(wǎng)頁設(shè)計公司、定制開發(fā)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)