fix(region): support ksyun tag sync (#19956)

This commit is contained in:
屈轩
2024-04-12 12:05:26 +08:00
committed by GitHub
parent 396aa79087
commit ee44f7ea92
17 changed files with 330 additions and 94 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+1 -1
View File
@@ -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
+68 -64
View File
@@ -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),
+7 -6
View File
@@ -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 {
+1 -1
View File
@@ -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
}
}
+8
View File
@@ -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
}
+8
View File
@@ -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":
+28 -1
View File
@@ -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
}
+25 -13
View File
@@ -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
+8
View File
@@ -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
}
+96
View File
@@ -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
}
+1 -1
View File
@@ -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) {
+8 -4
View File
@@ -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)
}
+8
View File
@@ -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 {
+52
View File
@@ -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
}
+8
View File
@@ -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 {