mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #208 in YUNIONIO/onecloud from ~LIZEXI/onecloud:feature/lzx-network-list-by-region to release/2.1.0
* commit 'eb77372794804d7f500c188b28ba24ecda6542b3': region: network list by cloudregion
This commit is contained in:
@@ -12,10 +12,11 @@ import (
|
||||
func init() {
|
||||
type NetworkListOptions struct {
|
||||
options.BaseListOptions
|
||||
Ip string `help:"search networks that contain this IP"`
|
||||
Zone string `help:"search networks in a zone"`
|
||||
Wire string `help:"search networks belongs to a wire"`
|
||||
Vpc string `help:"search networks belongs to a VPC"`
|
||||
Ip string `help:"search networks that contain this IP"`
|
||||
Zone string `help:"search networks in a zone"`
|
||||
Wire string `help:"search networks belongs to a wire"`
|
||||
Vpc string `help:"search networks belongs to a VPC"`
|
||||
Region string `help:"search networks belongs to a CloudRegion"`
|
||||
}
|
||||
R(&NetworkListOptions{}, "network-list", "List networks", func(s *mcclient.ClientSession, args *NetworkListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
@@ -36,6 +37,9 @@ func init() {
|
||||
if len(args.Vpc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Vpc), "vpc")
|
||||
}
|
||||
if len(args.Region) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Region), "cloudregion")
|
||||
}
|
||||
var result *modules.ListResult
|
||||
var err error
|
||||
if len(args.Wire) > 0 {
|
||||
|
||||
@@ -1211,6 +1211,24 @@ func (manager *SNetworkManager) ListItemFilter(ctx context.Context, q *sqlchemy.
|
||||
sq := WireManager.Query("id").Equals("vpc_id", vpcObj.GetId())
|
||||
q = q.Filter(sqlchemy.In(q.Field("wire_id"), sq.SubQuery()))
|
||||
}
|
||||
regionStr := jsonutils.GetAnyString(query, []string{"region_id", "region", "cloudregion_id", "cloudregion"})
|
||||
if len(regionStr) > 0 {
|
||||
region, err := CloudregionManager.FetchByIdOrName(userCred.GetProjectId(), regionStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("cloud region %s not found", regionStr)
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
wires := WireManager.Query().SubQuery()
|
||||
vpcs := VpcManager.Query().SubQuery()
|
||||
sq := wires.Query(wires.Field("id")).
|
||||
Join(vpcs, sqlchemy.AND(
|
||||
sqlchemy.Equals(vpcs.Field("cloudregion_id"), region.GetId()),
|
||||
sqlchemy.Equals(wires.Field("vpc_id"), vpcs.Field("id"))))
|
||||
q = q.Filter(sqlchemy.In(q.Field("wire_id"), sq.SubQuery()))
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user