diff --git a/go.mod b/go.mod index 9b15821ccd..51174492ab 100644 --- a/go.mod +++ b/go.mod @@ -89,7 +89,7 @@ require ( k8s.io/cluster-bootstrap v0.19.3 k8s.io/cri-api v0.22.17 moul.io/http2curl/v2 v2.3.0 - yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240423080301-f3d434d413c4 + yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240424091412-88cd35a379f2 yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401 yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91 diff --git a/go.sum b/go.sum index 8f18e73e92..b44a67e8a6 100644 --- a/go.sum +++ b/go.sum @@ -1209,8 +1209,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240423080301-f3d434d413c4 h1:/CY5NV5Bw8g5sLkgFO+LcEYX8XfOO8zcark59smHdZo= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240423080301-f3d434d413c4/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240424091412-88cd35a379f2 h1:1k9Dcojz2CI+UKnTQJsPG5qiISd+c/YWiwXVnS6912k= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240424091412-88cd35a379f2/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk= yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug= yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws= yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634= diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 7198b39543..0f34536ea3 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -3041,6 +3041,16 @@ func (g *SGuest) SyncOsInfo(ctx context.Context, userCred mcclient.TokenCredenti return g.GetDriver().SyncOsInfo(ctx, userCred, g, extVM) } +func (g *SGuest) SyncHostname(ext cloudprovider.ICloudVM) { + hostname := pinyinutils.Text2Pinyin(ext.GetHostname()) + if len(hostname) > 128 { + hostname = hostname[:128] + } + if len(hostname) > 0 { + g.Hostname = hostname + } +} + func (g *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.TokenCredential, provider cloudprovider.ICloudProvider, host *SHost, extVM cloudprovider.ICloudVM, syncOwnerId mcclient.IIdentityProvider, syncStatus bool) error { recycle := false @@ -3055,13 +3065,9 @@ func (g *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.TokenCre g.Name = newName } } - hostname := pinyinutils.Text2Pinyin(extVM.GetHostname()) - if len(hostname) > 128 { - hostname = hostname[:128] - } - if extVM.GetName() != hostname { - g.Hostname = hostname - } + + g.SyncHostname(extVM) + if !g.IsFailureStatus() && syncStatus { g.Status = extVM.GetStatus() g.PowerStates = extVM.GetPowerStates() @@ -3176,7 +3182,11 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient. guest.Bios = string(extVM.GetBios()) guest.Machine = extVM.GetMachine() guest.Hypervisor = extVM.GetHypervisor() - guest.Hostname = pinyinutils.Text2Pinyin(extVM.GetHostname()) + hostname := extVM.GetHostname() + if len(hostname) == 0 { + hostname = extVM.GetName() + } + guest.Hostname = pinyinutils.Text2Pinyin(hostname) guest.InternetMaxBandwidthOut = extVM.GetInternetMaxBandwidthOut() guest.Throughput = extVM.GetThroughput() guest.Description = extVM.GetDescription() diff --git a/vendor/modules.txt b/vendor/modules.txt index d4c711c2f7..1e56e3dbfc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1476,7 +1476,7 @@ sigs.k8s.io/structured-merge-diff/v4/value # sigs.k8s.io/yaml v1.2.0 ## explicit; go 1.12 sigs.k8s.io/yaml -# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240423080301-f3d434d413c4 +# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240424091412-88cd35a379f2 ## explicit; go 1.18 yunion.io/x/cloudmux/pkg/apis yunion.io/x/cloudmux/pkg/apis/billing diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/instance.go index 34511f4283..412366eb09 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/aws/instance.go @@ -223,7 +223,7 @@ func (self *SInstance) GetName() string { } func (self *SInstance) GetHostname() string { - return self.GetName() + return "" } func (self *SInstance) GetGlobalId() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/instance.go index fdd7d5052d..27f883e9d4 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/azure/instance.go @@ -803,7 +803,7 @@ func (self *SInstance) GetName() string { } func (self *SInstance) GetHostname() string { - return self.Name + return "" } func (self *SInstance) GetGlobalId() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ecloud/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ecloud/instance.go index b41ba8e162..38bea5a480 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ecloud/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ecloud/instance.go @@ -98,7 +98,7 @@ func (i *SInstance) GetName() string { } func (i *SInstance) GetHostname() string { - return i.Name + return "" } func (i *SInstance) GetGlobalId() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go index 7dc4ec2148..5cc18c7bb1 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go @@ -220,7 +220,7 @@ func (svm *SVirtualMachine) GetGlobalId() string { } func (svm *SVirtualMachine) GetHostname() string { - return svm.GetName() + return "" } func (svm *SVirtualMachine) GetDescription() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/google/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/google/instance.go index 0359c589fc..1bd8f1512a 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/google/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/google/instance.go @@ -133,7 +133,7 @@ func (region *SRegion) GetInstance(id string) (*SInstance, error) { } func (instance *SInstance) GetHostname() string { - return instance.GetName() + return "" } func (instance *SInstance) fetchMachineType() error { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/nutanix/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/nutanix/instance.go index 90927b28ab..d1ab7faa2d 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/nutanix/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/nutanix/instance.go @@ -224,7 +224,7 @@ func (self *SInstance) GetError() error { } func (self *SInstance) GetHostname() string { - return self.Name + return "" } func (self *SInstance) GetHypervisor() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/oracle/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/oracle/instance.go index 63c8fe18af..ef4a0f8bbe 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/oracle/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/oracle/instance.go @@ -150,7 +150,7 @@ func (self *SInstance) GetName() string { } func (self *SInstance) GetHostname() string { - return self.DisplayName + return "" } func (self *SInstance) GetGlobalId() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/proxmox/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/proxmox/instance.go index 61d831d579..56a9777c59 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/proxmox/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/proxmox/instance.go @@ -284,7 +284,7 @@ func (self *SInstance) GetError() error { } func (self *SInstance) GetHostname() string { - return self.GetName() + return "" } func (self *SInstance) GetHypervisor() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/instance.go index 25a9d15790..16581bfd6a 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/qcloud/instance.go @@ -198,7 +198,7 @@ func (self *SInstance) GetName() string { } func (self *SInstance) GetHostname() string { - return self.GetName() + return "" } func (self *SInstance) GetGlobalId() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ucloud/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ucloud/instance.go index 7a08199d94..91158dd5ae 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ucloud/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ucloud/instance.go @@ -138,7 +138,7 @@ func (self *SInstance) GetName() string { } func (self *SInstance) GetHostname() string { - return self.GetName() + return "" } func (self *SInstance) GetGlobalId() string { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/zstack/instance.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/zstack/instance.go index e4b63bacb9..fd6c721bb3 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/zstack/instance.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/zstack/instance.go @@ -131,7 +131,7 @@ func (instance *SInstance) GetName() string { } func (instance *SInstance) GetHostname() string { - return instance.Name + return "" } func (instance *SInstance) GetGlobalId() string {