mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Merge pull request #10097 from ioito/automated-cherry-pick-of-#10096-upstream-release-3.7
Automated cherry pick of #10096: fix(region): filter resource by classic vpc
This commit is contained in:
@@ -33,6 +33,8 @@ const (
|
||||
|
||||
DEFAULT_VPC_ID = "default"
|
||||
NORMAL_VPC_ID = "normal" // 没有关联VPC的安全组,统一使用normal
|
||||
|
||||
CLASSIC_VPC_NAME = "-"
|
||||
)
|
||||
|
||||
type UsableResourceListInput struct {
|
||||
|
||||
@@ -303,11 +303,11 @@ func (man *SLoadbalancerManager) ValidateCreateData(
|
||||
|
||||
var region *SCloudregion
|
||||
if len(input.VpcId) > 0 {
|
||||
var vpc *SVpc
|
||||
vpc, input.VpcResourceInput, err = ValidateVpcResourceInput(userCred, input.VpcResourceInput)
|
||||
_vpc, err := validators.ValidateModel(userCred, VpcManager, &input.VpcId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ValidateVpcResourceInput")
|
||||
return nil, err
|
||||
}
|
||||
vpc := _vpc.(*SVpc)
|
||||
region, _ = vpc.GetRegion()
|
||||
} else if len(input.ZoneId) > 0 {
|
||||
var zone *SZone
|
||||
|
||||
@@ -155,9 +155,9 @@ func (man *SRouteTableManager) ValidateCreateData(
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "validateRoutes")
|
||||
}
|
||||
_, input.VpcResourceInput, err = ValidateVpcResourceInput(userCred, input.VpcResourceInput)
|
||||
_, err = validators.ValidateModel(userCred, VpcManager, &input.VpcId)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "ValidateVpcResourceInput")
|
||||
return input, err
|
||||
}
|
||||
input.StatusInfrasResourceBaseCreateInput, err = man.SStatusInfrasResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.StatusInfrasResourceBaseCreateInput)
|
||||
if err != nil {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
@@ -136,7 +137,7 @@ func (sgm *SScalingGroupManager) ValidateCreateData(ctx context.Context, userCre
|
||||
input.CloudregionId = cloudregion.GetId()
|
||||
|
||||
// check vpc
|
||||
_, input.VpcResourceInput, err = ValidateVpcResourceInput(userCred, input.VpcResourceInput)
|
||||
_, err = validators.ValidateModel(userCred, VpcManager, &input.VpcId)
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -26,6 +25,7 @@ import (
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -46,19 +46,6 @@ type SVpcResourceBaseManager struct {
|
||||
SManagedResourceBaseManager
|
||||
}
|
||||
|
||||
func ValidateVpcResourceInput(userCred mcclient.TokenCredential, input api.VpcResourceInput) (*SVpc, api.VpcResourceInput, error) {
|
||||
vpcObj, err := VpcManager.FetchByIdOrName(userCred, input.VpcId)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, input, httperrors.NewResourceNotFoundError2(VpcManager.Keyword(), input.VpcId)
|
||||
} else {
|
||||
return nil, input, errors.Wrap(err, "VpcManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
input.VpcId = vpcObj.GetId()
|
||||
return vpcObj.(*SVpc), input, nil
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetVpc() *SVpc {
|
||||
obj, _ := VpcManager.FetchById(self.VpcId)
|
||||
if obj == nil {
|
||||
@@ -180,11 +167,16 @@ func (manager *SVpcResourceBaseManager) ListItemFilter(
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
if len(query.VpcId) > 0 {
|
||||
vpcObj, _, err := ValidateVpcResourceInput(userCred, query.VpcResourceInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ValidateVpcResourceInput")
|
||||
switch query.VpcId {
|
||||
case api.CLASSIC_VPC_NAME:
|
||||
q = q.Equals("name", api.CLASSIC_VPC_NAME)
|
||||
default:
|
||||
_, err := validators.ValidateModel(userCred, VpcManager, &query.VpcId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q = q.Equals("vpc_id", query.VpcId)
|
||||
}
|
||||
q = q.Equals("vpc_id", vpcObj.GetId())
|
||||
}
|
||||
subq := VpcManager.Query("id").Snapshot()
|
||||
subq, err = manager.SCloudregionResourceBaseManager.ListItemFilter(ctx, subq, userCred, query.RegionalFilterListInput)
|
||||
|
||||
@@ -287,7 +287,7 @@ func (manager *SVpcManager) GetOrCreateVpcForClassicNetwork(ctx context.Context,
|
||||
vpc.IsDefault = false
|
||||
vpc.CloudregionId = region.Id
|
||||
vpc.SetModelManager(manager, vpc)
|
||||
vpc.Name = "-"
|
||||
vpc.Name = api.CLASSIC_VPC_NAME
|
||||
vpc.IsEmulated = true
|
||||
vpc.SetEnabled(false)
|
||||
vpc.Status = api.VPC_STATUS_UNAVAILABLE
|
||||
|
||||
@@ -113,11 +113,11 @@ func (manager *SWireManager) ValidateCreateData(
|
||||
input.VpcId = api.DEFAULT_VPC_ID
|
||||
}
|
||||
|
||||
var vpc *SVpc
|
||||
vpc, input.VpcResourceInput, err = ValidateVpcResourceInput(userCred, input.VpcResourceInput)
|
||||
_vpc, err := validators.ValidateModel(userCred, VpcManager, &input.VpcId)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "ValidateVpcResourceInput")
|
||||
return input, err
|
||||
}
|
||||
vpc := _vpc.(*SVpc)
|
||||
|
||||
if len(vpc.ManagerId) > 0 {
|
||||
return input, httperrors.NewNotSupportedError("Currently only kvm platform supports creating wire")
|
||||
|
||||
Reference in New Issue
Block a user