mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
huawei secgroup default vpc id fix
This commit is contained in:
@@ -38,6 +38,7 @@ func InitDB() error {
|
||||
WireManager,
|
||||
StorageManager,
|
||||
SecurityGroupManager,
|
||||
SecurityGroupCacheManager,
|
||||
NetworkManager,
|
||||
LoadbalancerCertificateManager,
|
||||
LoadbalancerAclManager,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user