CMDB服務器管理系統【s5day91】:資產採集相關問題

 

資產採集惟一標識和容許臨時修改主機名python

class AgentClient(BaseClient):

    def exec(self):
        obj = PluginManager()
        server_dict = obj.exec_plugin()
        new_hostname = server_dict['basic']['data']['hostname']
        cert_path = os.path.join(settings.BASEDIR,'conf','cert')

        f = open(cert_path,mode='r')
        old_hostname = f.read()
        f.close()

        if not old_hostname:
            """第一次運行"""
            with open(cert_path,mode='w') as ff:
                ff.write(new_hostname)
        else:
            server_dict['basic']['data']['hostname'] = old_hostname
        print('採集到的服務器信息:',server_dict)
        self.post_server_info(server_dict)

Django補充之事務操做django

def tran(request):
	from django.db import transactio
	try:
		with transaction.atomic():
			models.UserProfile.objec
			models.Server.objects.cr
	except Exception as e:
		return HttpResponse('出現錯誤

	return HttpResponse('執行成功')
相關文章
相關標籤/搜索