From 69e18bae85e7d9108fedc7f55347a88534591c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Tue, 29 Aug 2023 15:43:01 +0800 Subject: [PATCH] fix(region): hostname length (#17866) --- pkg/cloudcommon/db/standalone_anon.go | 2 +- pkg/compute/models/guests.go | 3 +++ pkg/compute/models/hostnameresource.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/cloudcommon/db/standalone_anon.go b/pkg/cloudcommon/db/standalone_anon.go index 51f663ad803..519d3b59d69 100644 --- a/pkg/cloudcommon/db/standalone_anon.go +++ b/pkg/cloudcommon/db/standalone_anon.go @@ -47,7 +47,7 @@ type SStandaloneAnonResourceBase struct { Id string `width:"128" charset:"ascii" primary:"true" list:"user" create:"optional" json:"id"` // 资源描述信息 - Description string `width:"256" charset:"utf8" get:"user" list:"user" update:"user" create:"optional" json:"description"` + Description string `length:"0" charset:"utf8" get:"user" list:"user" update:"user" create:"optional" json:"description"` // 是否是模拟资源, 部分从公有云上同步的资源并不真实存在, 例如宿主机 // list 接口默认不会返回这类资源,除非显示指定 is_emulate=true 过滤参数 diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 619cf722ff5..84434a291db 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -2967,6 +2967,9 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token } } hostname := pinyinutils.Text2Pinyin(extVM.GetHostname()) + if len(hostname) > 128 { + hostname = hostname[:128] + } if extVM.GetName() != hostname { self.Hostname = hostname } diff --git a/pkg/compute/models/hostnameresource.go b/pkg/compute/models/hostnameresource.go index 39663011103..907fa859426 100644 --- a/pkg/compute/models/hostnameresource.go +++ b/pkg/compute/models/hostnameresource.go @@ -26,7 +26,7 @@ import ( ) type SHostnameResourceBase struct { - Hostname string `width:"60" charset:"ascii" nullable:"true" list:"user" create:"optional" update:"user"` + Hostname string `width:"128" charset:"ascii" nullable:"true" list:"user" create:"optional" update:"user"` } type SHostnameResourceBaseManager struct {