From b799682ac24878e7eaaa44849b78dfd293ea7333 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Thu, 11 Jul 2019 18:24:26 +0800 Subject: [PATCH] fix: notify message use brand insteand of hypervisor --- .../compute/content/SERVER_CHANGE_FLAVOR | 2 +- .../compute/content/SERVER_CREATED | 2 +- .../compute/content/SERVER_CREATED_ADMIN | 2 +- .../compute/content/SERVER_DELETED | 2 +- .../compute/content/SERVER_DELETED_ADMIN | 2 +- .../compute/content/SERVER_REBUILD_ROOT | 2 +- .../compute/title/SERVER_CHANGE_FLAVOR | 2 +- .../compute/title/SERVER_CREATED | 2 +- .../compute/title/SERVER_CREATED_ADMIN | 2 +- .../compute/title/SERVER_DELETED | 2 +- .../compute/title/SERVER_DELETED_ADMIN | 2 +- .../compute/title/SERVER_REBUILD_ROOT | 2 +- pkg/compute/models/guest_actions.go | 4 +++ pkg/compute/models/managedresource.go | 25 +++++++++++++++---- 14 files changed, 36 insertions(+), 17 deletions(-) diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CHANGE_FLAVOR b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CHANGE_FLAVOR index abd3ec1c22..ae88892b55 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CHANGE_FLAVOR +++ b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CHANGE_FLAVOR @@ -1 +1 @@ -您的{{ .hypervisor }}主机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。 +您的{{ .brand }}主机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED index b40ad4eeca..794534b586 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED +++ b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED @@ -1 +1 @@ -您的{{ .hypervisor }}主机{{ .name }}已经创建成功,服务器IP地址为{{ .ips }},{{ if .account }}初始帐号为{{ .account }},{{ end }}{{ if .keypair }}访问ssh密钥为{{ .keypair }},{{ end }}{{ if .password }}初始密码为{{ .password }},{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问云主机。 +您的{{ .brand }}主机{{ .name }}已经创建成功,服务器IP地址为{{ .ips }},{{ if .account }}初始帐号为{{ .account }},{{ end }}{{ if .keypair }}访问ssh密钥为{{ .keypair }},{{ end }}{{ if .password }}初始密码为{{ .password }},{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问云主机。 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED_ADMIN b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED_ADMIN index ea3967773e..ac8116d83f 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED_ADMIN +++ b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_CREATED_ADMIN @@ -1 +1 @@ -项目{{ .tenant }}的{{ .hypervisor }}主机{{ .name }}已经创建成功。 +项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经创建成功。 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED index e698dab091..fdb4991a1c 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED +++ b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED @@ -1 +1 @@ -您的{{ .hypervisor }}主机{{ .name }}已经删除。 +您的{{ .brand }}主机{{ .name }}已经删除。 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED_ADMIN b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED_ADMIN index fba006c849..9486f23ac3 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED_ADMIN +++ b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_DELETED_ADMIN @@ -1 +1 @@ -项目{{ .tenant }}的{{ .hypervisor }}主机{{ .name }}已经删除。 +项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经删除。 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_REBUILD_ROOT b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_REBUILD_ROOT index 4709ad8784..f3e3dd4ae0 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_REBUILD_ROOT +++ b/build/region/root/opt/yunion/share/notify_templates/compute/content/SERVER_REBUILD_ROOT @@ -1 +1 @@ -您的{{ .hypervisor }}主机{{ .name }}重装系统成功,{{ if .account }}初始帐号为{{ .account }},{{ end }}{{ if .keypair }}访问密钥为{{ .keypair }},{{ end }}{{ if .password }}初始密码为{{ .password }},{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问云主机。 +您的{{ .brand }}主机{{ .name }}重装系统成功,{{ if .account }}初始帐号为{{ .account }},{{ end }}{{ if .keypair }}访问密钥为{{ .keypair }},{{ end }}{{ if .password }}初始密码为{{ .password }},{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问云主机。 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CHANGE_FLAVOR b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CHANGE_FLAVOR index abd3ec1c22..ae88892b55 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CHANGE_FLAVOR +++ b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CHANGE_FLAVOR @@ -1 +1 @@ -您的{{ .hypervisor }}主机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。 +您的{{ .brand }}主机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED index 8a9d9c7352..bce76701de 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED +++ b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED @@ -1 +1 @@ -{{ .hypervisor }}主机{{ .Name }}创建成功 +{{ .brand }}主机{{ .Name }}创建成功 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED_ADMIN b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED_ADMIN index cea68610d1..0b3670d8b0 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED_ADMIN +++ b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_CREATED_ADMIN @@ -1 +1 @@ -项目{{ .tenant }}的{{ .hypervisor }}主机{{ .name }}已经创建成功 +项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经创建成功 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED index 208ffffeea..88e0c7bc7c 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED +++ b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED @@ -1 +1 @@ -{{ .hypervisor }}主机{{ .name }}删除通知 +{{ .brand }}主机{{ .name }}删除通知 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED_ADMIN b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED_ADMIN index a7cf1bbb6b..20e8c288db 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED_ADMIN +++ b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_DELETED_ADMIN @@ -1 +1 @@ -项目{{ .tenant }}的{{ .hypervisor }}主机{{ .name }}已经删除 +项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经删除 diff --git a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_REBUILD_ROOT b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_REBUILD_ROOT index 15c65dfc10..4e275a206a 100644 --- a/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_REBUILD_ROOT +++ b/build/region/root/opt/yunion/share/notify_templates/compute/title/SERVER_REBUILD_ROOT @@ -1 +1 @@ -{{ .hypervisor }}主机{{ .name }}重装系统成功 +{{ .brand }}主机{{ .name }}重装系统成功 diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 5d3a6a3352..8b6db54d2d 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -686,6 +686,10 @@ func (self *SGuest) NotifyServerEvent(userCred mcclient.TokenCredential, event s kwargs := jsonutils.NewDict() kwargs.Add(jsonutils.NewString(self.Name), "name") kwargs.Add(jsonutils.NewString(self.Hypervisor), "hypervisor") + host := self.GetHost() + if host != nil { + kwargs.Add(jsonutils.NewString(host.GetBrand()), "brand") + } if loginInfo { kwargs.Add(jsonutils.NewString(self.getNotifyIps()), "ips") osName := meta[api.VM_METADATA_OS_NAME] diff --git a/pkg/compute/models/managedresource.go b/pkg/compute/models/managedresource.go index 728b63c135..9c9bc04a0d 100644 --- a/pkg/compute/models/managedresource.go +++ b/pkg/compute/models/managedresource.go @@ -58,7 +58,6 @@ func (self *SManagedResourceBase) GetCustomizeColumns(ctx context.Context, userC info := map[string]string{ "manager": provider.GetName(), "manager_id": provider.GetId(), - "provider": provider.Provider, } if len(provider.ProjectId) > 0 { info["manager_project_id"] = provider.ProjectId @@ -73,6 +72,14 @@ func (self *SManagedResourceBase) GetCustomizeColumns(ctx context.Context, userC account := provider.GetCloudaccount() info["account"] = account.GetName() info["account_id"] = account.GetId() + info["provider"] = account.Provider + info["brand"] = account.Brand + + info["account_domain_id"] = account.DomainId + dc, err := db.TenantCacheManager.FetchDomainById(appctx.Background, account.DomainId) + if err == nil { + info["account_domain"] = dc.Name + } return jsonutils.Marshal(info).(*jsonutils.JSONDict) } @@ -100,11 +107,19 @@ func (self *SManagedResourceBase) GetDriver() (cloudprovider.ICloudProvider, err } func (self *SManagedResourceBase) GetProviderName() string { - driver := self.GetCloudprovider() - if driver != nil { - return driver.Provider + account := self.GetCloudaccount() + if account != nil { + return account.Provider } - return "" + return api.CLOUD_PROVIDER_ONECLOUD +} + +func (self *SManagedResourceBase) GetBrand() string { + account := self.GetCloudaccount() + if account != nil { + return account.Brand + } + return api.CLOUD_PROVIDER_ONECLOUD } func (self *SManagedResourceBase) IsManaged() bool {