Authored by root

Fix sync bug

... ... @@ -147,6 +147,19 @@ class EMRClusterScanner(object):
return False
else:
return True
def checkDNS(self):
check_cmd = 'ansible-playbook -i {0} {1} --check'.format(self.inventoryFile,self.playbook_resolv)
execute_cmd = 'ansible-playbook -i {0} {1}'.format(self.inventoryFile,self.playbook_resolv)
output = os.popen(check_cmd).read()
if 'changed=1' in output:
print '检测到未变更主机!'
print '开始执行变更'
os.popen(execute_cmd)
else:
print '主机配置已最新'
return True
def updateEMRInventory(self, emrName):
#比对当前与最新的Inventory ip列表,相同则pass不同则更新
... ... @@ -182,6 +195,9 @@ class EMRClusterScanner(object):
print 'Running playbook to sync DNS...'
syncResult = self.syncDNS(emrName)
if syncResult:
print 'Running playbook to sync DNS...'
syncResult = self.syncDNS(emrName)
if syncResult:
print 'DNS synced'
else:
print 'DNS sync failed'
... ... @@ -192,6 +208,7 @@ class EMRClusterScanner(object):
def start_daemon(self):
#以守护进程的状态运行此EMR扫描程序
while True:
self.checkDNS()
for emrName in self.emrNameMap:
try:
result = self.updateEMRInventory(emrName)
... ...