同步信息时机器对象保存项目名称到tags

This commit is contained in:
chenzuoqing 2021-12-01 11:47:16 +08:00
parent 1b6eb7147b
commit b2e7e18f8a
1 changed files with 7 additions and 2 deletions

View File

@ -111,8 +111,13 @@ class ServerSyncView(CreateMixin):
try:
if not host:
hostObj, _ = Host.get_or_create(
public_ip=ip, defaults=dict(public_ip=ip, created=datetime.datetime.now()))
proj = self.project.fullname()
hostObj, created = Host.get_or_create(
public_ip=ip, defaults=dict(public_ip=ip, tags=[proj], created=datetime.datetime.now()))
# 项目写入机器的tags
if not created and proj not in hostObj.tags:
hostObj.tags.append(proj)
hostObj.save()
host = hostObj.id
hosts[ip] = hostObj.id
if not channel: