From ee44f7ea92a16da21e8c8bdeabd10232ec5bb932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Fri, 12 Apr 2024 12:05:26 +0800 Subject: [PATCH] fix(region): support ksyun tag sync (#19956) --- go.mod | 2 +- go.sum | 4 +- vendor/modules.txt | 2 +- .../x/cloudmux/pkg/multicloud/esxi/guestos.go | 132 +++++++++--------- .../cloudmux/pkg/multicloud/esxi/template.go | 13 +- .../pkg/multicloud/esxi/virtualmachine.go | 2 +- .../x/cloudmux/pkg/multicloud/ksyun/disks.go | 8 ++ .../x/cloudmux/pkg/multicloud/ksyun/eip.go | 8 ++ .../pkg/multicloud/ksyun/instances.go | 29 +++- .../x/cloudmux/pkg/multicloud/ksyun/ksyun.go | 38 +++-- .../cloudmux/pkg/multicloud/ksyun/network.go | 8 ++ .../cloudmux/pkg/multicloud/ksyun/project.go | 96 +++++++++++++ .../pkg/multicloud/ksyun/provider/provider.go | 2 +- .../x/cloudmux/pkg/multicloud/ksyun/region.go | 12 +- .../pkg/multicloud/ksyun/securitygroup.go | 8 ++ .../x/cloudmux/pkg/multicloud/ksyun/tag.go | 52 +++++++ .../x/cloudmux/pkg/multicloud/ksyun/vpc.go | 8 ++ 17 files changed, 330 insertions(+), 94 deletions(-) create mode 100644 vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/project.go create mode 100644 vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go diff --git a/go.mod b/go.mod index 3bebca2cd2..4c756a5621 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.20240411035554-973f38d58429 + yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240412034729-5250d15c00b1 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 775c0a6f58..b723d45c09 100644 --- a/go.sum +++ b/go.sum @@ -1210,8 +1210,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.20240411035554-973f38d58429 h1:Dr04yssuhKLqb5cPLPv6Kp6gLZLfIuEle+L6mQ8mXB8= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240411035554-973f38d58429/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240412034729-5250d15c00b1 h1:1N069/5RxK6zElHbDvE4JgE7rbJQsOeueg8A+UrUA80= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240412034729-5250d15c00b1/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/vendor/modules.txt b/vendor/modules.txt index 785d9baf73..b511c3567c 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.20240411035554-973f38d58429 +# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240412034729-5250d15c00b1 ## 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/esxi/guestos.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/guestos.go index d5b9333337..84e31e97d2 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/guestos.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/guestos.go @@ -124,71 +124,75 @@ func vmware(ver string) SOsInfo { } var ( + // https://vdc-repo.vmware.com/vmwb-repository/dcr-public/da47f910-60ac-438b-8b9b-6122f4d14524/16b7274a-bf8b-4b4c-a05e-746f2aa93c8c/doc/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html GuestOsInfo = map[string]SOsInfo{ - "asianux3_64Guest": asian("3", X86_64), - "asianux3Guest": asian("3", X86), - "asianux4_64Guest": asian("4", X86_64), - "asianux4Guest": asian("4", X86), - "asianux5_64Guest": asian("5", X86_64), - "asianux7_64Guest": asian("7", X86_64), - "centos6_64Guest": centos("6", X86_64), - "centos64Guest": centos4_5(X86_64), - "centos6Guest": centos("6", X86), - "centos7_64Guest": centos("7", X86_64), - "centos7Guest": centos("7", X86), - "centosGuest": centos4_5(X86), - "coreos64Guest": coreos("", X86_64), - "darwin10_64Guest": macos("10.6", X86_64), - "darwin10Guest": macos("10.6", X86), - "darwin11_64Guest": macos("10.7", X86_64), - "darwin11Guest": macos("10.7", X86), - "darwin12_64Guest": macos("10.8", X86_64), - "darwin13_64Guest": macos("10.9", X86_64), - "darwin14_64Guest": macos("10.10", X86_64), - "darwin15_64Guest": macos("10.11", X86_64), - "darwin16_64Guest": macos("10.12", X86_64), - "darwin64Guest": macos("10.5", X86_64), - "darwinGuest": macos("10.5", X86), - "debian10_64Guest": debian("10", X86_64), - "debian10Guest": debian("10", X86), - "debian4_64Guest": debian("4", X86_64), - "debian4Guest": debian("4", X86), - "debian5_64Guest": debian("5", X86_64), - "debian5Guest": debian("5", X86), - "debian6_64Guest": debian("6", X86_64), - "debian6Guest": debian("6", X86), - "debian7_64Guest": debian("7", X86_64), - "debian7Guest": debian("7", X86), - "debian8_64Guest": debian("8", X86_64), - "debian8Guest": debian("8", X86), - "debian9_64Guest": debian("9", X86_64), - "debian9Guest": debian("9", X86), - "eComStation2Guest": eComStationGuest("2.0", X86), - "eComStationGuest": eComStationGuest("1.x", X86), - "fedora64Guest": fedora("?", X86_64), - "fedoraGuest": fedora("?", X86), - "freebsd64Guest": freebsd(X86_64), - "freebsdGuest": freebsd(X86), - "genericLinuxGuest": linux("?", X86), - "mandrakeGuest": mandrake(X86), - "mandriva64Guest": mandriva(X86_64), - "mandrivaGuest": mandriva(X86), - "opensuse64Guest": opensuse(X86_64), - "opensuseGuest": opensuse(X86), - "oracleLinux6_64Guest": oracle("6", X86_64), - "oracleLinux64Guest": oracle("4/5", X86_64), - "oracleLinux6Guest": oracle("6", X86), - "oracleLinux7_64Guest": oracle("7", X86_64), - "oracleLinux7Guest": oracle("7", X86), - "oracleLinuxGuest": oracle("4/5", X86), - "other24xLinux64Guest": linux("2.4", X86_64), - "other24xLinuxGuest": linux("2.4", X86), - "other26xLinux64Guest": linux("2.6", X86_64), - "other26xLinuxGuest": linux("2.6", X86), - "other3xLinux64Guest": linux("3.x", X86_64), - "other3xLinuxGuest": linux("3.x", X86_64), - "otherLinux64Guest": linux("2.2", X86_64), - "otherLinuxGuest": linux("2.2", X86), + "asianux3_64Guest": asian("3", X86_64), + "asianux3Guest": asian("3", X86), + "asianux4_64Guest": asian("4", X86_64), + "asianux4Guest": asian("4", X86), + "asianux5_64Guest": asian("5", X86_64), + "asianux7_64Guest": asian("7", X86_64), + "centos6_64Guest": centos("6", X86_64), + "centos64Guest": centos4_5(X86_64), + "centos6Guest": centos("6", X86), + "centos7_64Guest": centos("7", X86_64), + "centos7Guest": centos("7", X86), + "centos8_64Guest": centos("8", X86), + "centosGuest": centos4_5(X86), + "coreos64Guest": coreos("", X86_64), + "darwin10_64Guest": macos("10.6", X86_64), + "darwin10Guest": macos("10.6", X86), + "darwin11_64Guest": macos("10.7", X86_64), + "darwin11Guest": macos("10.7", X86), + "darwin12_64Guest": macos("10.8", X86_64), + "darwin13_64Guest": macos("10.9", X86_64), + "darwin14_64Guest": macos("10.10", X86_64), + "darwin15_64Guest": macos("10.11", X86_64), + "darwin16_64Guest": macos("10.12", X86_64), + "darwin17_64Guest": macos("10.13", X86_64), + "darwin18_64Guest": macos("10.14", X86_64), + "darwin64Guest": macos("10.5", X86_64), + "darwinGuest": macos("10.5", X86), + "debian10_64Guest": debian("10", X86_64), + "debian10Guest": debian("10", X86), + "debian4_64Guest": debian("4", X86_64), + "debian4Guest": debian("4", X86), + "debian5_64Guest": debian("5", X86_64), + "debian5Guest": debian("5", X86), + "debian6_64Guest": debian("6", X86_64), + "debian6Guest": debian("6", X86), + "debian7_64Guest": debian("7", X86_64), + "debian7Guest": debian("7", X86), + "debian8_64Guest": debian("8", X86_64), + "debian8Guest": debian("8", X86), + "debian9_64Guest": debian("9", X86_64), + "debian9Guest": debian("9", X86), + "eComStation2Guest": eComStationGuest("2.0", X86), + "eComStationGuest": eComStationGuest("1.x", X86), + "fedora64Guest": fedora("?", X86_64), + "fedoraGuest": fedora("?", X86), + "freebsd64Guest": freebsd(X86_64), + "freebsdGuest": freebsd(X86), + //"genericLinuxGuest": linux("?", X86), + "mandrakeGuest": mandrake(X86), + "mandriva64Guest": mandriva(X86_64), + "mandrivaGuest": mandriva(X86), + "opensuse64Guest": opensuse(X86_64), + "opensuseGuest": opensuse(X86), + "oracleLinux6_64Guest": oracle("6", X86_64), + "oracleLinux64Guest": oracle("4/5", X86_64), + "oracleLinux6Guest": oracle("6", X86), + "oracleLinux7_64Guest": oracle("7", X86_64), + "oracleLinux7Guest": oracle("7", X86), + "oracleLinuxGuest": oracle("4/5", X86), + //"other24xLinux64Guest": linux("2.4", X86_64), + //"other24xLinuxGuest": linux("2.4", X86), + //"other26xLinux64Guest": linux("2.6", X86_64), + //"other26xLinuxGuest": linux("2.6", X86), + //"other3xLinux64Guest": linux("3.x", X86_64), + //"other3xLinuxGuest": linux("3.x", X86_64), + //"otherLinux64Guest": linux("2.2", X86_64), + //"otherLinuxGuest": linux("2.2", X86), "redhatGuest": rhel("2.1", X86), "rhel2Guest": rhel("2", X86), "rhel3_64Guest": rhel("3", X86_64), diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/template.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/template.go index a46d808a28..1c5ab92f5b 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/template.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/template.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/errors" + "yunion.io/x/pkg/util/imagetools" api "yunion.io/x/cloudmux/pkg/apis/compute" "yunion.io/x/cloudmux/pkg/cloudprovider" @@ -148,27 +149,27 @@ func (t *SVMTemplate) GetBios() cloudprovider.TBiosType { } func (t *SVMTemplate) GetOsType() cloudprovider.TOsType { - return t.vm.GetOsType() + return cloudprovider.TOsType(imagetools.NormalizeImageInfo(t.GetName(), "", "", "", "").OsType) } func (t *SVMTemplate) GetOsDist() string { - return t.vm.GetOsDist() + return imagetools.NormalizeImageInfo(t.GetName(), "", "", "", "").OsDistro } func (t *SVMTemplate) GetOsVersion() string { - return t.vm.GetOsVersion() + return imagetools.NormalizeImageInfo(t.GetName(), "", "", "", "").OsVersion } func (t *SVMTemplate) GetOsLang() string { - return t.vm.GetOsLang() + return imagetools.NormalizeImageInfo(t.GetName(), "", "", "", "").OsLang } func (t *SVMTemplate) GetOsArch() string { - return t.vm.GetOsArch() + return imagetools.NormalizeImageInfo(t.GetName(), "", "", "", "").OsArch } func (t *SVMTemplate) GetFullOsName() string { - return t.vm.GetFullOsName() + return imagetools.NormalizeImageInfo(t.GetName(), "", "", "", "").OsFullVersion } func (t *SVMTemplate) GetMinOsDiskSizeGb() int { 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 4205353ab3..7dc4ec2148 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/esxi/virtualmachine.go @@ -470,7 +470,7 @@ func (vm *SVirtualMachine) getNormalizedOsInfo() *imagetools.ImageInfo { osInfo := imagetools.NormalizeImageInfo("", string(osInfo.OsArch), string(osInfo.OsType), osInfo.OsDistribution, osInfo.OsVersion) vm.osInfo = &osInfo } else { - osInfo := imagetools.NormalizeImageInfo("", "", "", "", "") + osInfo := imagetools.NormalizeImageInfo(vm.GetName(), "", "", "", "") vm.osInfo = &osInfo } } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/disks.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/disks.go index 4ea3f1f3f5..1a742b76e4 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/disks.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/disks.go @@ -141,6 +141,14 @@ func (disk *SDisk) GetId() string { return disk.VolumeID } +func (disk *SDisk) GetTags() (map[string]string, error) { + tags, err := disk.storage.zone.region.ListTags("volume", disk.VolumeID) + if err != nil { + return nil, err + } + return tags.GetTags(), nil +} + func (disk *SDisk) GetGlobalId() string { return disk.VolumeID } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/eip.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/eip.go index 2d8b2c921e..e8b7e4fefa 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/eip.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/eip.go @@ -111,6 +111,14 @@ func (eip *SEip) GetGlobalId() string { return eip.AllocationID } +func (eip *SEip) GetTags() (map[string]string, error) { + tags, err := eip.region.ListTags("eip", eip.AllocationID) + if err != nil { + return nil, err + } + return tags.GetTags(), nil +} + func (eip *SEip) GetStatus() string { switch eip.State { case "associate": 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 4d46a40e84..efda6d2689 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/instances.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/instances.go @@ -129,6 +129,22 @@ type SInstance struct { } func (region *SRegion) GetInstances(zoneName string, instanceIds []string) ([]SInstance, error) { + projectIds, err := region.client.GetSplitProjectIds() + if err != nil { + return nil, err + } + ret := []SInstance{} + for _, projects := range projectIds { + part, err := region.getInstances(zoneName, instanceIds, projects) + if err != nil { + return nil, err + } + ret = append(ret, part...) + } + return ret, nil +} + +func (region *SRegion) getInstances(zoneName string, instanceIds []string, projectIds []string) ([]SInstance, error) { instances := []SInstance{} params := map[string]string{ "MaxResults": "1000", @@ -139,7 +155,10 @@ func (region *SRegion) GetInstances(zoneName string, instanceIds []string) ([]SI params["Filter.1.Value.1"] = zoneName } for i, v := range instanceIds { - params[fmt.Sprintf("%d", i+1)] = v + params[fmt.Sprintf("InstanceId.%d", i+1)] = v + } + for i, v := range projectIds { + params[fmt.Sprintf("ProjectId.%d", i+1)] = v } for { resp, err := region.ecsRequest("DescribeInstances", params) @@ -182,6 +201,14 @@ func (ins *SInstance) Refresh() error { return jsonutils.Update(ins, extIns) } +func (ins *SInstance) GetTags() (map[string]string, error) { + tags, err := ins.host.zone.region.ListTags("kec-instance", ins.InstanceID) + if err != nil { + return nil, err + } + return tags.GetTags(), nil +} + func (ins *SInstance) AssignSecurityGroup(secgroupId string) error { return cloudprovider.ErrNotImplemented } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/ksyun.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/ksyun.go index 8d51aa36de..17d8230236 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/ksyun.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/ksyun.go @@ -39,8 +39,9 @@ import ( ) const ( - CLOUD_PROVIDER_KSYUN_CN = "金山云" - KSYUN_DEFAULT_REGION = "cn-beijing-6" + CLOUD_PROVIDER_KSYUN_CN = "金山云" + KSYUN_DEFAULT_REGION = "cn-beijing-6" + KSYUN_DEFAULT_API_VERSION = "2016-03-04" ) type KsyunClientConfig struct { @@ -125,16 +126,10 @@ func (cli *SKsyunClient) getUrl(service, regionId string) (string, error) { regionId = KSYUN_DEFAULT_REGION } switch service { - case "kingpay", "iam": + case "kingpay", "iam", "vpc", "ebs", "eip": return fmt.Sprintf("http://%s.api.ksyun.com", service), nil - case "kec": - return fmt.Sprintf("https://kec.%s.api.ksyun.com", regionId), nil - case "vpc": - return "http://vpc.api.ksyun.com", nil - case "ebs": - return "http://ebs.api.ksyun.com", nil - case "eip": - return "http://eip.api.ksyun.com", nil + case "kec", "tag": + return fmt.Sprintf("https://%s.%s.api.ksyun.com", service, regionId), nil } return "", errors.Wrapf(cloudprovider.ErrNotSupported, "service %s", service) } @@ -237,13 +232,29 @@ func (cli *SKsyunClient) Do(req *http.Request) (*http.Response, error) { } func (cli *SKsyunClient) ec2Request(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) { - return cli.request("kec", regionId, apiName, "2016-03-04", params) + return cli.request("kec", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params) } func (cli *SKsyunClient) iamRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) { return cli.request("iam", regionId, apiName, "2015-11-01", params) } +func (cli *SKsyunClient) tagRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) { + return cli.request("tag", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params) +} + +func (cli *SKsyunClient) eipRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) { + return cli.request("eip", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params) +} + +func (cli *SKsyunClient) ebsRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) { + return cli.request("ebs", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params) +} + +func (cli *SKsyunClient) vpcRequest(regionId, apiName string, params map[string]string) (jsonutils.JSONObject, error) { + return cli.request("vpc", regionId, apiName, KSYUN_DEFAULT_API_VERSION, params) +} + func (cli *SKsyunClient) request(service, regionId, apiName, apiVersion string, params map[string]string) (jsonutils.JSONObject, error) { uri, err := cli.getUrl(service, regionId) if err != nil { @@ -269,7 +280,7 @@ func (cli *SKsyunClient) request(service, regionId, apiName, apiVersion string, } uri = fmt.Sprintf("%s?%s", uri, values.Encode()) method := httputils.GET - if !strings.HasPrefix(apiName, "Describe") { + if !strings.HasPrefix(apiName, "Describe") && !strings.HasPrefix(apiName, "Get") { method = httputils.POST } req := httputils.NewJsonRequest(method, uri, nil) @@ -331,6 +342,7 @@ func (cli *SKsyunClient) QueryCashWalletAction() (*CashWalletDetail, error) { func (cli *SKsyunClient) GetCapabilities() []string { caps := []string{ cloudprovider.CLOUD_CAPABILITY_COMPUTE + cloudprovider.READ_ONLY_SUFFIX, + cloudprovider.CLOUD_CAPABILITY_PROJECT + cloudprovider.READ_ONLY_SUFFIX, cloudprovider.CLOUD_CAPABILITY_CLOUDID, } return caps diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/network.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/network.go index 96ec7fa19e..23ce126957 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/network.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/network.go @@ -139,6 +139,14 @@ func (net *SNetwork) Refresh() error { return jsonutils.Update(net, extNet) } +func (net *SNetwork) GetTags() (map[string]string, error) { + tags, err := net.wire.zone.region.ListTags("subnet", net.SubnetID) + if err != nil { + return nil, err + } + return tags.GetTags(), nil +} + func (net *SNetwork) GetIWire() cloudprovider.ICloudWire { return net.wire } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/project.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/project.go new file mode 100644 index 0000000000..df8283342f --- /dev/null +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/project.go @@ -0,0 +1,96 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ksyun + +import ( + api "yunion.io/x/cloudmux/pkg/apis/compute" + "yunion.io/x/cloudmux/pkg/cloudprovider" + "yunion.io/x/cloudmux/pkg/multicloud" +) + +type SProject struct { + multicloud.SProjectBase + client *SKsyunClient + + ProjectId string + AccountId string + ProjectName string + ProjectDesc string + Status string + Krn string +} + +func (self *SProject) GetGlobalId() string { + return self.ProjectId +} + +func (self *SProject) GetId() string { + return self.ProjectId +} + +func (self *SProject) GetName() string { + return self.ProjectName +} + +func (self *SProject) GetStatus() string { + return api.EXTERNAL_PROJECT_STATUS_AVAILABLE +} + +func (self *SKsyunClient) GetProjects() ([]SProject, error) { + resp, err := self.iamRequest("", "GetAccountAllProjectList", nil) + if err != nil { + return nil, err + } + ret := []SProject{} + err = resp.Unmarshal(&ret, "ProjectList") + if err != nil { + return nil, err + } + return ret, nil +} + +func (self *SKsyunClient) GetSplitProjectIds() ([][]string, error) { + projects, err := self.GetProjects() + if err != nil { + return nil, err + } + length := 100 + var result [][]string + for i := 0; i < len(projects); i += length { + end := i + length + if end > len(projects) { + end = len(projects) + } + part := []string{} + for j := i; j < end; j++ { + part = append(part, projects[j].ProjectId) + } + result = append(result, part) + } + return result, nil +} + +func (self *SKsyunClient) GetIProjects() ([]cloudprovider.ICloudProject, error) { + projects, err := self.GetProjects() + if err != nil { + return nil, err + } + ret := []cloudprovider.ICloudProject{} + for i := range projects { + projects[i].client = self + ret = append(ret, &projects[i]) + } + return ret, nil +} diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/provider/provider.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/provider/provider.go index d9cec60bbf..97062860e8 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/provider/provider.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/provider/provider.go @@ -163,7 +163,7 @@ func (self *SKsyunProvider) GetBalance() (*cloudprovider.SBalanceInfo, error) { } func (self *SKsyunProvider) GetIProjects() ([]cloudprovider.ICloudProject, error) { - return []cloudprovider.ICloudProject{}, nil + return self.client.GetIProjects() } func (self *SKsyunProvider) CreateIProject(name string) (cloudprovider.ICloudProject, error) { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/region.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/region.go index 46f300076f..b36a7b9499 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/region.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/region.go @@ -239,17 +239,21 @@ func (region *SRegion) GetIStorages() ([]cloudprovider.ICloudStorage, error) { } func (region *SRegion) ecsRequest(action string, params map[string]string) (jsonutils.JSONObject, error) { - return region.client.request("kec", region.Region, action, "2016-03-04", params) + return region.client.ec2Request(region.Region, action, params) +} + +func (region *SRegion) tagRequest(action string, params map[string]string) (jsonutils.JSONObject, error) { + return region.client.tagRequest(region.Region, action, params) } func (region *SRegion) eipRequest(action string, params map[string]string) (jsonutils.JSONObject, error) { - return region.client.request("eip", region.Region, action, "2016-03-04", params) + return region.client.eipRequest(region.Region, action, params) } func (region *SRegion) ebsRequest(action string, params map[string]string) (jsonutils.JSONObject, error) { - return region.client.request("ebs", region.Region, action, "2016-03-04", params) + return region.client.ebsRequest(region.Region, action, params) } func (region *SRegion) vpcRequest(action string, params map[string]string) (jsonutils.JSONObject, error) { - return region.client.request("vpc", region.Region, action, "2016-03-04", params) + return region.client.vpcRequest(region.Region, action, params) } diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/securitygroup.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/securitygroup.go index cb61614e3d..8e0639770b 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/securitygroup.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/securitygroup.go @@ -104,6 +104,14 @@ func (secgroup *SSecurityGroup) Refresh() error { return jsonutils.Update(secgroup, group) } +func (secgroup *SSecurityGroup) GetTags() (map[string]string, error) { + tags, err := secgroup.region.ListTags("security-group", secgroup.SecurityGroupID) + if err != nil { + return nil, err + } + return tags.GetTags(), nil +} + func (secgroup *SSecurityGroup) GetReferences() ([]cloudprovider.SecurityGroupReference, error) { references, err := secgroup.region.DescribeSecurityGroupReferences(secgroup.SecurityGroupID) if err != nil { diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go new file mode 100644 index 0000000000..32ea95ee3b --- /dev/null +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/tag.go @@ -0,0 +1,52 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ksyun + +type STag struct { + ResourceType string + ResourceId string + Key string + Value string +} + +type TagSet []STag + +func (vv TagSet) GetTags() map[string]string { + ret := map[string]string{} + for _, v := range vv { + ret[v.Key] = v.Value + } + return ret +} + +func (self *SRegion) ListTags(resType string, resId string) (*TagSet, error) { + params := map[string]string{ + "MaxResults": "1000", + "Filter.1.Name": "resource-type", + "Filter.1.Value.1": resType, + "Filter.2.Name": "resource-id", + "Filter.2.Value.1": resId, + } + resp, err := self.tagRequest("DescribeTags", params) + if err != nil { + return nil, err + } + ret := &TagSet{} + err = resp.Unmarshal(&ret, "TagSet") + if err != nil { + return nil, err + } + return ret, nil +} diff --git a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/vpc.go b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/vpc.go index 3934e2f996..a9cd1e7f87 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/vpc.go +++ b/vendor/yunion.io/x/cloudmux/pkg/multicloud/ksyun/vpc.go @@ -163,6 +163,14 @@ func (vpc *SVpc) Delete() error { return cloudprovider.ErrNotImplemented } +func (vpc *SVpc) GetTags() (map[string]string, error) { + tags, err := vpc.region.ListTags("vpc", vpc.VpcID) + if err != nil { + return nil, err + } + return tags.GetTags(), nil +} + func (vpc *SVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) { wires, err := vpc.GetIWires() if err != nil {