diff --git a/go.mod b/go.mod index f0f78630eb..c194410893 100644 --- a/go.mod +++ b/go.mod @@ -88,7 +88,7 @@ require ( k8s.io/client-go v0.19.3 k8s.io/cluster-bootstrap v0.19.3 moul.io/http2curl/v2 v2.3.0 - yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251022024207-a6ddf356a465 + yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251024142004-e98de79fcabf yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1 yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91 diff --git a/go.sum b/go.sum index 761f2e6e56..ce5bcc1468 100644 --- a/go.sum +++ b/go.sum @@ -1279,8 +1279,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.20251022024207-a6ddf356a465 h1:UQDct7l4uICSmaGsju1BhSFPUEM7xsE+n+7u2GqgvAs= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251022024207-a6ddf356a465/go.mod h1:S9o/TRZsnYWGaGe7o3PpeOv6CgMY8ZJwITYsEnGfOgQ= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251024142004-e98de79fcabf h1:YXvJjd2mhGAYsACGXygfJ5Jti4xHE7E6iD4z7FHbWBo= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251024142004-e98de79fcabf/go.mod h1:S9o/TRZsnYWGaGe7o3PpeOv6CgMY8ZJwITYsEnGfOgQ= yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU= yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws= yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634= diff --git a/vendor/modules.txt b/vendor/modules.txt index ea84f07dc6..6b0ba2d095 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1605,7 +1605,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.20251022024207-a6ddf356a465 +# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20251024142004-e98de79fcabf ## explicit; go 1.21 yunion.io/x/cloudmux/pkg/apis yunion.io/x/cloudmux/pkg/apis/billing diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/host.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/host.go index 1495fcfcfa..68b9f13cf6 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/host.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/host.go @@ -127,6 +127,7 @@ func (region *SRegion) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (*SI for k, v := range opts.Tags { params[fmt.Sprintf("Tag.%d.Key", tagIdx)] = k params[fmt.Sprintf("Tag.%d.Value", tagIdx)] = v + tagIdx++ } resp, err := region.ecsRequest("RunInstances", params) if err != nil { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/instances.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/instances.go index d89461bcd1..657d0f165a 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/instances.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/instances.go @@ -212,6 +212,10 @@ func (ins *SInstance) GetTags() (map[string]string, error) { return tags.GetTags(), nil } +func (ins *SInstance) SetTags(tags map[string]string, replace bool) error { + return ins.getRegion().SetResourceTags("kec-instance", ins.InstanceId, tags, replace) +} + func (ins *SInstance) getRegion() *SRegion { if ins.region != nil { return ins.region @@ -363,7 +367,7 @@ func (ins *SInstance) GetSecurityGroupIds() ([]string, error) { func (ins *SInstance) GetStatus() string { switch ins.InstanceState.Name { - case "block_device_mapping", "scheduling", "updating_password", "rebuilding": + case "block_device_mapping", "scheduling", "updating_password", "rebuilding", "updating_hostname": return api.VM_DEPLOYING case "active": return api.VM_RUNNING diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/secgroup_rules.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/secgroup_rules.go index 7be74812d3..2b5b4669f6 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/secgroup_rules.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/secgroup_rules.go @@ -17,6 +17,7 @@ package ksyun import ( "fmt" "strings" + "time" "yunion.io/x/cloudmux/pkg/cloudprovider" "yunion.io/x/jsonutils" @@ -166,16 +167,19 @@ func (region *SRegion) CreateSecurityGroupRule(groupId string, opts *cloudprovid if len(ruleId) == 0 { return nil, fmt.Errorf("invalid rule create response %s", resp.String()) } - group, err := region.GetSecurityGroup(groupId) - if err != nil { - return nil, err - } - for i := range group.SecurityGroupEntrySet { - if group.SecurityGroupEntrySet[i].SecurityGroupEntryId == ruleId { - group.SecurityGroupEntrySet[i].region = region - group.SecurityGroupEntrySet[i].SecurityGroupId = groupId - return &group.SecurityGroupEntrySet[i], nil + for i := 0; i < 3; i++ { + group, err := region.GetSecurityGroup(groupId) + if err != nil { + return nil, err } + for i := range group.SecurityGroupEntrySet { + if group.SecurityGroupEntrySet[i].SecurityGroupEntryId == ruleId { + group.SecurityGroupEntrySet[i].region = region + group.SecurityGroupEntrySet[i].SecurityGroupId = groupId + return &group.SecurityGroupEntrySet[i], nil + } + } + time.Sleep(time.Second * 3) } return nil, errors.Wrapf(cloudprovider.ErrNotFound, "after create %s", jsonutils.Marshal(opts)) } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go index 7f57ab13b0..a2c30fa7f8 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go @@ -14,6 +14,15 @@ package ksyun +import ( + "fmt" + "strings" + + "yunion.io/x/pkg/errors" + "yunion.io/x/pkg/gotypes" + "yunion.io/x/pkg/utils" +) + type STag struct { ResourceType string ResourceId string @@ -31,7 +40,7 @@ func (vv TagSet) GetTags() map[string]string { return ret } -func (self *SRegion) ListTags(resType string, resId string) (*TagSet, error) { +func (region *SRegion) ListTags(resType string, resId string) (*TagSet, error) { params := map[string]interface{}{ "MaxResults": "1000", "Filter.1.Name": "resource-type", @@ -39,7 +48,7 @@ func (self *SRegion) ListTags(resType string, resId string) (*TagSet, error) { "Filter.2.Name": "resource-id", "Filter.2.Value.1": resId, } - resp, err := self.tagRequest("DescribeTags", params) + resp, err := region.tagRequest("DescribeTags", params) if err != nil { return nil, err } @@ -50,3 +59,84 @@ func (self *SRegion) ListTags(resType string, resId string) (*TagSet, error) { } return ret, nil } + +func (region *SRegion) DeleteTags(resType, resId string, tags map[string]string) error { + params := map[string]interface{}{ + "Resource.1.Type": resType, + "Resource.1.Id": resId, + } + idx := 1 + for k, v := range tags { + params[fmt.Sprintf("Tag.%d.Key", idx)] = k + params[fmt.Sprintf("Tag.%d.Value", idx)] = v + idx++ + } + _, err := region.tagRequest("DeleteTags", params) + if err != nil { + return err + } + return nil +} + +func (region *SRegion) CreateTags(resType, resId string, tags map[string]string) error { + params := map[string]interface{}{ + "Resource.1.Type": resType, + "Resource.1.Id": resId, + } + idx := 1 + for k, v := range tags { + params[fmt.Sprintf("Tag.%d.Key", idx)] = k + params[fmt.Sprintf("Tag.%d.Value", idx)] = v + idx++ + } + _, err := region.tagRequest("CreateTags", params) + if err != nil { + return err + } + return nil +} + +func (region *SRegion) SetResourceTags(resType string, resId string, tags map[string]string, replace bool) error { + _tags, err := region.ListTags(resType, resId) + if err != nil { + return errors.Wrapf(err, "ListTags") + } + if gotypes.IsNil(_tags) { + _tags = &TagSet{} + } + keys, upperKeys := []string{}, []string{} + for k := range tags { + keys = append(keys, k) + upperKeys = append(upperKeys, strings.ToUpper(k)) + } + if replace { + if len(tags) > 0 { + removeKeys := map[string]string{} + for _, k := range *_tags { + if !utils.IsInStringArray(k.Key, keys) { + removeKeys[k.Key] = k.Value + } + } + if len(removeKeys) > 0 { + err := region.DeleteTags(resType, resId, removeKeys) + if err != nil { + return errors.Wrapf(err, "DeleteTags") + } + } + } + } else { + removeKeys := map[string]string{} + for _, k := range *_tags { + if !utils.IsInStringArray(k.Key, keys) && utils.IsInStringArray(strings.ToUpper(k.Key), upperKeys) { + removeKeys[k.Key] = k.Value + } + } + if len(removeKeys) > 0 { + err := region.DeleteTags(resType, resId, removeKeys) + if err != nil { + return errors.Wrapf(err, "DeleteTags") + } + } + } + return region.CreateTags(resType, resId, tags) +}