mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix: fix region list fitlers, round 1
This commit is contained in:
@@ -100,4 +100,13 @@ type BucketListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
ManagedResourceListInput
|
||||
RegionalFilterListInput
|
||||
|
||||
// STORAGE_CLASS
|
||||
StorageClass string `json:"storage_class"`
|
||||
|
||||
// 位置
|
||||
Location string `json:"location"`
|
||||
|
||||
// ACL
|
||||
Acl string `json:"acl"`
|
||||
}
|
||||
|
||||
@@ -211,6 +211,15 @@ type CloudaccountListInput struct {
|
||||
ManagedResourceListInput
|
||||
|
||||
CapabilityListInput
|
||||
|
||||
// 同步状态
|
||||
SyncStatus []string `json:"sync_status"`
|
||||
|
||||
// 账号健康状态
|
||||
HealthStatus []string `json:"health_status"`
|
||||
|
||||
// 共享模式
|
||||
ShareMode []string `json:"share_mode"`
|
||||
}
|
||||
|
||||
type ProviderProject struct {
|
||||
|
||||
@@ -215,6 +215,12 @@ type CloudproviderListInput struct {
|
||||
UsableResourceListInput
|
||||
|
||||
CapabilityListInput
|
||||
|
||||
// 同步状态
|
||||
SyncStatus []string `json:"sync_status"`
|
||||
|
||||
// 账号健康状态
|
||||
HealthStatus []string `json:"health_status"`
|
||||
}
|
||||
|
||||
func (input *CapabilityListInput) AfterUnmarshal() {
|
||||
|
||||
@@ -167,8 +167,23 @@ type DBInstanceListInput struct {
|
||||
|
||||
VpcFilterListInput
|
||||
|
||||
// 以可用区过滤数据库实例
|
||||
Zone string `json:"zone"`
|
||||
ZoneResourceInput
|
||||
|
||||
MasterInstance string `json:"master_instance"`
|
||||
|
||||
VcpuCount int `json:"vcpu_count"`
|
||||
|
||||
VmemSizeMb int `json:"vmem_size_mb"`
|
||||
|
||||
StorageType string `json:"storage_type"`
|
||||
|
||||
Category string `json:"category"`
|
||||
|
||||
Engine string `json:"engine"`
|
||||
|
||||
EngineVersion string `json:"engine_version"`
|
||||
|
||||
InstanceType string `json:"instance_type"`
|
||||
}
|
||||
|
||||
type DBInstanceBackupListInput struct {
|
||||
@@ -177,6 +192,20 @@ type DBInstanceBackupListInput struct {
|
||||
RegionalFilterListInput
|
||||
|
||||
DBInstanceFilterListInputBase
|
||||
|
||||
// RDS引擎
|
||||
// example: MySQL
|
||||
Engine string `json:"engine"`
|
||||
|
||||
// RDS引擎版本
|
||||
// example: 5.7
|
||||
EngineVersion string `json:"engine_version"`
|
||||
|
||||
// 备份模式
|
||||
BackupMode string `json:"backup_mode"`
|
||||
|
||||
// 数据库名称
|
||||
DBNames string `json:"db_names"`
|
||||
}
|
||||
|
||||
type DBInstancePrivilegeListInput struct {
|
||||
@@ -186,18 +215,30 @@ type DBInstancePrivilegeListInput struct {
|
||||
Dbinstanceaccount string `json:"dbinstanceaccount"`
|
||||
// filter by dbinstancedatabase
|
||||
Dbinstancedatabase string `json:"dbinstancedatabase"`
|
||||
|
||||
// 权限
|
||||
Privilege string `json:"privilege"`
|
||||
}
|
||||
|
||||
type DBInstanceParameterListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
DBInstanceFilterListInput
|
||||
|
||||
// 参数名称
|
||||
Key []string `json:"key"`
|
||||
|
||||
// 参数值
|
||||
Value []string `json:"value"`
|
||||
}
|
||||
|
||||
type DBInstanceDatabaseListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
DBInstanceFilterListInput
|
||||
|
||||
// 数据库字符集
|
||||
CharacterSet []string `json:"character_set"`
|
||||
}
|
||||
|
||||
type DBInstanceAccountListInput struct {
|
||||
|
||||
@@ -118,6 +118,26 @@ type DiskListInput struct {
|
||||
// | volume | 容器volumn盘 |
|
||||
//
|
||||
DiskType string `json:"disk_type"`
|
||||
|
||||
DiskFormat string `json:"disk_format"`
|
||||
|
||||
DiskSize int `json:"disk_size"`
|
||||
|
||||
AutoDelete *bool `json:"auto_delete"`
|
||||
|
||||
FsFormat string `json:"fs_format"`
|
||||
|
||||
// 镜像
|
||||
Template string `json:"template"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
TemplateId string `json:"template_id" deprecated-by:"template"`
|
||||
|
||||
// 快照
|
||||
Snapshot string `json:"snapshot"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
SnapshotId string `json:"snapshot_id" deprecated-by:"snapshot"`
|
||||
}
|
||||
|
||||
type DiskFilterListInput struct {
|
||||
|
||||
@@ -111,28 +111,96 @@ type ElasticcacheListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
VpcFilterListInput
|
||||
ZonalFilterListBase
|
||||
|
||||
// 实例规格
|
||||
// example: redis.master.micro.default
|
||||
InstanceType []string `json:"instance_type"`
|
||||
|
||||
// 对应Sku
|
||||
LocalCategory []string `json:"local_category"`
|
||||
|
||||
// 类型
|
||||
// single(单副本) | double(双副本) | readone (单可读) | readthree (3可读) | readfive(5只读)
|
||||
NodeType []string `json:"node_type"`
|
||||
|
||||
// 后端存储引擎
|
||||
// Redis | Memcache
|
||||
// example: redis
|
||||
Engine []string `json:"engine"`
|
||||
|
||||
// 后端存储引擎版本
|
||||
// example: 4.0
|
||||
EngineVersion []string `json:"engine_version"`
|
||||
|
||||
// 网络类型, CLASSIC(经典网络) VPC(专有网络)
|
||||
// example: CLASSIC
|
||||
NetworkType []string `json:"network_type"`
|
||||
|
||||
NetworkFilterListBase
|
||||
|
||||
// 内网DNS
|
||||
PrivateDNS []string `json:"private_dns"`
|
||||
|
||||
// 内网IP地址
|
||||
PrivateIpAddr []string `json:"private_ip_addr"`
|
||||
|
||||
// 内网访问端口
|
||||
PrivateConnectPort []int `json:"private_connect_port"`
|
||||
|
||||
// 公网DNS
|
||||
PublicDNS []string `json:"public_dns"`
|
||||
|
||||
// 公网IP地址
|
||||
PublicIpAddr []string `json:"public_ip_addr"`
|
||||
|
||||
// 外网访问端口
|
||||
PublicConnectPort []int `json:"public_connect_port"`
|
||||
|
||||
// 访问密码? on (开启密码)|off (免密码访问)
|
||||
AuthMode []string `json:"auth_mode"`
|
||||
}
|
||||
|
||||
type ElasticcacheAccountListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
ElasticcacheFilterListInput
|
||||
|
||||
// 账号类型 normal |admin
|
||||
AccountType []string `json:"account_type"`
|
||||
|
||||
// 账号权限 read | write | repl(复制, 复制权限支持读写,且开放SYNC/PSYNC命令)
|
||||
AccountPrivilege []string `json:"account_privilege"`
|
||||
}
|
||||
|
||||
type ElasticcacheAclListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
ElasticcacheFilterListInput
|
||||
|
||||
// Ip地址白名单列表
|
||||
IpList string `json:"ip_list"`
|
||||
}
|
||||
|
||||
type ElasticcacheBackupListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
ElasticcacheFilterListInput
|
||||
|
||||
// 备份类型, 全量|增量额
|
||||
BackupType []string `json:"backup_type"`
|
||||
|
||||
// 备份模式,自动|手动
|
||||
BackupMode []string `json:"backup_mode"`
|
||||
}
|
||||
|
||||
type ElasticcacheParameterListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
ElasticcacheFilterListInput
|
||||
|
||||
// 参数名称
|
||||
Key []string `json:"key"`
|
||||
|
||||
// 参数值
|
||||
Value []string `json:"value"`
|
||||
}
|
||||
|
||||
@@ -64,4 +64,34 @@ type ElasticipListInput struct {
|
||||
UsableEipForAssociateType string `json:"usable_eip_for_associate_type"`
|
||||
// filter usable eip for given associate id
|
||||
UsableEipForAssociateId string `json:"usable_eip_for_associate_id"`
|
||||
|
||||
NetworkFilterListBase
|
||||
|
||||
// 标识弹性或非弹性
|
||||
// | Mode | 说明 |
|
||||
// |------------|------------|
|
||||
// | public_ip | 公网IP |
|
||||
// | elastic_ip | 弹性公公网网IP |
|
||||
//
|
||||
// example: elastic_ip
|
||||
Mode string `json:"mode"`
|
||||
|
||||
// IP地址
|
||||
IpAddr string `json:"ip_addr"`
|
||||
|
||||
// 绑定资源类型
|
||||
AssociateType string `json:"associate_type"`
|
||||
|
||||
// 绑定资源Id
|
||||
AssociateId string `json:"associate_id"`
|
||||
|
||||
// 计费类型: 流量、带宽
|
||||
// example: bandwidth
|
||||
ChargeType []string `json:"charge_type"`
|
||||
|
||||
// 目前只有华为云此字段是必需填写的
|
||||
BgpType []string `json:"bgp_type"`
|
||||
|
||||
// 是否跟随主机删除而自动释放
|
||||
AutoDellocate *bool `json:"auto_dellocate"`
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ type CloudregionListInput struct {
|
||||
City string `json:"city"`
|
||||
// 过滤提供特定服务的区域
|
||||
Service string `json:"service"`
|
||||
|
||||
// 云环境
|
||||
Environment string `json:"environment"`
|
||||
}
|
||||
|
||||
type ZoneListInput struct {
|
||||
|
||||
@@ -38,3 +38,15 @@ type GuestDiskDetails struct {
|
||||
// example: ssd
|
||||
MediumType string `json:"medium_type"`
|
||||
}
|
||||
|
||||
type GuestdiskListInput struct {
|
||||
GuestJointsListInput
|
||||
|
||||
DiskFilterListInput
|
||||
|
||||
Driver []string `json:"driver"`
|
||||
|
||||
CacheMode []string `json:"cache_mode"`
|
||||
|
||||
AioMode []string `json:"aio_mode"`
|
||||
}
|
||||
|
||||
@@ -35,3 +35,21 @@ type GuestnetworkShortDesc struct {
|
||||
// Bonding的配对网卡MAC
|
||||
TeamWith string `json:"team_with"`
|
||||
}
|
||||
|
||||
type GuestnetworkListInput struct {
|
||||
GuestJointsListInput
|
||||
|
||||
NetworkFilterListInput
|
||||
|
||||
MacAddr []string `json:"mac_addr"`
|
||||
|
||||
IpAddr []string `json:"ip_addr"`
|
||||
|
||||
Ip6Addr []string `json:"ip6_addr"`
|
||||
|
||||
Driver []string `json:"driver"`
|
||||
|
||||
Ifname []string `json:"ifname"`
|
||||
|
||||
TeamWith []string `json:"team_with"`
|
||||
}
|
||||
|
||||
@@ -68,11 +68,11 @@ type ServerListInput struct {
|
||||
WithoutEip *bool `json:"without_eip"`
|
||||
// 列出操作系统为指定值的主机
|
||||
// enum: linux,windows,vmware
|
||||
OsType string `json:"os_type"`
|
||||
OsType []string `json:"os_type"`
|
||||
|
||||
// 对列表结果按照磁盘进行排序
|
||||
// enum: asc,desc
|
||||
OrderByDisk string `json:"order_by_disk"`
|
||||
// OrderByDisk string `json:"order_by_disk"`
|
||||
|
||||
// 列出可以挂载指定EIP的主机
|
||||
UsableServerForEip string `json:"usable_server_for_eip"`
|
||||
@@ -85,6 +85,26 @@ type ServerListInput struct {
|
||||
|
||||
// 根据宿主机 SN 过滤
|
||||
// HostSn string `json:"host_sn"`
|
||||
|
||||
VcpuCount []int `json:"vcpu_count"`
|
||||
|
||||
VmemSize []int `json:"vmem_size"`
|
||||
|
||||
BootOrder []string `json:"boot_order"`
|
||||
|
||||
Vga []string `json:"vga"`
|
||||
|
||||
Vdi []string `json:"vdi"`
|
||||
|
||||
Machine []string `json:"machine"`
|
||||
|
||||
Bios []string `json:"bios"`
|
||||
|
||||
SrcIpCheck *bool `json:"src_ip_check"`
|
||||
|
||||
SrcMacCheck *bool `json:"src_mac_check"`
|
||||
|
||||
InstanceType []string `json:"instance_type"`
|
||||
}
|
||||
|
||||
func (input *ServerListInput) AfterUnmarshal() {
|
||||
@@ -224,3 +244,42 @@ type GuestJointResourceDetails struct {
|
||||
// 云主机名称
|
||||
Server string `json:"server"`
|
||||
}
|
||||
|
||||
type GuestJointsListInput struct {
|
||||
apis.VirtualJointResourceBaseListInput
|
||||
|
||||
GuestFilterListInput
|
||||
}
|
||||
|
||||
type GuestResourceInfo struct {
|
||||
// 虚拟机名称
|
||||
Guest string `json:"guest"`
|
||||
|
||||
// 虚拟机状态
|
||||
GuestStatus string `json:"guest_status"`
|
||||
|
||||
// 宿主机ID
|
||||
HostId string `json:"host_id"`
|
||||
|
||||
HostResourceInfo
|
||||
}
|
||||
|
||||
type GuestFilterListInput struct {
|
||||
HostFilterListInput
|
||||
|
||||
// 以指定虚拟主机(ID或Name)过滤列表结果
|
||||
Server string `json:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
ServerId string `json:"server_id" deprecated-by:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
Guest string `json:"guest" deprecated-by:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
GuestId string `json:"guest_id" deprecated-by:"server"`
|
||||
|
||||
// 以虚拟主机名称排序
|
||||
// pattern:asc|desc
|
||||
OrderByServer string `json:"order_by_server"`
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ type CachedimageListInput struct {
|
||||
|
||||
ManagedResourceListInput
|
||||
ZonalFilterListInput
|
||||
|
||||
// 镜像类型,可能值为: system(公有云公共镜像), customized(自定义镜像)
|
||||
// example: system
|
||||
ImageType string `json:"image_type"`
|
||||
}
|
||||
|
||||
type ExternalProjectListInput struct {
|
||||
@@ -82,6 +86,13 @@ type NetworkInterfaceListInput struct {
|
||||
type BaremetalagentListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
ZonalFilterListInput
|
||||
|
||||
// 以状态过滤
|
||||
Status string `json:"status"`
|
||||
// 以IP地址过滤
|
||||
AccessIp string `json:"access_ip"`
|
||||
// 以AgentType过滤
|
||||
AgentType string `json:"agent_type"`
|
||||
}
|
||||
|
||||
type DnsRecordListInput struct {
|
||||
@@ -91,6 +102,9 @@ type DnsRecordListInput struct {
|
||||
type DynamicschedtagListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
SchedtagFilterListInput
|
||||
|
||||
// filter by enabled status
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type GuestTemplateListInput struct {
|
||||
|
||||
@@ -29,6 +29,9 @@ type InstanceGroupListInput struct {
|
||||
ServiceType string `json:"service_type"`
|
||||
// 以parent_id过滤列表结果
|
||||
ParentId string `json:"parent_id"`
|
||||
|
||||
// 调度策略
|
||||
SchedStrategy string `json:"sched_strategy"`
|
||||
}
|
||||
|
||||
type InstanceGroupDetail struct {
|
||||
|
||||
@@ -90,6 +90,34 @@ type ElasticcacheSkuListInput struct {
|
||||
|
||||
// filter sku by memory size in MB
|
||||
MemorySizeMb int `json:"memory_size_mb"`
|
||||
|
||||
InstanceSpec []string `json:"instance_spec"`
|
||||
|
||||
EngineArch []string `json:"engine_arch"`
|
||||
|
||||
LocalCategory []string `json:"local_category"`
|
||||
|
||||
PrepaidStatus []string `json:"prepaid_status"`
|
||||
|
||||
PostpaidStatus []string `json:"postpaid_sStatus"`
|
||||
|
||||
// 引擎 redis|memcached
|
||||
Engine []string `json:"engine"`
|
||||
|
||||
// 引擎版本 3.0
|
||||
EngineVersion []string `json:"engine_version"`
|
||||
|
||||
// CPU 架构 x86|ARM
|
||||
CpuArch []string `json:"cpu_arch"`
|
||||
|
||||
// 存储类型 DRAM|SCM
|
||||
StorageType []string `json:"storage_type"`
|
||||
|
||||
// standrad|enhanced
|
||||
PerformanceType []string `json:"performance_type"`
|
||||
|
||||
// single(单副本) | double(双副本) | readone (单可读) | readthree (3可读) | readfive(5只读)
|
||||
NodeType []string `json:"node_type"`
|
||||
}
|
||||
|
||||
type DBInstanceSkuListInput struct {
|
||||
@@ -100,4 +128,17 @@ type DBInstanceSkuListInput struct {
|
||||
|
||||
RegionalFilterListInput
|
||||
billing.BillingResourceListInput
|
||||
|
||||
// StorageType
|
||||
StorageType string `json:"storage_type"`
|
||||
|
||||
VcpuCount int `json:"vcpu_count"`
|
||||
|
||||
VmemSizeMb int `json:"vmem_size_mb"`
|
||||
|
||||
Category string `json:"category"`
|
||||
|
||||
Engine string `json:"engine"`
|
||||
|
||||
EngineVersion string `json:"engine_version"`
|
||||
}
|
||||
|
||||
@@ -214,3 +214,11 @@ type EnabledStatusDomainLevelResourceListInput struct {
|
||||
StatusDomainLevelResourceListInput
|
||||
EnabledResourceBaseListInput
|
||||
}
|
||||
|
||||
type JointResourceBaseListInput struct {
|
||||
ResourceBaseListInput
|
||||
}
|
||||
|
||||
type VirtualJointResourceBaseListInput struct {
|
||||
JointResourceBaseListInput
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/reflectutils"
|
||||
@@ -256,3 +257,35 @@ func (manager *SJointResourceBaseManager) FetchCustomizeColumns(
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (manager *SJointResourceBaseManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query apis.JointResourceBaseListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SJointResourceBaseManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query apis.JointResourceBaseListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.ResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package db
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/util/reflectutils"
|
||||
@@ -147,3 +148,35 @@ func (manager *SVirtualJointResourceBaseManager) FetchCustomizeColumns(
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (manager *SVirtualJointResourceBaseManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query apis.VirtualJointResourceBaseListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SJointResourceBaseManager.ListItemFilter(ctx, q, userCred, query.JointResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SJointResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SVirtualJointResourceBaseManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query apis.VirtualJointResourceBaseListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SJointResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.JointResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SJointResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
@@ -278,6 +278,15 @@ func (manager *SBaremetalagentManager) ListItemFilter(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SZoneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
if len(query.Status) > 0 {
|
||||
q = q.Equals("status", query.Status)
|
||||
}
|
||||
if len(query.AccessIp) > 0 {
|
||||
q = q.Equals("access_ip", query.AccessIp)
|
||||
}
|
||||
if len(query.AgentType) > 0 {
|
||||
q = q.Equals("agent_type", query.AgentType)
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -588,7 +588,12 @@ func (bucket *SBucket) getCloudProviderInfo() SCloudProviderInfo {
|
||||
}
|
||||
|
||||
// 对象存储的存储桶列表
|
||||
func (manager *SBucketManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.BucketListInput) (*sqlchemy.SQuery, error) {
|
||||
func (manager *SBucketManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.BucketListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SCloudregionResourceBaseManager.ListItemFilter(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
@@ -606,6 +611,16 @@ func (manager *SBucketManager) ListItemFilter(ctx context.Context, q *sqlchemy.S
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.StorageClass) > 0 {
|
||||
q = q.Equals("storage_class", query.StorageClass)
|
||||
}
|
||||
if len(query.Location) > 0 {
|
||||
q = q.Equals("location", query.Location)
|
||||
}
|
||||
if len(query.Acl) > 0 {
|
||||
q = q.Equals("acl", query.Acl)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -626,7 +641,12 @@ func (manager *SBucketManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
func (manager *SBucketManager) OrderByExtraFields(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.BucketListInput) (*sqlchemy.SQuery, error) {
|
||||
func (manager *SBucketManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.BucketListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
|
||||
@@ -674,6 +674,10 @@ func (manager *SCachedimageManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
|
||||
if len(query.ImageType) > 0 {
|
||||
q = q.Equals("image_type", query.ImageType)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1235,6 +1235,22 @@ func (manager *SCloudaccountManager) ListItemFilter(
|
||||
q = q.In("id", subq.SubQuery())
|
||||
}
|
||||
|
||||
if len(query.SyncStatus) > 0 {
|
||||
q = q.In("sync_status", query.SyncStatus)
|
||||
}
|
||||
if len(query.HealthStatus) > 0 {
|
||||
q = q.In("health_status", query.HealthStatus)
|
||||
}
|
||||
if len(query.ShareMode) > 0 {
|
||||
q = q.In("share_mode", query.ShareMode)
|
||||
}
|
||||
if len(query.Providers) > 0 {
|
||||
q = q.In("provider", query.Providers)
|
||||
}
|
||||
if len(query.Brands) > 0 {
|
||||
q = q.In("brand", query.Brands)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1063,6 +1063,21 @@ func (manager *SCloudproviderManager) ListItemFilter(
|
||||
q = q.In("id", subq)
|
||||
}
|
||||
|
||||
if len(query.SyncStatus) > 0 {
|
||||
q = q.In("sync_status", query.SyncStatus)
|
||||
}
|
||||
if len(query.HealthStatus) > 0 {
|
||||
q = q.In("health_status", query.HealthStatus)
|
||||
}
|
||||
if len(query.Providers) > 0 {
|
||||
subq := CloudaccountManager.Query("id").In("provider", query.Providers).SubQuery()
|
||||
q = q.In("cloudaccount_id", subq)
|
||||
}
|
||||
if len(query.Brands) > 0 {
|
||||
subq := CloudaccountManager.Query("id").In("brand", query.Brands).SubQuery()
|
||||
q = q.In("cloudaccount_id", subq)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -751,6 +751,11 @@ func (manager *SCloudregionManager) ListItemFilter(
|
||||
} else if len(cityStr) > 0 {
|
||||
q = q.Equals("city", cityStr)
|
||||
}
|
||||
|
||||
if len(query.Environment) > 0 {
|
||||
q = q.Equals("environment", query.Environment)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,19 @@ func (manager *SDBInstanceBackupManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SDBInstanceResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.Engine) > 0 {
|
||||
q = q.Equals("engine", query.Engine)
|
||||
}
|
||||
if len(query.EngineVersion) > 0 {
|
||||
q = q.Equals("engine_version", query.EngineVersion)
|
||||
}
|
||||
if len(query.BackupMode) > 0 {
|
||||
q = q.Equals("backup_mode", query.BackupMode)
|
||||
}
|
||||
if len(query.DBNames) > 0 {
|
||||
q = q.Contains("db_names", query.DBNames)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,11 @@ func (manager *SDBInstanceDatabaseManager) ListItemFilter(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SDBInstanceResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.CharacterSet) > 0 {
|
||||
q = q.In("character_set", query.CharacterSet)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,14 @@ func (manager *SDBInstanceParameterManager) ListItemFilter(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SDBInstanceResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.Key) > 0 {
|
||||
q = q.In("key", query.Key)
|
||||
}
|
||||
if len(query.Value) > 0 {
|
||||
q = q.In("value", query.Value)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -104,11 +104,21 @@ func (self *SDBInstancePrivilege) GetPrivilege() (api.DBInstancePrivilege, error
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (manager *SDBInstancePrivilegeManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstancePrivilegeListInput) (*sqlchemy.SQuery, error) {
|
||||
func (manager *SDBInstancePrivilegeManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.DBInstancePrivilegeListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.Privilege) > 0 {
|
||||
q = q.Equals("privilege", query.Privilege)
|
||||
}
|
||||
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "dbinstanceaccount", ModelKeyword: "dbinstanceaccount", OwnerId: userCred},
|
||||
|
||||
@@ -138,6 +138,26 @@ func (manager *SDBInstanceSkuManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
// StorageType
|
||||
if len(query.StorageType) > 0 {
|
||||
q = q.Equals("storage_type", query.StorageType)
|
||||
}
|
||||
if query.VcpuCount > 0 {
|
||||
q = q.Equals("vcpu_count", query.VcpuCount)
|
||||
}
|
||||
if query.VmemSizeMb > 0 {
|
||||
q = q.Equals("vmem_size_mb", query.VmemSizeMb)
|
||||
}
|
||||
if len(query.Category) > 0 {
|
||||
q = q.Equals("category", query.Category)
|
||||
}
|
||||
if len(query.Engine) > 0 {
|
||||
q = q.Equals("engine", query.Engine)
|
||||
}
|
||||
if len(query.EngineVersion) > 0 {
|
||||
q = q.Equals("engine_version", query.EngineVersion)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,39 @@ func (man *SDBInstanceManager) ListItemFilter(
|
||||
))
|
||||
}
|
||||
|
||||
if len(query.MasterInstance) > 0 {
|
||||
instObj, err := DBInstanceManager.FetchByIdOrName(userCred, query.MasterInstance)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(DBInstanceManager.Keyword(), query.MasterInstance)
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "DBInstanceManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
q = q.Equals("master_instance_id", instObj.GetId())
|
||||
}
|
||||
if query.VcpuCount > 0 {
|
||||
q = q.Equals("vcpu_count", query.VcpuCount)
|
||||
}
|
||||
if query.VmemSizeMb > 0 {
|
||||
q = q.Equals("vmem_size_mb", query.VmemSizeMb)
|
||||
}
|
||||
if len(query.StorageType) > 0 {
|
||||
q = q.Equals("storage_type", query.StorageType)
|
||||
}
|
||||
if len(query.Category) > 0 {
|
||||
q = q.Equals("category", query.Category)
|
||||
}
|
||||
if len(query.Engine) > 0 {
|
||||
q = q.Equals("engine", query.Engine)
|
||||
}
|
||||
if len(query.EngineVersion) > 0 {
|
||||
q = q.Equals("engine_version", query.EngineVersion)
|
||||
}
|
||||
if len(query.InstanceType) > 0 {
|
||||
q = q.Equals("instance_type", query.InstanceType)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,48 @@ func (manager *SDiskManager) ListItemFilter(
|
||||
sq := SnapshotPolicyDiskManager.Query("disk_id").Equals("snapshotpolicy_id", snapshotpolicyId)
|
||||
q = q.In("id", sq)
|
||||
}
|
||||
|
||||
|
||||
if len(query.DiskFormat) > 0 {
|
||||
q = q.Equals("disk_format", query.DiskFormat)
|
||||
}
|
||||
|
||||
if query.DiskSize > 0 {
|
||||
q = q.Equals("disk_size", query.DiskSize)
|
||||
}
|
||||
|
||||
if query.AutoDelete != nil {
|
||||
if *query.AutoDelete {
|
||||
q = q.IsTrue("auto_delete")
|
||||
} else {
|
||||
q = q.IsFalse("auto_delete")
|
||||
}
|
||||
}
|
||||
|
||||
if len(query.FsFormat) > 0 {
|
||||
q = q.Equals("fs_format", query.FsFormat)
|
||||
}
|
||||
|
||||
if len(query.Template) > 0 {
|
||||
img, err := CachedimageManager.getImageInfo(ctx, userCred, query.Template, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CachedimageManager.getImageInfo")
|
||||
}
|
||||
q = q.Equals("template_id", img.Id)
|
||||
}
|
||||
|
||||
if len(query.Snapshot) > 0 {
|
||||
snapObj, err := SnapshotManager.FetchByIdOrName(userCred, query.Snapshot)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(SnapshotManager.Keyword(), query.Snapshot)
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "SnapshotManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
q = q.Equals("snapshot_id", snapObj.GetId())
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -307,6 +307,14 @@ func (manager *SDynamicschedtagManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SSchedtagResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if input.Enabled != nil {
|
||||
if *input.Enabled {
|
||||
q = q.IsTrue("enabled")
|
||||
} else {
|
||||
q = q.IsFalse("enabled")
|
||||
}
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -467,6 +467,14 @@ func (manager *SElasticcacheAccountManager) ListItemFilter(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SElasticcacheResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(input.AccountType) > 0 {
|
||||
q = q.In("account_type", input.AccountType)
|
||||
}
|
||||
if len(input.AccountPrivilege) > 0 {
|
||||
q = q.In("account_privilege", input.AccountPrivilege)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -348,6 +348,10 @@ func (manager *SElasticcacheAclManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SElasticcacheResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(input.IpList) > 0 {
|
||||
q = q.Contains("ip_list", input.IpList)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -360,6 +360,13 @@ func (manager *SElasticcacheBackupManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SElasticcacheResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(input.BackupType) > 0 {
|
||||
q = q.In("backup_type", input.BackupType)
|
||||
}
|
||||
if len(input.BackupMode) > 0 {
|
||||
q = q.In("backup_mode", input.BackupMode)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ type SElasticcacheManager struct {
|
||||
db.SVirtualResourceBaseManager
|
||||
SVpcResourceBaseManager
|
||||
SZoneResourceBaseManager
|
||||
SNetworkResourceBaseManager
|
||||
}
|
||||
|
||||
var ElasticcacheManager *SElasticcacheManager
|
||||
@@ -326,6 +327,54 @@ func (manager *SElasticcacheManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SZoneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.InstanceType) > 0 {
|
||||
q = q.In("instance_type", query.InstanceType)
|
||||
}
|
||||
if len(query.LocalCategory) > 0 {
|
||||
q = q.In("local_category", query.LocalCategory)
|
||||
}
|
||||
if len(query.NodeType) > 0 {
|
||||
q = q.In("node_type", query.NodeType)
|
||||
}
|
||||
if len(query.Engine) > 0 {
|
||||
q = q.In("engine", query.Engine)
|
||||
}
|
||||
if len(query.EngineVersion) > 0 {
|
||||
q = q.In("engine_version", query.EngineVersion)
|
||||
}
|
||||
if len(query.NetworkType) > 0 {
|
||||
q = q.In("network_type", query.NetworkType)
|
||||
}
|
||||
netQuery := api.NetworkFilterListInput {
|
||||
NetworkFilterListBase: query.NetworkFilterListBase,
|
||||
}
|
||||
q, err = manager.SNetworkResourceBaseManager.ListItemFilter(ctx, q, userCred, netQuery)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SNetworkResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.PrivateDNS) > 0 {
|
||||
q = q.In("private_dns", query.PrivateDNS)
|
||||
}
|
||||
if len(query.PrivateIpAddr) > 0 {
|
||||
q = q.In("private_ip_addr", query.PrivateIpAddr)
|
||||
}
|
||||
if len(query.PrivateConnectPort) > 0 {
|
||||
q = q.In("private_connect_port", query.PrivateConnectPort)
|
||||
}
|
||||
if len(query.PublicDNS) > 0 {
|
||||
q = q.In("public_dns", query.PublicDNS)
|
||||
}
|
||||
if len(query.PublicIpAddr) > 0 {
|
||||
q = q.In("public_ip_addr", query.PublicIpAddr)
|
||||
}
|
||||
if len(query.PublicConnectPort) > 0 {
|
||||
q = q.In("public_connect_port", query.PublicConnectPort)
|
||||
}
|
||||
if len(query.AuthMode) > 0 {
|
||||
q = q.In("auth_mode", query.AuthMode)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -267,6 +267,13 @@ func (manager *SElasticcacheParameterManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SElasticcacheResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(input.Key) > 0 {
|
||||
q = q.In("key", input.Key)
|
||||
}
|
||||
if len(input.Value) > 0 {
|
||||
q = q.In("value", input.Value)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -72,27 +72,45 @@ type SElasticcacheSku struct {
|
||||
PrepaidStatus string `width:"32" charset:"utf8" nullable:"false" list:"user" create:"admin_optional" update:"admin" default:"available"`
|
||||
PostpaidStatus string `width:"32" charset:"utf8" nullable:"false" list:"user" create:"admin_optional" update:"admin" default:"available"`
|
||||
|
||||
Engine string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 引擎 redis|memcached
|
||||
EngineVersion string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 引擎版本 3.0
|
||||
CpuArch string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // CPU 架构 x86|ARM
|
||||
StorageType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 存储类型 DRAM|SCM
|
||||
PerformanceType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // standrad|enhanced
|
||||
NodeType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"` // single(单副本) | double(双副本) | readone (单可读) | readthree (3可读) | readfive(5只读)
|
||||
// 引擎 redis|memcached
|
||||
Engine string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 引擎版本 3.0
|
||||
EngineVersion string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// CPU 架构 x86|ARM
|
||||
CpuArch string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 存储类型 DRAM|SCM
|
||||
StorageType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// standrad|enhanced
|
||||
PerformanceType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// single(单副本) | double(双副本) | readone (单可读) | readthree (3可读) | readfive(5只读)
|
||||
NodeType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
|
||||
MemorySizeMB int `nullable:"false" list:"user" create:"admin_required" update:"admin"` // 内存容量
|
||||
DiskSizeGB int `nullable:"false" list:"user" create:"admin_required" update:"admin"` // 套餐附带硬盘容量
|
||||
ShardNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 最小分片数量
|
||||
MaxShardNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 最大分片数量
|
||||
ReplicasNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 最小副本数量
|
||||
MaxReplicasNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 最大副本数量
|
||||
// 内存容量
|
||||
MemorySizeMB int `nullable:"false" list:"user" create:"admin_required" update:"admin"`
|
||||
// 套餐附带硬盘容量
|
||||
DiskSizeGB int `nullable:"false" list:"user" create:"admin_required" update:"admin"`
|
||||
// 最小分片数量
|
||||
ShardNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 最大分片数量
|
||||
MaxShardNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 最小副本数量
|
||||
ReplicasNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 最大副本数量
|
||||
MaxReplicasNum int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
|
||||
MaxClients int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 最大客户端数
|
||||
MaxConnections int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 最大连接数
|
||||
MaxInBandwidthMb int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 最大内网带宽
|
||||
MaxMemoryMB int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // 实际可使用的最大内存
|
||||
QPS int `nullable:"false" list:"user" create:"admin_optional" update:"admin"` // QPS参考值
|
||||
// 最大客户端数
|
||||
MaxClients int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 最大连接数
|
||||
MaxConnections int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 最大内网带宽
|
||||
MaxInBandwidthMb int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// 实际可使用的最大内存
|
||||
MaxMemoryMB int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
// QPS参考值
|
||||
QPS int `nullable:"false" list:"user" create:"admin_optional" update:"admin"`
|
||||
|
||||
Provider string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_required" update:"admin"` // 公有云厂商 Aliyun/Azure/AWS/Qcloud/...
|
||||
// 公有云厂商 Aliyun/Azure/AWS/Qcloud/...
|
||||
Provider string `width:"32" charset:"ascii" nullable:"false" list:"user" create:"admin_required" update:"admin"`
|
||||
}
|
||||
|
||||
func (self SElasticcacheSku) GetGlobalId() string {
|
||||
@@ -255,6 +273,44 @@ func (manager *SElasticcacheSkuManager) ListItemFilter(
|
||||
q.LE("memory_size_mb", e)
|
||||
}
|
||||
|
||||
if len(query.InstanceSpec) > 0 {
|
||||
q = q.In("instance_spec", query.InstanceSpec)
|
||||
}
|
||||
if len(query.EngineArch) > 0 {
|
||||
q = q.In("engine_arch", query.EngineArch)
|
||||
}
|
||||
if len(query.LocalCategory)> 0 {
|
||||
q = q.In("local_category", query.LocalCategory)
|
||||
}
|
||||
if len(query.PrepaidStatus) > 0 {
|
||||
q = q.In("prepaid_status", query.PrepaidStatus)
|
||||
}
|
||||
if len(query.PostpaidStatus) > 0 {
|
||||
q = q.In("postpaid_sStatus", query.PostpaidStatus)
|
||||
}
|
||||
if len(query.Engine) > 0 {
|
||||
q = q.In("engine", query.Engine)
|
||||
}
|
||||
if len(query.EngineVersion) > 0 {
|
||||
q = q.In("engine_version", query.EngineVersion)
|
||||
}
|
||||
if len(query.CpuArch) > 0 {
|
||||
q = q.In("cpu_arch", query.CpuArch)
|
||||
}
|
||||
if len(query.StorageType) > 0 {
|
||||
q = q.In("storage_type", query.StorageType)
|
||||
}
|
||||
if len(query.PerformanceType) > 0 {
|
||||
q = q.In("performance_type", query.PerformanceType)
|
||||
}
|
||||
if len(query.NodeType) > 0 {
|
||||
q = q.In("node_type", query.NodeType)
|
||||
}
|
||||
|
||||
if len(query.Providers) > 0 {
|
||||
q = q.In("provider", query.Providers)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,11 @@ type SElasticip struct {
|
||||
// IP子网Id, 仅私有云不为空
|
||||
NetworkId string `width:"36" charset:"ascii" nullable:"true" get:"user" list:"user" create:"optional"`
|
||||
// 标识弹性或非弹性
|
||||
// public_ip: 公网IP
|
||||
// elastic_ip: 弹性公网IP
|
||||
// | Mode | 说明 |
|
||||
// |------------|------------|
|
||||
// | public_ip | 公网IP |
|
||||
// | elastic_ip | 弹性公网IP |
|
||||
//
|
||||
// example: elastic_ip
|
||||
Mode string `width:"32" charset:"ascii" list:"user"`
|
||||
|
||||
@@ -164,6 +167,32 @@ func (manager *SElasticipManager) ListItemFilter(
|
||||
q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("associate_id")), sqlchemy.IsEmpty(q.Field("associate_id"))))
|
||||
}
|
||||
|
||||
if len(query.Mode) > 0 {
|
||||
q = q.In("mode", query.Mode)
|
||||
}
|
||||
if len(query.IpAddr) > 0 {
|
||||
q = q.In("ip_addr", query.IpAddr)
|
||||
}
|
||||
if len(query.AssociateType) > 0 {
|
||||
q = q.In("associate_type", query.AssociateType)
|
||||
}
|
||||
if len(query.AssociateId) > 0 {
|
||||
q = q.In("associate_id", query.AssociateId)
|
||||
}
|
||||
if len(query.ChargeType) > 0 {
|
||||
q = q.In("charge_type", query.ChargeType)
|
||||
}
|
||||
if len(query.BgpType) > 0 {
|
||||
q = q.In("bgp_type", query.BgpType)
|
||||
}
|
||||
if query.AutoDellocate != nil {
|
||||
if *query.AutoDellocate {
|
||||
q = q.IsTrue("auto_dellocate")
|
||||
} else {
|
||||
q = q.IsFalse("auto_dellocate")
|
||||
}
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,9 @@ func (sm *SGroupManager) ListItemFilter(
|
||||
if len(input.ServiceType) > 0 {
|
||||
q = q.Equals("service_type", input.ServiceType)
|
||||
}
|
||||
if len(input.SchedStrategy) > 0 {
|
||||
q = q.Equals("sched_strategy", input.SchedStrategy)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -31,6 +32,7 @@ import (
|
||||
|
||||
type SGuestdiskManager struct {
|
||||
SGuestJointsManager
|
||||
SDiskResourceBaseManager
|
||||
}
|
||||
|
||||
var GuestdiskManager *SGuestdiskManager
|
||||
@@ -55,6 +57,7 @@ func init() {
|
||||
type SGuestdisk struct {
|
||||
SGuestJointsBase
|
||||
|
||||
// SDiskResourceBase `list:"user" create:"required"`
|
||||
DiskId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required"` // Column(VARCHAR(36, charset='ascii'), nullable=False)
|
||||
|
||||
ImagePath string `width:"256" charset:"ascii" nullable:"false" get:"user" create:"required"` // Column(VARCHAR(256, charset='ascii'), nullable=False)
|
||||
@@ -322,3 +325,53 @@ func (self *SGuestdisk) ToDiskConfig() *api.DiskConfig {
|
||||
conf.Index = int(self.Index)
|
||||
return conf
|
||||
}
|
||||
|
||||
func (manager *SGuestdiskManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestdiskListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SGuestJointsManager.ListItemFilter(ctx, q, userCred, query.GuestJointsListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SGuestJointsManager.ListItemFilter")
|
||||
}
|
||||
q, err = manager.SDiskResourceBaseManager.ListItemFilter(ctx, q, userCred, query.DiskFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SDiskResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.Driver) > 0 {
|
||||
q = q.In("driver", query.Driver)
|
||||
}
|
||||
if len(query.CacheMode) > 0 {
|
||||
q = q.In("cache_mode", query.CacheMode)
|
||||
}
|
||||
if len(query.AioMode) > 0 {
|
||||
q = q.In("aio_mode", query.AioMode)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SGuestdiskManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestdiskListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SGuestJointsManager.OrderByExtraFields(ctx, q, userCred, query.GuestJointsListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SGuestJointsManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = manager.SDiskResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.DiskFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SDiskResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
@@ -16,6 +16,8 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -29,6 +31,7 @@ import (
|
||||
|
||||
type SGuestJointsManager struct {
|
||||
db.SVirtualJointResourceBaseManager
|
||||
SGuestResourceBaseManager
|
||||
}
|
||||
|
||||
func NewGuestJointsManager(dt interface{}, tableName string, keyword string, keywordPlural string, slave db.IVirtualModelManager) SGuestJointsManager {
|
||||
@@ -107,3 +110,43 @@ func (manager *SGuestJointsManager) FetchCustomizeColumns(
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
func (manager *SGuestJointsManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestJointsListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SVirtualJointResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualJointResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SVirtualJointResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = manager.SGuestResourceBaseManager.ListItemFilter(ctx, q, userCred, query.GuestFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SGuestResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SGuestJointsManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestJointsListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SVirtualJointResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.VirtualJointResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SVirtualJointResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = manager.SGuestResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.GuestFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SGuestResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
@@ -52,6 +52,7 @@ const (
|
||||
|
||||
type SGuestnetworkManager struct {
|
||||
SGuestJointsManager
|
||||
SNetworkResourceBaseManager
|
||||
}
|
||||
|
||||
var GuestnetworkManager *SGuestnetworkManager
|
||||
@@ -75,16 +76,26 @@ func init() {
|
||||
type SGuestnetwork struct {
|
||||
SGuestJointsBase
|
||||
|
||||
NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"user" ` // Column(VARCHAR(36, charset='ascii'), nullable=False)
|
||||
MacAddr string `width:"32" charset:"ascii" nullable:"false" list:"user"` // Column(VARCHAR(32, charset='ascii'), nullable=False)
|
||||
IpAddr string `width:"16" charset:"ascii" nullable:"false" list:"user"` // Column(VARCHAR(16, charset='ascii'), nullable=True)
|
||||
Ip6Addr string `width:"64" charset:"ascii" nullable:"true" list:"user"` // Column(VARCHAR(64, charset='ascii'), nullable=True)
|
||||
Driver string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user"` // Column(VARCHAR(16, charset='ascii'), nullable=True)
|
||||
BwLimit int `nullable:"false" default:"0" list:"user"` // Column(Integer, nullable=False, default=0) # Mbps
|
||||
Index int8 `nullable:"false" default:"0" list:"user" update:"user"` // Column(TINYINT, nullable=False, default=0)
|
||||
Virtual bool `default:"false" list:"user"` // Column(Boolean, default=False)
|
||||
Ifname string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user"` // Column(VARCHAR(16, charset='ascii'), nullable=True)
|
||||
NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"user" `
|
||||
|
||||
// MAC地址
|
||||
MacAddr string `width:"32" charset:"ascii" nullable:"false" list:"user"`
|
||||
// IPv4地址
|
||||
IpAddr string `width:"16" charset:"ascii" nullable:"false" list:"user"`
|
||||
// IPv6地址
|
||||
Ip6Addr string `width:"64" charset:"ascii" nullable:"true" list:"user"`
|
||||
// 虚拟网卡驱动
|
||||
Driver string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user"`
|
||||
// 带宽限制,单位mbps
|
||||
BwLimit int `nullable:"false" default:"0" list:"user"`
|
||||
// 网卡序号
|
||||
Index int8 `nullable:"false" default:"0" list:"user" update:"user"`
|
||||
// 是否为虚拟接口(无IP)
|
||||
Virtual bool `default:"false" list:"user"`
|
||||
// 虚拟网卡设备名称
|
||||
Ifname string `width:"16" charset:"ascii" nullable:"true" list:"user" update:"user"`
|
||||
|
||||
// bind配对网卡MAC地址
|
||||
TeamWith string `width:"32" charset:"ascii" nullable:"false" list:"user"`
|
||||
}
|
||||
|
||||
@@ -833,3 +844,62 @@ func (self *SGuestnetwork) ToNetworkConfig() *api.NetworkConfig {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (manager *SGuestnetworkManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestnetworkListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SGuestJointsManager.ListItemFilter(ctx, q, userCred, query.GuestJointsListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SGuestJointsManager.ListItemFilter")
|
||||
}
|
||||
q, err = manager.SNetworkResourceBaseManager.ListItemFilter(ctx, q, userCred, query.NetworkFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SNetworkResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(query.MacAddr) > 0 {
|
||||
q = q.In("mac_addr", query.MacAddr)
|
||||
}
|
||||
if len(query.IpAddr) > 0 {
|
||||
q = q.In("ip_addr", query.IpAddr)
|
||||
}
|
||||
if len(query.Ip6Addr) > 0 {
|
||||
q = q.In("ip6_addr", query.Ip6Addr)
|
||||
}
|
||||
if len(query.Driver) > 0 {
|
||||
q = q.In("driver", query.Driver)
|
||||
}
|
||||
if len(query.Ifname) > 0 {
|
||||
q = q.In("ifname", query.Ifname)
|
||||
}
|
||||
if len(query.TeamWith) > 0 {
|
||||
q = q.In("team_with", query.TeamWith)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SGuestnetworkManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestnetworkListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SGuestJointsManager.OrderByExtraFields(ctx, q, userCred, query.GuestJointsListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SGuestJointsManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = manager.SNetworkResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.NetworkFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SNetworkResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/reflectutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
type SGuestResourceBase struct {
|
||||
GuestId string `width:"36" charset:"ascii" nullable:"true" list:"user" create:"optional"`
|
||||
}
|
||||
|
||||
type SGuestResourceBaseManager struct {
|
||||
SHostResourceBaseManager
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetGuest() *SGuest {
|
||||
obj, _ := GuestManager.FetchById(self.GuestId)
|
||||
if obj != nil {
|
||||
return obj.(*SGuest)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetHost() *SHost {
|
||||
guest := self.GetGuest()
|
||||
if guest != nil {
|
||||
return guest.GetHost()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetZone() *SZone {
|
||||
host := self.GetHost()
|
||||
if host != nil {
|
||||
return host.GetZone()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetRegion() *SCloudregion {
|
||||
host := self.GetHost()
|
||||
if host == nil {
|
||||
return nil
|
||||
}
|
||||
region := host.GetRegion()
|
||||
return region
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.GuestResourceInfo {
|
||||
return api.GuestResourceInfo{}
|
||||
}
|
||||
|
||||
func (manager *SGuestResourceBaseManager) FetchCustomizeColumns(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
objs []interface{},
|
||||
fields stringutils2.SSortedStrings,
|
||||
isList bool,
|
||||
) []api.GuestResourceInfo {
|
||||
rows := make([]api.GuestResourceInfo, len(objs))
|
||||
guestIds := make([]string, len(objs))
|
||||
for i := range objs {
|
||||
var base *SGuestResourceBase
|
||||
err := reflectutils.FindAnonymouStructPointer(objs[i], &base)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot find SGuestResourceBase in object %s", objs[i])
|
||||
continue
|
||||
}
|
||||
guestIds[i] = base.GuestId
|
||||
}
|
||||
guests := make(map[string]SGuest)
|
||||
err := db.FetchStandaloneObjectsByIds(GuestManager, guestIds, guests)
|
||||
if err != nil {
|
||||
log.Errorf("FetchStandaloneObjectsByIds fail %s", err)
|
||||
return rows
|
||||
}
|
||||
|
||||
hostList := make([]interface{}, len(rows))
|
||||
for i := range rows {
|
||||
if guest, ok := guests[guestIds[i]]; ok {
|
||||
rows[i].Guest = guest.Name
|
||||
rows[i].HostId = guest.HostId
|
||||
}
|
||||
hostList[i] = &SHostResourceBase{rows[i].HostId}
|
||||
}
|
||||
|
||||
hostRows := manager.SHostResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, hostList, fields, isList)
|
||||
for i := range rows {
|
||||
rows[i].HostResourceInfo = hostRows[i]
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
func (manager *SGuestResourceBaseManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestFilterListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
if len(query.Server) > 0 {
|
||||
guestObj, err := GuestManager.FetchByIdOrName(userCred, query.Server)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(GuestManager.Keyword(), query.Server)
|
||||
} else {
|
||||
return nil, errors.Wrap(err, "GuestManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
q = q.Equals("guest_id", guestObj.GetId())
|
||||
}
|
||||
guestQ := GuestManager.Query("id").Snapshot()
|
||||
guestQ, err = manager.SHostResourceBaseManager.ListItemFilter(ctx, guestQ, userCred, query.HostFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHostResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
if guestQ.IsAltered() {
|
||||
q = q.Filter(sqlchemy.In(q.Field("guest_id"), guestQ.SubQuery()))
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SGuestResourceBaseManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error) {
|
||||
switch field {
|
||||
case "guest", "server":
|
||||
guestQuery := GuestManager.Query("name", "id").SubQuery()
|
||||
q = q.AppendField(guestQuery.Field("name", field)).Distinct()
|
||||
q = q.Join(guestQuery, sqlchemy.Equals(q.Field("guest_id"), guestQuery.Field("id")))
|
||||
return q, nil
|
||||
default:
|
||||
guests := GuestManager.Query("id", "host_id").SubQuery()
|
||||
q = q.LeftJoin(guests, sqlchemy.Equals(q.Field("guest_id"), guests.Field("id")))
|
||||
q, err := manager.SHostResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
}
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
func (manager *SGuestResourceBaseManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestFilterListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
q, orders, fields := manager.GetOrderBySubQuery(q, userCred, query)
|
||||
if len(orders) > 0 {
|
||||
q = db.OrderByFields(q, orders, fields)
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SGuestResourceBaseManager) GetOrderBySubQuery(
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.GuestFilterListInput,
|
||||
) (*sqlchemy.SQuery, []string, []sqlchemy.IQueryField) {
|
||||
guestQ := GuestManager.Query("id", "name")
|
||||
var orders []string
|
||||
var fields []sqlchemy.IQueryField
|
||||
|
||||
if db.NeedOrderQuery(manager.SHostResourceBaseManager.GetOrderByFields(query.HostFilterListInput)) {
|
||||
var hostOrders []string
|
||||
var hostFields []sqlchemy.IQueryField
|
||||
guestQ, hostOrders, hostFields = manager.SHostResourceBaseManager.GetOrderBySubQuery(guestQ, userCred, query.HostFilterListInput)
|
||||
if len(hostOrders) > 0 {
|
||||
orders = append(orders, hostOrders...)
|
||||
fields = append(fields, hostFields...)
|
||||
}
|
||||
}
|
||||
if db.NeedOrderQuery(manager.GetOrderByFields(query)) {
|
||||
subq := guestQ.SubQuery()
|
||||
q = q.LeftJoin(subq, sqlchemy.Equals(q.Field("guest_id"), subq.Field("id")))
|
||||
if db.NeedOrderQuery([]string{query.OrderByServer}) {
|
||||
orders = append(orders, query.OrderByServer)
|
||||
fields = append(fields, subq.Field("name"))
|
||||
}
|
||||
}
|
||||
return q, orders, fields
|
||||
}
|
||||
|
||||
func (manager *SGuestResourceBaseManager) GetOrderByFields(query api.GuestFilterListInput) []string {
|
||||
orders := make([]string, 0)
|
||||
hostOrders := manager.SHostResourceBaseManager.GetOrderByFields(query.HostFilterListInput)
|
||||
orders = append(orders, hostOrders...)
|
||||
orders = append(orders, query.OrderByServer)
|
||||
return orders
|
||||
}
|
||||
@@ -401,7 +401,45 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
}*/
|
||||
|
||||
if len(query.OsType) > 0 {
|
||||
q = q.Equals("os_type", query.OsType)
|
||||
q = q.In("os_type", query.OsType)
|
||||
}
|
||||
if len(query.VcpuCount) > 0 {
|
||||
q = q.In("vcpu_count", query.VcpuCount)
|
||||
}
|
||||
if len(query.VmemSize) > 0 {
|
||||
q = q.In("vmem_size", query.VmemSize)
|
||||
}
|
||||
if len(query.BootOrder) > 0 {
|
||||
q = q.In("boot_order", query.BootOrder)
|
||||
}
|
||||
if len(query.Vga) > 0 {
|
||||
q = q.In("vga", query.Vga)
|
||||
}
|
||||
if len(query.Vdi) > 0 {
|
||||
q = q.In("vdi", query.Vdi)
|
||||
}
|
||||
if len(query.Machine) > 0 {
|
||||
q = q.In("machine", query.Machine)
|
||||
}
|
||||
if len(query.Bios) > 0 {
|
||||
q = q.In("bios", query.Bios)
|
||||
}
|
||||
if query.SrcIpCheck != nil {
|
||||
if *query.SrcIpCheck {
|
||||
q = q.IsTrue("src_ip_check")
|
||||
} else {
|
||||
q = q.IsFalse("src_ip_check")
|
||||
}
|
||||
}
|
||||
if query.SrcMacCheck != nil {
|
||||
if *query.SrcMacCheck {
|
||||
q = q.IsTrue("src_mac_check")
|
||||
} else {
|
||||
q = q.IsFalse("src_mac_check")
|
||||
}
|
||||
}
|
||||
if len(query.InstanceType) > 0 {
|
||||
q = q.In("instance_type", query.InstanceType)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
|
||||
Reference in New Issue
Block a user