Merge pull request #16401 from gouqi11/addResourceOrder

feature(region): add resource order
This commit is contained in:
Zexi Li
2023-04-11 21:05:12 +08:00
committed by GitHub
51 changed files with 445 additions and 23 deletions
+2
View File
@@ -93,6 +93,8 @@ type DiskBackupListInput struct {
BackupStorageId string `json:"backup_storage_id"`
// description: 是否为主机备份的一部分
IsInstanceBackup *bool `json:"is_instance_backup"`
// 按硬盘名称排序
OrderByDiskName string `json:"order_by_disk_name"`
}
type DiskBackupDetails struct {
+7
View File
@@ -254,6 +254,13 @@ type CloudaccountListInput struct {
ProxySetting string `json:"proxy_setting"`
// swagger:ignore
ProxySettingId string `json:"proxy_setting_id" yunion-deprecated-by:"proxy_setting"`
// 按宿主机数量排序
// pattern:asc|desc
OrderByHostCount string `json:"order_by_host_count"`
// 按虚拟机数量排序
// pattern:asc|desc
OrderByGuestCount string `json:"order_by_guest_count"`
}
type ProviderProject struct {
+3
View File
@@ -105,4 +105,7 @@ type ElasticipListInput struct {
// 是否跟随主机删除而自动释放
AutoDellocate *bool `json:"auto_dellocate"`
// 按ip地址排序
// pattern:asc|desc
OrderByIp string `json:"order_by_ip"`
}
+15
View File
@@ -106,6 +106,15 @@ type CloudregionListInput struct {
// 云环境
Environment []string `json:"environment"`
// 按可用区数量排序
// pattern:asc|desc
OrderByZoneCount string `json:"order_by_zone_count"`
// 按vpc数量排序
// pattern:asc|desc
OrderByVpcCount string `json:"order_by_vpc_count"`
// 按虚拟机数量排序
// pattern:asc|desc
OrderByGuestCount string `json:"order_by_guest_count"`
}
type ZoneListInput struct {
@@ -124,6 +133,12 @@ type ZoneListInput struct {
Location []string `json:"location"`
Contacts []string `json:"contacts"`
OrderByWires string
OrderByHosts string
OrderByHostsEnabled string
OrderByBaremetals string
OrderByBaremetalsEnabled string
}
type ZoneResourceInput struct {
+4
View File
@@ -53,6 +53,7 @@ type GlobalVpcResourceListInput struct {
GlobalVpcResourceInput
// 以GlobalVpc的名称排序
// pattern:asc|desc
OrderByGlobalvpc string `json:"order_by_globalvpc"`
}
@@ -65,4 +66,7 @@ type GlobalVpcListInput struct {
apis.ExternalizedResourceBaseListInput
ManagedResourceListInput
// 以关联的vpc数量排序
// pattern:asc|desc
OrderByVpcCount string `json:"order_by_vpc_count"`
}
+3
View File
@@ -162,6 +162,9 @@ type ServiceCatalogListInput struct {
type SnapshotPolicyListInput struct {
apis.VirtualResourceListInput
// 按绑定的磁盘数量排序
// pattern:asc|desc
OrderByBindDiskCount string `json:"order_by_bind_disk_count"`
// 是否启用?
IsActivated *bool `json:"is_activated"`
}
+4
View File
@@ -48,6 +48,10 @@ type InstanceBackupListInput struct {
ServerFilterListInput
// 按虚拟机名称排序
// pattern:asc|desc
OrderByGuest string `json:"order_by_guest"`
// 操作系统类型
OsType []string `json:"os_type"`
}
+6
View File
@@ -32,6 +32,12 @@ type InstanceGroupListInput struct {
// 调度策略
SchedStrategy string `json:"sched_strategy"`
// 按ip地址排序
// pattern:asc|desc
OrderByVips string `json:"order_by_vips"`
// 按关联的虚拟机数量排序
// pattern:asc|desc
OrderByGuestCount string `json:"order_by_guest_count"`
}
type InstanceGroupDetail struct {
+6
View File
@@ -79,4 +79,10 @@ type InstanceSnapshotListInput struct {
// 包含内存快照
WithMemory *bool `json:"with_memory"`
// 按磁盘快照数量排序
// pattern:asc|desc
OrderByDiskSnapshotCount string `json:"order_by_disk_snapshot_count"`
// 按虚拟机名称排序
// pattern:asc|desc
OrderByGuest string `json:"order_by_guest"`
}
+4
View File
@@ -78,4 +78,8 @@ type InterVpcNetworkFilterListBase struct {
type InterVpcNetworkManagerListInput struct {
apis.EnabledStatusInfrasResourceBaseListInput
ManagedResourceListInput
// 按关联的vpc数量排序
// pattern:asc|desc
OrderByVpcCount string `json:"order_by_vpc_count"`
}
+6
View File
@@ -25,6 +25,12 @@ type NetTapServiceListInput struct {
apis.EnabledStatusStandaloneResourceListInput
HostId string `json:"host_id" help:"filter by host id or name"`
// 按目的ip地址排序
// pattern:asc|desc
OrderByIp string `json:"order_by_ip"`
// 按镜像源数量排序
// pattern:asc|desc
OrderByFlowCount string `json:"order_by_flow_count"`
}
type NetTapServiceDetails struct {
+7
View File
@@ -143,6 +143,13 @@ type NetworkListInput struct {
BgpType []string `json:"bgp_type"`
HostType string `json:"host_type"`
// 按起始ip地址排序
// pattern:asc|desc
OrderByIpStart string `json:"order_by_ip_start"`
// 按终止ip地址排序
// pattern:asc|desc
OrderByIpEnd string `json:"order_by_ip_end"`
}
type NetworkResourceInfoBase struct {
+3
View File
@@ -79,6 +79,9 @@ type ServerSkuListInput struct {
// 按套餐名称去重
Distinct bool `json:"distinct"`
// 按关联虚拟机数量排序
OrderByTotalGuestCount string `json:"order_by_total_guest_count"`
}
type ElasticcacheSkuListInput struct {
+7
View File
@@ -95,6 +95,13 @@ type SnapshotListInput struct {
// list server snapshots
ServerId string `json:"server_id"`
// 按虚拟机名称排序
// pattern:asc|desc
OrderByGuest string `json:"order_by_guest"`
// 按磁盘名称排序
// pattern:asc|desc
OrderByDiskName string `json:"order_by_disk_name"`
}
type SnapshotDetails struct {
+5
View File
@@ -83,7 +83,12 @@ type VpcListInput struct {
// enmu: eip, none
ExternalAccessMode string `json:"external_access_mode"`
// 按子网数量排序
// pattern:asc|desc
OrderByNetworkCount string `json:"order_by_network_count"`
// 按二层网络数量排序
// pattern:asc|desc
OrderByWireCount string `json:""order_by_wire_count`
}
const (
+4
View File
@@ -107,6 +107,10 @@ type WireListInput struct {
Bandwidth *int `json:"bandwidth"`
HostType string `json:"host_type"`
// 按子网数量排序
// pattern:asc|desc
OrderByNetworkCount string `json:"order_by_network_count"`
}
type WireMergeInput struct {
+37
View File
@@ -1777,6 +1777,43 @@ func (manager *SCloudaccountManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByHostCount}) {
hostQ := HostManager.Query()
hostQ = hostQ.AppendField(hostQ.Field("manager_id"), sqlchemy.COUNT("host_count"))
hostQ = hostQ.GroupBy("manager_id")
hostSQ := hostQ.SubQuery()
providerQ := CloudproviderManager.Query()
providerQ = providerQ.Join(hostSQ, sqlchemy.Equals(providerQ.Field("id"), hostSQ.Field("manager_id")))
providerQ = providerQ.AppendField(providerQ.Field("cloudaccount_id"), sqlchemy.SUM("host_count", hostSQ.Field("host_count")))
providerQ = providerQ.GroupBy("cloudaccount_id")
providerSQ := providerQ.SubQuery()
q = q.Join(providerSQ, sqlchemy.Equals(providerSQ.Field("cloudaccount_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(providerSQ.Field("host_count"))
q = db.OrderByFields(q, []string{query.OrderByHostCount}, []sqlchemy.IQueryField{q.Field("host_count")})
}
if db.NeedOrderQuery([]string{query.OrderByGuestCount}) {
guestQ := GuestManager.Query()
guestQ = guestQ.AppendField(guestQ.Field("host_id"), sqlchemy.COUNT("guest_count"))
guestQ = guestQ.GroupBy("host_id")
guestSQ := guestQ.SubQuery()
hostQ := HostManager.Query()
hostQ = hostQ.Join(guestSQ, sqlchemy.Equals(hostQ.Field("id"), guestSQ.Field("host_id")))
hostQ = hostQ.AppendField(hostQ.Field("manager_id"), sqlchemy.SUM("guest_count", guestQ.Field("guest_count")))
hostQ = hostQ.GroupBy("manager_id")
hostSQ := hostQ.SubQuery()
providerQ := CloudproviderManager.Query()
providerQ = providerQ.Join(hostSQ, sqlchemy.Equals(providerQ.Field("id"), hostSQ.Field("manager_id")))
providerQ = providerQ.AppendField(providerQ.Field("cloudaccount_id"), sqlchemy.SUM("guest_count", hostSQ.Field("guest_count")))
providerQ = providerQ.GroupBy("cloudaccount_id")
providerSQ := providerQ.SubQuery()
q = q.Join(providerSQ, sqlchemy.Equals(providerSQ.Field("cloudaccount_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(providerSQ.Field("guest_count"))
q = db.OrderByFields(q, []string{query.OrderByGuestCount}, []sqlchemy.IQueryField{q.Field("guest_count")})
}
return q, nil
}
+44
View File
@@ -678,6 +678,50 @@ func (manager *SCloudregionManager) OrderByExtraFields(ctx context.Context, q *s
if err != nil {
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByZoneCount}) {
zQ := ZoneManager.Query()
zQ = zQ.AppendField(zQ.Field("cloudregion_id"), sqlchemy.COUNT("zone_count", zQ.Field("cloudregion_id")))
zQ = zQ.GroupBy(zQ.Field("cloudregion_id"))
zSQ := zQ.SubQuery()
q = q.LeftJoin(zSQ, sqlchemy.Equals(zSQ.Field("cloudregion_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(zSQ.Field("zone_count"))
q = db.OrderByFields(q, []string{query.OrderByZoneCount}, []sqlchemy.IQueryField{q.Field("zone_count")})
}
if db.NeedOrderQuery([]string{query.OrderByVpcCount}) {
vQ := VpcManager.Query()
vQ = vQ.AppendField(vQ.Field("cloudregion_id"), sqlchemy.COUNT("vpc_count", vQ.Field("cloudregion_id")))
vQ = vQ.GroupBy(vQ.Field("cloudregion_id"))
vSQ := vQ.SubQuery()
q = q.LeftJoin(vSQ, sqlchemy.Equals(vSQ.Field("cloudregion_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(vSQ.Field("vpc_count"))
q = db.OrderByFields(q, []string{query.OrderByZoneCount}, []sqlchemy.IQueryField{q.Field("vpc_count")})
}
if db.NeedOrderQuery([]string{query.OrderByGuestCount}) {
guestQ := GuestManager.Query()
guestQ = guestQ.AppendField(guestQ.Field("host_id"), sqlchemy.COUNT("guest_count"))
guestQ = guestQ.GroupBy(guestQ.Field("host_id"))
guestSQ := guestQ.SubQuery()
hostQ := HostManager.Query()
hostQ = hostQ.LeftJoin(guestSQ, sqlchemy.Equals(guestSQ.Field("host_id"), hostQ.Field("id")))
hostQ = hostQ.AppendField(hostQ.QueryFields()...)
hostQ = hostQ.AppendField(hostQ.Field("zone_id"), sqlchemy.COUNT("guest_count", guestSQ.Field("guest_count")))
hostQ = hostQ.GroupBy("zone_id")
hostSQ := hostQ.SubQuery()
zQ := ZoneManager.Query()
zQ = zQ.AppendField(zQ.Field("cloudregion_id"), sqlchemy.COUNT("guest_count", hostSQ.Field("guest_count")))
zQ = zQ.GroupBy(zQ.Field("cloudregion_id"))
zQ = zQ.LeftJoin(hostSQ, sqlchemy.Equals(zQ.Field("id"), hostSQ.Field("zone_id")))
zSQ := zQ.SubQuery()
q = q.LeftJoin(zSQ, sqlchemy.Equals(zSQ.Field("cloudregion_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(zSQ.Field("guest_count"))
q = db.OrderByFields(q, []string{query.OrderByGuestCount}, []sqlchemy.IQueryField{q.Field("guest_count")})
}
return q, nil
}
+9
View File
@@ -389,6 +389,15 @@ func (manager *SDiskBackupManager) OrderByExtraFields(ctx context.Context, q *sq
if err != nil {
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByDiskName}) {
dQ := DiskManager.Query()
dSQ := dQ.AppendField(dQ.Field("name").Label("disk_name"), dQ.Field("id")).SubQuery()
q = q.LeftJoin(dSQ, sqlchemy.Equals(dSQ.Field("id"), q.Field("disk_id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(dSQ.Field("disk_name"))
q = db.OrderByFields(q, []string{query.OrderByDiskName}, []sqlchemy.IQueryField{q.Field("disk_name")})
}
return q, nil
}
+3
View File
@@ -304,6 +304,9 @@ func (manager *SElasticipManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByIp}) {
db.OrderByFields(q, []string{query.OrderByIp}, []sqlchemy.IQueryField{sqlchemy.INET_ATON(q.Field("ip_addr"))})
}
return q, nil
}
+10
View File
@@ -224,6 +224,16 @@ func (manager *SGlobalVpcManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByVpcCount}) {
vpcQ := VpcManager.Query()
vpcQ = vpcQ.AppendField(vpcQ.Field("globalvpc_id"), sqlchemy.COUNT("vpc_count"))
vpcQ = vpcQ.GroupBy(vpcQ.Field("globalvpc_id"))
vpcSQ := vpcQ.SubQuery()
q = q.LeftJoin(vpcSQ, sqlchemy.Equals(vpcSQ.Field("globalvpc_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(vpcSQ.Field("vpc_count"))
q = db.OrderByFields(q, []string{query.OrderByVpcCount}, []sqlchemy.IQueryField{q.Field("vpc_count")})
}
return q, nil
}
+20 -1
View File
@@ -153,7 +153,26 @@ func (sm *SGroupManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SZoneResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{input.OrderByVips}) {
gnQ := GroupnetworkManager.Query()
gnQ = gnQ.AppendField(gnQ.Field("group_id"), sqlchemy.COUNT("vips", gnQ.Field("ip_addr")))
gnQ = gnQ.GroupBy("group_id")
gnSQ := gnQ.SubQuery()
q = q.LeftJoin(gnSQ, sqlchemy.Equals(gnSQ.Field("group_id"), q.Field("id")))
q.AppendField(q.QueryFields()...)
q.AppendField(gnSQ.Field("vips"))
q = db.OrderByFields(q, []string{input.OrderByVips}, []sqlchemy.IQueryField{q.Field("vips")})
}
if db.NeedOrderQuery([]string{input.OrderByGuestCount}) {
ggQ := GroupguestManager.Query()
ggQ = ggQ.AppendField(ggQ.Field("group_id"), sqlchemy.COUNT("guest_count"))
ggQ = ggQ.GroupBy("group_id")
ggSQ := ggQ.SubQuery()
q = q.LeftJoin(ggSQ, sqlchemy.Equals(ggSQ.Field("group_id"), q.Field("id")))
q.AppendField(q.QueryFields()...)
q.AppendField(ggSQ.Field("guest_count"))
q = db.OrderByFields(q, []string{input.OrderByGuestCount}, []sqlchemy.IQueryField{q.Field("guest_count")})
}
return q, nil
}
-1
View File
@@ -686,7 +686,6 @@ func (manager *SGuestManager) OrderByExtraFields(ctx context.Context, q *sqlchem
q = q.LeftJoin(guestnet, sqlchemy.Equals(q.Field("id"), guestnet.Field("guest_id")))
db.OrderByFields(q, []string{query.OrderByIp}, []sqlchemy.IQueryField{sqlchemy.INET_ATON(q.Field("ip_addr"))})
}
return q, nil
}
+8
View File
@@ -141,6 +141,14 @@ func (manager *SInstanceBackupManager) OrderByExtraFields(
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByGuest}) {
gQ := GuestManager.Query()
gSQ := gQ.AppendField(gQ.Field("name").Label("guest_name"), gQ.Field("id")).SubQuery()
q = q.LeftJoin(gSQ, sqlchemy.Equals(gSQ.Field("id"), q.Field("guest_id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(gSQ.Field("guest_name"))
q = db.OrderByFields(q, []string{query.OrderByGuest}, []sqlchemy.IQueryField{q.Field("guest_name")})
}
return q, nil
}
+24
View File
@@ -178,6 +178,30 @@ func (manager *SInstanceSnapshotManager) OrderByExtraFields(
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByDiskSnapshotCount}) {
nQ := SnapshotManager.Query()
nQ = nQ.AppendField(nQ.Field("disk_id"), sqlchemy.COUNT("snapshot_count"))
nQ = nQ.GroupBy("disk_id")
nSQ := nQ.SubQuery()
guestdiskQ := GuestdiskManager.Query()
guestdiskQ = guestdiskQ.LeftJoin(nSQ, sqlchemy.Equals(nSQ.Field("disk_id"), guestdiskQ.Field("disk_id")))
guestdiskSQ := guestdiskQ.AppendField(guestdiskQ.Field("guest_id"), nSQ.Field("snapshot_count")).SubQuery()
q = q.LeftJoin(guestdiskSQ, sqlchemy.Equals(guestdiskSQ.Field("guest_id"), q.Field("guest_id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(guestdiskSQ.Field("snapshot_count"))
q = db.OrderByFields(q, []string{query.OrderByDiskSnapshotCount}, []sqlchemy.IQueryField{q.Field("snapshot_count")})
}
if db.NeedOrderQuery([]string{query.OrderByGuest}) {
guestQ := GuestManager.Query()
guestSQ := guestQ.AppendField(guestQ.Field("id"), guestQ.Field("name").Label("guest_name")).SubQuery()
q = q.LeftJoin(guestSQ, sqlchemy.Equals(guestSQ.Field("id"), q.Field("guest_id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(guestSQ.Field("guest_name"))
q = db.OrderByFields(q, []string{query.OrderByGuest}, []sqlchemy.IQueryField{q.Field("guest_name")})
}
return q, nil
}
+10
View File
@@ -91,6 +91,16 @@ func (manager *SInterVpcNetworkManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByVpcCount}) {
vpcNetVpcQ := InterVpcNetworkVpcManager.Query()
vpcNetVpcQ = vpcNetVpcQ.AppendField(vpcNetVpcQ.Field("inter_vpc_network_id"), sqlchemy.COUNT("vpc_count", vpcNetVpcQ.Field("vpc_id")))
vpcNetVpcQ = vpcNetVpcQ.GroupBy(vpcNetVpcQ.Field("inter_vpc_network_id"))
vpcNetVpcSQ := vpcNetVpcQ.SubQuery()
q = q.LeftJoin(vpcNetVpcSQ, sqlchemy.Equals(vpcNetVpcSQ.Field("inter_vpc_network_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(vpcNetVpcSQ.Field("vpc_count"))
q = db.OrderByFields(q, []string{query.OrderByVpcCount}, []sqlchemy.IQueryField{q.Field("vpc_count")})
}
return q, nil
}
+17
View File
@@ -130,6 +130,23 @@ func (man *SNetTapServiceManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SEnabledStatusInfrasResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByIp}) {
hSQ := HostManager.Query("id", "access_ip").SubQuery()
q = q.LeftJoin(hSQ, sqlchemy.Equals(q.Field("target_id"), hSQ.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(hSQ.Field("access_ip"))
db.OrderByFields(q, []string{query.OrderByIp}, []sqlchemy.IQueryField{q.Field("access_ip")})
}
if db.NeedOrderQuery([]string{query.OrderByFlowCount}) {
ntfQ := NetTapFlowManager.Query()
ntfQ = ntfQ.AppendField(ntfQ.Field("tap_id"), sqlchemy.COUNT("flow_count", ntfQ.Field("tap_id")))
ntfQ = ntfQ.GroupBy("tap_id")
ntfSQ := ntfQ.SubQuery()
q = q.LeftJoin(ntfSQ, sqlchemy.Equals(q.Field("id"), ntfSQ.Field("tap_id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(ntfSQ.Field("flow_count"))
db.OrderByFields(q, []string{query.OrderByFlowCount}, []sqlchemy.IQueryField{q.Field("flow_count")})
}
return q, nil
}
+6
View File
@@ -2302,6 +2302,12 @@ func (manager *SNetworkManager) OrderByExtraFields(
return nil, errors.Wrap(err, "SWireResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{input.OrderByIpStart}) {
q = db.OrderByFields(q, []string{input.OrderByIpStart}, []sqlchemy.IQueryField{sqlchemy.INET_ATON(q.Field("guest_ip_start"))})
}
if db.NeedOrderQuery([]string{input.OrderByIpEnd}) {
q = db.OrderByFields(q, []string{input.OrderByIpEnd}, []sqlchemy.IQueryField{sqlchemy.INET_ATON(q.Field("guest_ip_end"))})
}
return q, nil
}
-1
View File
@@ -232,7 +232,6 @@ func (manager *SSchedtagManager) OrderByExtraFields(
query api.SchedtagListInput,
) (*sqlchemy.SQuery, error) {
var err error
q, err = manager.SStandaloneResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.StandaloneResourceListInput)
if err != nil {
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.OrderByExtraFields")
+10
View File
@@ -851,6 +851,16 @@ func (manager *SServerSkuManager) OrderByExtraFields(
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByTotalGuestCount}) {
guestQ := GuestManager.Query()
guestQ = guestQ.AppendField(guestQ.Field("instance_type"), sqlchemy.COUNT("total_guest_count"))
guestQ = guestQ.GroupBy(guestQ.Field("instance_type"))
guestSQ := guestQ.SubQuery()
q = q.Join(guestSQ, sqlchemy.Equals(guestSQ.Field("instance_type"), q.Field("name")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(guestSQ.Field("total_guest_count"))
q = db.OrderByFields(q, []string{query.OrderByTotalGuestCount}, []sqlchemy.IQueryField{q.Field("total_guest_count")})
}
return q, nil
}
+8 -1
View File
@@ -966,7 +966,14 @@ func (manager *SSnapshotPolicyManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{input.OrderByBindDiskCount}) {
sdQ := SnapshotPolicyDiskManager.Query()
sdSQ := sdQ.AppendField(sdQ.Field("snapshotpolicy_id"), sqlchemy.COUNT("disk_count")).GroupBy("snapshotpolicy_id").SubQuery()
q = q.LeftJoin(sdSQ, sqlchemy.Equals(sdSQ.Field("snapshotpolicy_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(sdSQ.Field("disk_count"))
q = db.OrderByFields(q, []string{input.OrderByBindDiskCount}, []sqlchemy.IQueryField{q.Field("disk_count")})
}
return q, nil
}
+20
View File
@@ -245,6 +245,26 @@ func (manager *SSnapshotManager) OrderByExtraFields(
if err != nil {
return nil, errors.Wrap(err, "SStorageResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByGuest}) {
guestSQ := GuestManager.Query("name", "id").SubQuery()
guestdiskQ := GuestdiskManager.Query()
guestdiskQ = guestdiskQ.Join(guestSQ, sqlchemy.Equals(guestSQ.Field("id"), guestdiskQ.Field("guest_id")))
guestdiskSQ := guestdiskQ.AppendField(guestdiskQ.Field("disk_id"), guestSQ.Field("name").Label("guest_name")).SubQuery()
q = q.LeftJoin(guestdiskSQ, sqlchemy.Equals(guestdiskSQ.Field("disk_id"), q.Field("disk_id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(guestdiskSQ.Field("guest_name"))
q = db.OrderByFields(q, []string{query.OrderByGuest}, []sqlchemy.IQueryField{q.Field("guest_name")})
}
if db.NeedOrderQuery([]string{query.OrderByDiskName}) {
dSQ := DiskManager.Query("name", "id").SubQuery()
guestdiskQ := GuestdiskManager.Query()
guestdiskQ = guestdiskQ.LeftJoin(dSQ, sqlchemy.Equals(dSQ.Field("id"), guestdiskQ.Field("disk_id")))
guestdiskSQ := guestdiskQ.AppendField(guestdiskQ.Field("disk_id"), dSQ.Field("name").Label("disk_name")).SubQuery()
q = q.LeftJoin(guestdiskSQ, sqlchemy.Equals(guestdiskSQ.Field("disk_id"), q.Field("disk_id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(guestdiskSQ.Field("disk_name"))
q = db.OrderByFields(q, []string{query.OrderByDiskName}, []sqlchemy.IQueryField{q.Field("disk_name")})
}
return q, nil
}
+10
View File
@@ -1268,6 +1268,16 @@ func (manager *SVpcManager) OrderByExtraFields(
},
)
}
if db.NeedOrderQuery([]string{query.OrderByWireCount}) {
wireQ := WireManager.Query()
wireQ = wireQ.AppendField(wireQ.Field("vpc_id"), sqlchemy.COUNT("wire_count"))
wireQ = wireQ.GroupBy(wireQ.Field("vpc_id"))
wireSQ := wireQ.SubQuery()
q = q.LeftJoin(wireSQ, sqlchemy.Equals(wireSQ.Field("vpc_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(wireSQ.Field("wire_count"))
q = db.OrderByFields(q, []string{query.OrderByWireCount}, []sqlchemy.IQueryField{q.Field("wire_count")})
}
return q, nil
}
+10
View File
@@ -1386,6 +1386,16 @@ func (manager *SWireManager) OrderByExtraFields(
return nil, errors.Wrap(err, "SZoneResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByNetworkCount}) {
networkQ := NetworkManager.Query()
networkQ = networkQ.AppendField(networkQ.Field("wire_id"), sqlchemy.COUNT("network_count"))
networkQ = networkQ.GroupBy(networkQ.Field("wire_id"))
networkSQ := networkQ.SubQuery()
q = q.LeftJoin(networkSQ, sqlchemy.Equals(networkSQ.Field("wire_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(networkSQ.Field("network_count"))
q = db.OrderByFields(q, []string{query.OrderByNetworkCount}, []sqlchemy.IQueryField{q.Field("network_count")})
}
return q, nil
}
+54
View File
@@ -814,6 +814,60 @@ func (manager *SZoneManager) OrderByExtraFields(
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
}
if db.NeedOrderQuery([]string{query.OrderByWires}) {
wireQ := WireManager.Query()
wireQ = wireQ.AppendField(wireQ.Field("zone_id"), sqlchemy.COUNT("wire_count", wireQ.Field("zone_id")))
wireQ = wireQ.GroupBy(wireQ.Field("zone_id"))
wireSQ := wireQ.SubQuery()
q = q.LeftJoin(wireSQ, sqlchemy.Equals(wireSQ.Field("zone_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(wireSQ.Field("wire_count"))
q = db.OrderByFields(q, []string{query.OrderByWires}, []sqlchemy.IQueryField{q.Field("wire_count")})
}
if db.NeedOrderQuery([]string{query.OrderByHosts}) {
hostQ := HostManager.Query()
hostQ = hostQ.AppendField(hostQ.Field("zone_id"), sqlchemy.COUNT("host_count", hostQ.Field("zone_id")))
hostQ = hostQ.GroupBy(hostQ.Field("zone_id"))
hostSQ := hostQ.SubQuery()
q = q.LeftJoin(hostSQ, sqlchemy.Equals(hostSQ.Field("zone_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(hostSQ.Field("host_count"))
q = db.OrderByFields(q, []string{query.OrderByHosts}, []sqlchemy.IQueryField{q.Field("host_count")})
}
if db.NeedOrderQuery([]string{query.OrderByHostsEnabled}) {
hostQ := HostManager.Query()
hostQ = hostQ.Filter(sqlchemy.Equals(hostQ.Field("enabled"), true))
hostQ = hostQ.AppendField(hostQ.Field("zone_id"), sqlchemy.COUNT("host_count", hostQ.Field("zone_id")))
hostQ = hostQ.GroupBy(hostQ.Field("zone_id"))
hostSQ := hostQ.SubQuery()
q = q.LeftJoin(hostSQ, sqlchemy.Equals(hostSQ.Field("zone_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(hostSQ.Field("host_count"))
q = db.OrderByFields(q, []string{query.OrderByHostsEnabled}, []sqlchemy.IQueryField{q.Field("host_count")})
}
if db.NeedOrderQuery([]string{query.OrderByBaremetals}) {
hostQ := HostManager.Query()
hostQ = hostQ.Filter(sqlchemy.Equals(hostQ.Field("is_baremetal"), true))
hostQ = hostQ.AppendField(hostQ.Field("zone_id"), sqlchemy.COUNT("host_count", hostQ.Field("zone_id")))
hostQ = hostQ.GroupBy(hostQ.Field("zone_id"))
hostSQ := hostQ.SubQuery()
q = q.LeftJoin(hostSQ, sqlchemy.Equals(hostSQ.Field("zone_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(hostSQ.Field("host_count"))
q = db.OrderByFields(q, []string{query.OrderByBaremetals}, []sqlchemy.IQueryField{q.Field("host_count")})
}
if db.NeedOrderQuery([]string{query.OrderByBaremetalsEnabled}) {
hostQ := HostManager.Query()
hostQ = hostQ.Filter(sqlchemy.Equals(hostQ.Field("is_baremetal"), true))
hostQ = hostQ.Filter(sqlchemy.Equals(hostQ.Field("enabled"), true))
hostQ = hostQ.AppendField(hostQ.Field("zone_id"), sqlchemy.COUNT("host_count", hostQ.Field("zone_id")))
hostQ = hostQ.GroupBy(hostQ.Field("zone_id"))
hostSQ := hostQ.SubQuery()
q = q.LeftJoin(hostSQ, sqlchemy.Equals(hostSQ.Field("zone_id"), q.Field("id")))
q = q.AppendField(q.QueryFields()...)
q = q.AppendField(hostSQ.Field("host_count"))
q = db.OrderByFields(q, []string{query.OrderByBaremetalsEnabled}, []sqlchemy.IQueryField{q.Field("host_count")})
}
return q, nil
}
+4
View File
@@ -30,6 +30,10 @@ type CloudaccountListOptions struct {
//DistinctField string `help:"distinct field"`
ProxySetting string `help:"Proxy setting id or name"`
// 按宿主机数量排序
OrderByHostCount string
// 按虚拟机数量排序
OrderByGuestCount string
}
func (opts *CloudaccountListOptions) Params() (jsonutils.JSONObject, error) {
+3
View File
@@ -25,6 +25,7 @@ type DiskBackupListOptions struct {
DiskId string `help:"disk id" json:"disk_id"`
BackupStorageId string `help:"backup storage id" json:"backup_storage_id"`
IsInstanceBackup *bool `help:"if part of instance backup" json:"is_instance_backup"`
OrderByDiskName string
}
func (opts *DiskBackupListOptions) Params() (jsonutils.JSONObject, error) {
@@ -123,6 +124,8 @@ func (opts *BackupStorageCreateOptions) Params() (jsonutils.JSONObject, error) {
type InstanceBackupListOptions struct {
options.BaseListOptions
OrderByGuest string
}
func (opts *InstanceBackupListOptions) Params() (jsonutils.JSONObject, error) {
+1
View File
@@ -26,6 +26,7 @@ type ElasticipListOptions struct {
Usable *bool `help:"List all zones that is usable"`
UsableEipForAssociateType string `help:"With associate id filter which eip can associate" choices:"server|natgateway|loadbalancer"`
UsableEipForAssociateId string `help:"With associate type filter which eip can associate"`
OrderByIp string
options.BaseListOptions
}
@@ -22,6 +22,8 @@ import (
type GlobalVpcListOptions struct {
options.BaseListOptions
OrderByVpcCount string
}
func (opts *GlobalVpcListOptions) Params() (jsonutils.JSONObject, error) {
@@ -25,10 +25,12 @@ import (
type InstanceGroupListOptions struct {
options.BaseListOptions
ServiceType string `help:"Service Type"`
ParentId string `help:"Parent ID"`
ZoneId string `help:"Zone ID"`
Server string `help:"Guest ID or Name"`
ServiceType string `help:"Service Type"`
ParentId string `help:"Parent ID"`
ZoneId string `help:"Zone ID"`
Server string `help:"Guest ID or Name"`
OrderByVips string
OrderByGuestCount string
}
func (opts *InstanceGroupListOptions) Params() (jsonutils.JSONObject, error) {
@@ -32,7 +32,9 @@ func (o *NetTapServiceCreateOptions) Params() (jsonutils.JSONObject, error) {
type NetTapServiceListOptions struct {
options.BaseListOptions
HostId string `json:"host_id" help:"Filter by host id or name"`
HostId string `json:"host_id" help:"Filter by host id or name"`
OrderByIp string
OrderByFlowCount string
}
func (o *NetTapServiceListOptions) Params() (jsonutils.JSONObject, error) {
+3
View File
@@ -50,6 +50,9 @@ type NetworkListOptions struct {
BgpType []string `help:"filter by bgp_type"`
HostType string `help:"filter by host_type"`
RouteTableId string `help:"Filter by RouteTable"`
OrderByIpStart string
OrderByIpEnd string
}
func (opts *NetworkListOptions) GetContextId() string {
@@ -18,6 +18,8 @@ import "yunion.io/x/jsonutils"
type InterVpcNetworkListOPtions struct {
BaseListOptions
OrderByVpcCount string
}
func (opts *InterVpcNetworkListOPtions) Params() (jsonutils.JSONObject, error) {
+12 -11
View File
@@ -18,17 +18,18 @@ import "yunion.io/x/jsonutils"
type ServerSkusListOptions struct {
BaseListOptions
Cloudregion string `help:"region Id or name"`
Usable bool `help:"Filter usable sku"`
Zone string `help:"zone Id or name"`
City *string `help:"city name,eg. BeiJing"`
Cpu *int `help:"Cpu core count" json:"cpu_core_count"`
Mem *int `help:"Memory size in MB" json:"memory_size_mb"`
Name string `help:"Name of Sku"`
PostpaidStatus string `help:"Postpaid status" choices:"soldout|available"`
PrepaidStatus string `help:"Prepaid status" choices:"soldout|available"`
Enabled *bool `help:"Filter enabled skus"`
Distinct bool `help:"distinct sku by name"`
Cloudregion string `help:"region Id or name"`
Usable bool `help:"Filter usable sku"`
Zone string `help:"zone Id or name"`
City *string `help:"city name,eg. BeiJing"`
Cpu *int `help:"Cpu core count" json:"cpu_core_count"`
Mem *int `help:"Memory size in MB" json:"memory_size_mb"`
Name string `help:"Name of Sku"`
PostpaidStatus string `help:"Postpaid status" choices:"soldout|available"`
PrepaidStatus string `help:"Prepaid status" choices:"soldout|available"`
Enabled *bool `help:"Filter enabled skus"`
Distinct bool `help:"distinct sku by name"`
OrderByTotalGuestCount string
}
func (opts *ServerSkusListOptions) GetId() string {
+1
View File
@@ -31,6 +31,7 @@ type VpcListOptions struct {
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"`
OrderByWireCount string
}
func (opts *VpcListOptions) GetContextId() string {
+2
View File
@@ -26,6 +26,8 @@ type WireListOptions struct {
Vpc string `help:"List wires in vpc"`
Host string `help:"List wires attached to a host"`
HostType string `help:"List wires attached to host with HostType"`
OrderByNetworkCount string
}
func (wo *WireListOptions) GetContextId() string {