mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): add api field for vpc-peering
This commit is contained in:
@@ -56,7 +56,11 @@ type InterVpcNetworkSyncstatusInput struct {
|
||||
}
|
||||
|
||||
type InterVpcNetworkAddVpcInput struct {
|
||||
VpcId string
|
||||
// 待加入的vpc id
|
||||
// vpc和当前vpc互联所必须是同一平台,且运营平台一致,例如aws中国区不能和aws国际区运营平台不一致
|
||||
// 可以通过 /vpcs?usable_for_inter_vpc_network_id=<当前vpc互联id> 过滤可以加入的vpc列表
|
||||
// required: true
|
||||
VpcId string `json:"vpc_id"`
|
||||
}
|
||||
|
||||
type InterVpcNetworkRemoveVpcInput struct {
|
||||
|
||||
@@ -28,7 +28,8 @@ const (
|
||||
|
||||
type VpcPeeringConnectionDetails struct {
|
||||
apis.EnabledStatusInfrasResourceBaseDetails
|
||||
VpcName string
|
||||
VpcResourceInfo
|
||||
|
||||
PeerVpcName string
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ type VpcListInput struct {
|
||||
DnsZoneFilterListBase
|
||||
|
||||
InterVpcNetworkFilterListBase
|
||||
// 过滤可以加入指定vpc互联的vpc
|
||||
UsableForInterVpcNetworkId string `json:"usable_for_inter_vpc_network_id"`
|
||||
|
||||
UsableResourceListInput
|
||||
UsableVpcResourceListInput
|
||||
|
||||
@@ -1477,6 +1477,7 @@ func (self *SCloudprovider) RealDelete(ctx context.Context, userCred mcclient.To
|
||||
CDNDomainManager,
|
||||
NetworkInterfaceManager,
|
||||
KubeClusterManager,
|
||||
InterVpcNetworkManager,
|
||||
CloudproviderRegionManager,
|
||||
CloudregionManager,
|
||||
CloudproviderQuotaManager,
|
||||
|
||||
@@ -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/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -111,6 +112,25 @@ func (manager *SInterVpcNetworkManager) ListItemFilter(
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SInterVpcNetworkManager) ListItemExportKeys(ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
keys stringutils2.SSortedStrings,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = manager.SEnabledStatusInfrasResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
if keys.ContainsAny(manager.SManagedResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SManagedResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SInterVpcNetworkManager) ValidateCreateData(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
@@ -141,10 +161,12 @@ func (manager *SInterVpcNetworkManager) FetchCustomizeColumns(
|
||||
) []api.InterVpcNetworkDetails {
|
||||
rows := make([]api.InterVpcNetworkDetails, len(objs))
|
||||
stdRows := manager.SEnabledStatusInfrasResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
manRows := manager.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
vpcNetworkIds := make([]string, len(objs))
|
||||
for i := range rows {
|
||||
rows[i] = api.InterVpcNetworkDetails{
|
||||
EnabledStatusInfrasResourceBaseDetails: stdRows[i],
|
||||
ManagedResourceInfo: manRows[i],
|
||||
}
|
||||
vpcNetwork := objs[i].(*SInterVpcNetwork)
|
||||
vpcNetworkIds[i] = vpcNetwork.Id
|
||||
@@ -264,13 +286,9 @@ func (self *SInterVpcNetwork) PerformAddvpc(ctx context.Context, userCred mcclie
|
||||
if len(input.VpcId) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("vpc_id")
|
||||
}
|
||||
// get vpc
|
||||
_vpc, err := VpcManager.FetchByIdOrName(userCred, input.VpcId)
|
||||
_vpc, err := validators.ValidateModel(userCred, VpcManager, &input.VpcId)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2("vpc", input.VpcId)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
return nil, err
|
||||
}
|
||||
vpc := _vpc.(*SVpc)
|
||||
|
||||
|
||||
@@ -1936,6 +1936,21 @@ func (vpcPC *SVpcPeeringConnection) purge(ctx context.Context, userCred mcclient
|
||||
return vpcPC.RealDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (manager *SInterVpcNetworkManager) purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error {
|
||||
networks := []SInterVpcNetwork{}
|
||||
err := fetchByManagerId(manager, providerId, &networks)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "fetchByManagerId")
|
||||
}
|
||||
for i := range networks {
|
||||
err := networks[i].RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "inter vpc network delete")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SWafRuleGroupCacheManager) purgeAll(ctx context.Context, userCred mcclient.TokenCredential, providerId string) error {
|
||||
caches := []SWafRuleGroupCache{}
|
||||
err := fetchByManagerId(manager, providerId, &caches)
|
||||
|
||||
@@ -253,20 +253,21 @@ func (manager *SVpcPeeringConnectionManager) FetchCustomizeColumns(
|
||||
) []api.VpcPeeringConnectionDetails {
|
||||
rows := make([]api.VpcPeeringConnectionDetails, len(objs))
|
||||
stdRows := manager.SEnabledStatusInfrasResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
vpcIds := make([]string, len(objs))
|
||||
vpcObjs := make([]interface{}, len(objs))
|
||||
peerVpcIds := make([]string, len(objs))
|
||||
for i := range rows {
|
||||
rows[i] = api.VpcPeeringConnectionDetails{
|
||||
EnabledStatusInfrasResourceBaseDetails: stdRows[i],
|
||||
}
|
||||
vpcPC := objs[i].(*SVpcPeeringConnection)
|
||||
vpcIds[i] = vpcPC.VpcId
|
||||
vpcObj := &SVpcResourceBase{VpcId: vpcPC.VpcId}
|
||||
vpcObjs[i] = vpcObj
|
||||
peerVpcIds[i] = vpcPC.PeerVpcId
|
||||
}
|
||||
|
||||
vpcMap, err := db.FetchIdNameMap2(VpcManager, vpcIds)
|
||||
if err != nil {
|
||||
return rows
|
||||
vpcRows := manager.SVpcResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, vpcObjs, fields, isList)
|
||||
for i := range rows {
|
||||
rows[i].VpcResourceInfo = vpcRows[i]
|
||||
}
|
||||
peerVpcMap, err := db.FetchIdNameMap2(VpcManager, peerVpcIds)
|
||||
if err != nil {
|
||||
@@ -274,7 +275,6 @@ func (manager *SVpcPeeringConnectionManager) FetchCustomizeColumns(
|
||||
}
|
||||
|
||||
for i := range rows {
|
||||
rows[i].VpcName, _ = vpcMap[vpcIds[i]]
|
||||
rows[i].PeerVpcName, _ = peerVpcMap[peerVpcIds[i]]
|
||||
}
|
||||
return rows
|
||||
@@ -341,6 +341,7 @@ func (manager *SVpcPeeringConnectionManager) ListItemExportKeys(ctx context.Cont
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1103,6 +1103,30 @@ func (manager *SVpcManager) ListItemFilter(
|
||||
q = q.In("id", sq.SubQuery())
|
||||
}
|
||||
|
||||
if len(query.UsableForInterVpcNetworkId) > 0 {
|
||||
_interVpc, err := validators.ValidateModel(userCred, InterVpcNetworkManager, &query.UsableForInterVpcNetworkId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
interVpc := _interVpc.(*SInterVpcNetwork)
|
||||
sq := InterVpcNetworkVpcManager.Query("vpc_id").Equals("inter_vpc_network_id", interVpc.GetId())
|
||||
q = q.NotIn("id", sq.SubQuery())
|
||||
account := interVpc.GetCloudaccount()
|
||||
if account == nil {
|
||||
return nil, httperrors.NewNotSupportedError("not supported for inter vpc network %s", interVpc.Name)
|
||||
}
|
||||
vpcs := VpcManager.Query().SubQuery()
|
||||
managers := CloudproviderManager.Query().SubQuery()
|
||||
accounts := CloudaccountManager.Query().SubQuery()
|
||||
vpcSQ := vpcs.Query(vpcs.Field("id")).Join(managers, sqlchemy.Equals(vpcs.Field("manager_id"), managers.Field("id"))).Join(accounts, sqlchemy.Equals(managers.Field("cloudaccount_id"), accounts.Field("id"))).Filter(
|
||||
sqlchemy.AND(
|
||||
sqlchemy.Equals(accounts.Field("provider"), account.Provider),
|
||||
sqlchemy.Equals(accounts.Field("access_url"), account.AccessUrl),
|
||||
),
|
||||
)
|
||||
q = q.In("id", vpcSQ.SubQuery())
|
||||
}
|
||||
|
||||
if len(query.InterVpcNetworkId) > 0 {
|
||||
vpcNetwork, err := InterVpcNetworkManager.FetchByIdOrName(userCred, query.InterVpcNetworkId)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,13 +23,14 @@ import (
|
||||
type VpcListOptions struct {
|
||||
BaseListOptions
|
||||
|
||||
Usable *bool `help:"Filter usable vpcs"`
|
||||
Region string `help:"ID or Name of region" json:"-"`
|
||||
Globalvpc string `help:"Filter by globalvpc"`
|
||||
DnsZoneId string `help:"Filter by DnsZone"`
|
||||
InterVpcNetworkId string `help:"Filter by InterVpcNetwork"`
|
||||
ExternalAccessMode string `help:"Filter by external access mode" choices:"distgw|eip|eip-distgw"`
|
||||
ZoneId string `help:"Filter by zone which has networks"`
|
||||
Usable *bool `help:"Filter usable vpcs"`
|
||||
Region string `help:"ID or Name of region" json:"-"`
|
||||
Globalvpc string `help:"Filter by globalvpc"`
|
||||
DnsZoneId string `help:"Filter by DnsZone"`
|
||||
InterVpcNetworkId string `help:"Filter by InterVpcNetwork"`
|
||||
ExternalAccessMode string `help:"Filter by external access mode" choices:"distgw|eip|eip-distgw"`
|
||||
ZoneId string `help:"Filter by zone which has networks"`
|
||||
UsableForInterVpcNetworkId string `help:"Filter usable vpcs for inter vpc network"`
|
||||
}
|
||||
|
||||
func (opts *VpcListOptions) GetContextId() string {
|
||||
|
||||
Reference in New Issue
Block a user