From ef70a95da9ee2705304689103b895399407bf4d3 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Mon, 24 May 2021 11:52:05 +0800 Subject: [PATCH] fix(region): azure uniform tags --- pkg/multicloud/azure/azure.go | 6 ++++++ pkg/multicloud/azure/classic_secruitygroup.go | 6 +----- pkg/multicloud/azure/dbinstance.go | 2 +- pkg/multicloud/azure/disk.go | 2 +- pkg/multicloud/azure/eip.go | 1 + pkg/multicloud/azure/instance.go | 2 +- pkg/multicloud/azure/region.go | 16 +++++++++++----- pkg/multicloud/azure/securitygroup.go | 6 +----- pkg/multicloud/azure/storageaccount.go | 8 ++++++-- pkg/multicloud/azure/vpc.go | 2 +- 10 files changed, 30 insertions(+), 21 deletions(-) diff --git a/pkg/multicloud/azure/azure.go b/pkg/multicloud/azure/azure.go index dcbd3af6fc..8b3c464f19 100644 --- a/pkg/multicloud/azure/azure.go +++ b/pkg/multicloud/azure/azure.go @@ -48,6 +48,12 @@ const ( type TAzureResource string +type TAzureTags map[string]string + +func (self TAzureTags) GetTags() (map[string]string, error) { + return self, nil +} + var ( GraphResource = TAzureResource("graph") DefaultResource = TAzureResource("default") diff --git a/pkg/multicloud/azure/classic_secruitygroup.go b/pkg/multicloud/azure/classic_secruitygroup.go index b3a2e03e76..a596452dc7 100644 --- a/pkg/multicloud/azure/classic_secruitygroup.go +++ b/pkg/multicloud/azure/classic_secruitygroup.go @@ -40,7 +40,7 @@ type SClassicSecurityGroup struct { Name string Location string Type string - Tags map[string]string + Tags TAzureTags } type ClassicSecurityGroupProperties struct { @@ -120,10 +120,6 @@ func (self *SClassicSecurityGroup) GetVpcId() string { return "classic" } -func (self *SClassicSecurityGroup) GetTags() (map[string]string, error) { - return self.Tags, nil -} - func (self *SClassicSecurityGroup) GetId() string { return self.ID } diff --git a/pkg/multicloud/azure/dbinstance.go b/pkg/multicloud/azure/dbinstance.go index dda365e4e7..66e6528801 100644 --- a/pkg/multicloud/azure/dbinstance.go +++ b/pkg/multicloud/azure/dbinstance.go @@ -83,7 +83,7 @@ type SDBInstance struct { ID string `json:"id"` Name string `json:"name"` Type string `json:"type"` - Tags map[string]string `json:"tags"` + Tags TAzureTags `json:"tags"` } func (self *SRegion) GetIDBInstances() ([]cloudprovider.ICloudDBInstance, error) { diff --git a/pkg/multicloud/azure/disk.go b/pkg/multicloud/azure/disk.go index 66166b0ec5..26fa9a23a8 100644 --- a/pkg/multicloud/azure/disk.go +++ b/pkg/multicloud/azure/disk.go @@ -80,7 +80,7 @@ type SDisk struct { Location string `json:"location,omitempty"` Properties DiskProperties `json:"properties,omitempty"` - Tags map[string]string `json:"tags,omitempty"` + Tags TAzureTags `json:"tags,omitempty"` } func (self *SRegion) CreateDisk(storageType string, name string, sizeGb int32, imageId, snapshotId, resourceGroup string) (*SDisk, error) { diff --git a/pkg/multicloud/azure/eip.go b/pkg/multicloud/azure/eip.go index 0700e87c51..85965b866f 100644 --- a/pkg/multicloud/azure/eip.go +++ b/pkg/multicloud/azure/eip.go @@ -60,6 +60,7 @@ type SEipAddress struct { Location string Properties PublicIPAddressPropertiesFormat `json:"properties,omitempty"` Type string + Tags TAzureTags Sku *PublicIPAddressSku } diff --git a/pkg/multicloud/azure/instance.go b/pkg/multicloud/azure/instance.go index 6e4b89a8b6..ac72db617c 100644 --- a/pkg/multicloud/azure/instance.go +++ b/pkg/multicloud/azure/instance.go @@ -184,7 +184,7 @@ type SInstance struct { Type string Location string vmSize *SVMSize - Tags map[string]string + Tags TAzureTags Resources []SExtensionResource } diff --git a/pkg/multicloud/azure/region.go b/pkg/multicloud/azure/region.go index 11ecef25d2..35777aab7f 100644 --- a/pkg/multicloud/azure/region.go +++ b/pkg/multicloud/azure/region.go @@ -381,20 +381,26 @@ func (region *SRegion) GetEips() ([]SEipAddress, error) { func (region *SRegion) GetIEips() ([]cloudprovider.ICloudEIP, error) { eips, err := region.GetEips() if err != nil { - return nil, err + return nil, errors.Wrapf(err, "GetEips") } classicEips, err := region.GetClassicEips() if err != nil { - return nil, err + return nil, errors.Wrapf(err, "GetClassicEips") } - ieips := make([]cloudprovider.ICloudEIP, len(eips)+len(classicEips)) + ieips := []cloudprovider.ICloudEIP{} for i := 0; i < len(eips); i++ { + if len(eips[i].GetIpAddr()) == 0 { + continue + } eips[i].region = region - ieips[i] = &eips[i] + ieips = append(ieips, &eips[i]) } for i := 0; i < len(classicEips); i++ { + if len(classicEips[i].GetIpAddr()) == 0 { + continue + } classicEips[i].region = region - ieips[len(eips)+i] = &classicEips[i] + ieips = append(ieips, &classicEips[i]) } return ieips, nil } diff --git a/pkg/multicloud/azure/securitygroup.go b/pkg/multicloud/azure/securitygroup.go index 15c2ebb2d6..b0d3d311f8 100644 --- a/pkg/multicloud/azure/securitygroup.go +++ b/pkg/multicloud/azure/securitygroup.go @@ -75,11 +75,7 @@ type SSecurityGroup struct { Name string Location string Type string - Tags map[string]string -} - -func (self *SSecurityGroup) GetTags() (map[string]string, error) { - return self.Tags, nil + Tags TAzureTags } func parseCIDR(cidr string) (*net.IPNet, error) { diff --git a/pkg/multicloud/azure/storageaccount.go b/pkg/multicloud/azure/storageaccount.go index c2464079fd..0f77b357b4 100644 --- a/pkg/multicloud/azure/storageaccount.go +++ b/pkg/multicloud/azure/storageaccount.go @@ -94,7 +94,7 @@ type SStorageAccount struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Type string `json:"type,omitempty"` - Tags map[string]string + Tags TAzureTags Properties AccountProperties `json:"properties"` } @@ -715,8 +715,12 @@ func (b *SStorageAccount) MaxPartCount() int { return 50000 } +func (b *SStorageAccount) GetTags() (map[string]string, error) { + return b.Tags, nil +} + func (b *SStorageAccount) GetProjectId() string { - return "" + return getResourceGroup(b.ID) } func (b *SStorageAccount) GetGlobalId() string { diff --git a/pkg/multicloud/azure/vpc.go b/pkg/multicloud/azure/vpc.go index 1c8071e1e8..0c59cea8d5 100644 --- a/pkg/multicloud/azure/vpc.go +++ b/pkg/multicloud/azure/vpc.go @@ -51,7 +51,7 @@ type SVpc struct { Etag string Type string Location string - Tags map[string]string + Tags TAzureTags Properties VirtualNetworkPropertiesFormat `json:"properties,omitempty"` }