huawei secgroup default vpc id fix

This commit is contained in:
TangBin
2020-02-27 17:49:21 +08:00
parent d4417f8027
commit 439d2a316e
5 changed files with 33 additions and 13 deletions
+1
View File
@@ -38,6 +38,7 @@ func InitDB() error {
WireManager,
StorageManager,
SecurityGroupManager,
SecurityGroupCacheManager,
NetworkManager,
LoadbalancerCertificateManager,
LoadbalancerAclManager,
+24
View File
@@ -350,3 +350,27 @@ func (self *SSecurityGroupCache) StartSecurityGroupCacheDeleteTask(ctx context.C
task.ScheduleRun(nil)
return nil
}
func (manager *SSecurityGroupCacheManager) InitializeData() error {
providerIds := CloudproviderManager.Query("id").In("provider", []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_CTYUN}).SubQuery()
deprecatedSecgroups := []SSecurityGroupCache{}
q := manager.Query().In("manager_id", providerIds).NotEquals("vpc_id", api.NORMAL_VPC_ID)
err := db.FetchModelObjects(manager, q, &deprecatedSecgroups)
if err != nil && err != sql.ErrNoRows {
return errors.Wrap(err, "SSecurityGroupCacheManager.InitializeData.Query")
}
for i := range deprecatedSecgroups {
cache := &deprecatedSecgroups[i]
_, err := db.Update(cache, func() error {
return cache.MarkDelete()
})
if err != nil {
return errors.Wrap(err, "SSecurityGroupCacheManager.InitializeData.Query")
}
}
log.Debugf("SSecurityGroupCacheManager cleaned %d deprecated security group cache.", len(deprecatedSecgroups))
return nil
}
+4 -6
View File
@@ -24,6 +24,8 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/secrules"
apis "yunion.io/x/onecloud/pkg/apis/compute"
)
type SSecurityGroup struct {
@@ -352,11 +354,7 @@ func (self *SSecurityGroup) GetSecurityRule(remoteRule SSecurityGroupRule, withR
}
func (self *SSecurityGroup) GetVpcId() string {
if len(self.VpcID) == 0 {
return "classic"
}
return self.VpcID
return apis.NORMAL_VPC_ID
}
func (self *SRegion) GetSecurityGroupDetails(groupId string) (*SSecurityGroup, error) {
@@ -413,7 +411,7 @@ func (self *SRegion) CreateSecurityGroup(vpcId, name string) (*SSecurityGroup, e
"name": jsonutils.NewString(name),
}
if len(vpcId) > 0 && (vpcId != "classic" && vpcId != "normal") {
if len(vpcId) > 0 && vpcId != apis.NORMAL_VPC_ID {
params["vpcId"] = jsonutils.NewString(vpcId)
}
+1 -1
View File
@@ -724,7 +724,7 @@ func (self *SRegion) CreateSecurityGroup(vpcId string, name string, desc string)
params := jsonutils.NewDict()
secgroupObj := jsonutils.NewDict()
secgroupObj.Add(jsonutils.NewString(name), "name")
if len(vpcId) > 0 && (vpcId != "classic" && vpcId != "normal") {
if len(vpcId) > 0 && vpcId != api.NORMAL_VPC_ID {
secgroupObj.Add(jsonutils.NewString(vpcId), "vpc_id")
}
params.Add(secgroupObj, "security_group")
+3 -6
View File
@@ -31,6 +31,8 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/util/secrules"
api "yunion.io/x/onecloud/pkg/apis/compute"
)
type SecurityGroupRule struct {
@@ -128,12 +130,7 @@ func (self *SSecurityGroup) GetId() string {
}
func (self *SSecurityGroup) GetVpcId() string {
// 无vpc关联的安全组统一返回classic
if len(self.VpcID) == 0 {
return "classic"
}
return self.VpcID
return api.NORMAL_VPC_ID
}
func (self *SSecurityGroup) GetName() string {