CMDB服务器管理系统【s5day91】:资产采集相关问题

 

资产采集唯一标识和允许临时修改主机名

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补充之事务操作

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('执行成功')

 

posted @ 2018-07-29 12:40  活的潇洒80  阅读(157)  评论(0编辑  收藏  举报