mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #4713 from swordqiu/feature/qj-cloud-provider-capability-and-list-input-struct
feature: cloudprovider capability filter and listinput recode
This commit is contained in:
@@ -30,6 +30,7 @@ func init() {
|
||||
|
||||
type CloudaccountListOptions struct {
|
||||
options.BaseListOptions
|
||||
Capability []string `help:"capability filter" choices:"project|compute|network|loadbalancer|objectstore|rds|cache|event"`
|
||||
}
|
||||
R(&CloudaccountListOptions{}, "cloud-account-list", "List cloud accounts", func(s *mcclient.ClientSession, args *CloudaccountListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
@@ -39,6 +40,9 @@ func init() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args.Capability) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(args.Capability), "capability")
|
||||
}
|
||||
}
|
||||
result, err := modules.Cloudaccounts.List(s, params)
|
||||
if err != nil {
|
||||
|
||||
@@ -31,8 +31,9 @@ func init() {
|
||||
|
||||
Usable bool `help:"Vpc & Network usable"`
|
||||
|
||||
HasObjectStorage bool `help:"filter cloudproviders that has object storage"`
|
||||
NoObjectStorage bool `help:"filter cloudproviders that has no object storage"`
|
||||
HasObjectStorage bool `help:"filter cloudproviders that has object storage"`
|
||||
NoObjectStorage bool `help:"filter cloudproviders that has no object storage"`
|
||||
Capability []string `help:"capability filter" choices:"project|compute|network|loadbalancer|objectstore|rds|cache|event"`
|
||||
}
|
||||
R(&CloudproviderListOptions{}, "cloud-provider-list", "List cloud providers", func(s *mcclient.ClientSession, args *CloudproviderListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
@@ -52,6 +53,10 @@ func init() {
|
||||
} else if args.NoObjectStorage {
|
||||
params.Add(jsonutils.JSONFalse, "has_object_storage")
|
||||
}
|
||||
|
||||
if len(args.Capability) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(args.Capability), "capability")
|
||||
}
|
||||
}
|
||||
result, err := modules.Cloudproviders.List(s, params)
|
||||
if err != nil {
|
||||
|
||||
@@ -133,7 +133,7 @@ require (
|
||||
k8s.io/klog v0.1.0 // indirect
|
||||
k8s.io/kubernetes v1.12.3
|
||||
yunion.io/x/executor v0.0.0-20191202093616-92e2e6119257
|
||||
yunion.io/x/jsonutils v0.0.0-20200110114224-cf1b538ba071
|
||||
yunion.io/x/jsonutils v0.0.0-20200113074440-9297fd00ba07
|
||||
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d
|
||||
yunion.io/x/pkg v0.0.0-20200103043034-27c6f82160fa
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
|
||||
@@ -662,8 +662,8 @@ yunion.io/x/executor v0.0.0-20191202093616-92e2e6119257 h1:LZ6eC1uoLDAp7NQlaCy+D
|
||||
yunion.io/x/executor v0.0.0-20191202093616-92e2e6119257/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051 h1:vtZw2iwGrsARNSwRTREGjmr2BWPdxbmXVkb3kI1qu28=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
yunion.io/x/jsonutils v0.0.0-20200110114224-cf1b538ba071 h1:k5IGOgp0aCr8CE3T2XdmYF7valNGx8M2uG9OI3s22NU=
|
||||
yunion.io/x/jsonutils v0.0.0-20200110114224-cf1b538ba071/go.mod h1:NpWHLv3D1iMpsp1Kv6o1ASPZmuSKutE3RIMhxKSOeAM=
|
||||
yunion.io/x/jsonutils v0.0.0-20200113074440-9297fd00ba07 h1:i6Im3w4UoyCIKOEtr0Y3aAPGrL9FYAzeFXoj3daXXt0=
|
||||
yunion.io/x/jsonutils v0.0.0-20200113074440-9297fd00ba07/go.mod h1:NpWHLv3D1iMpsp1Kv6o1ASPZmuSKutE3RIMhxKSOeAM=
|
||||
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b h1:Z9z+7iegu0HXuL+S8taVWRd1P4b9JJOgPXIeoqYrj7c=
|
||||
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE=
|
||||
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d h1:59zrDL7Ft+hDukguJRmLr/Gdu/9V75x+yX99ovZwfaA=
|
||||
|
||||
@@ -16,14 +16,11 @@ package cloudevent
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
)
|
||||
|
||||
type CloudeventListInput struct {
|
||||
apis.BaseListInput
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
apis.SharableVirtualResourceListInput
|
||||
|
||||
Cloudprovider string `json:"cloudprovider"`
|
||||
|
||||
Providers []string `json:"providers"`
|
||||
compute.ManagedResourceListInput
|
||||
}
|
||||
|
||||
+12
-6
@@ -424,9 +424,6 @@ type ServerCreateInput struct {
|
||||
// swagger:ignore
|
||||
AutoPrepaidRecycle bool `json:"auto_prepaid_recycle,omitfalse"`
|
||||
|
||||
// 安全组Id, 此参数会和secgroups参数合并
|
||||
SecgroupId string `json:"secgrp_id"`
|
||||
|
||||
// 弹性公网IP带宽
|
||||
// 指定此参数后会创建新的弹性公网IP并绑定到新建的虚拟机
|
||||
// 私有云不支持此参数
|
||||
@@ -445,6 +442,8 @@ type ServerCreateInput struct {
|
||||
// required: false
|
||||
InstanceSnapshotId string `json:"instance_snapshot_id,omitempty"`
|
||||
|
||||
// 安全组Id, 此参数会和secgroups参数合并
|
||||
SecgroupId string `json:"secgrp_id"`
|
||||
// 安全组Id列表
|
||||
Secgroups []string `json:"secgroups"`
|
||||
|
||||
@@ -458,7 +457,8 @@ type ServerCreateInput struct {
|
||||
// swagger:ignore
|
||||
BillingCycle string `json:"billing_cycle"`
|
||||
|
||||
// DEPRECATE
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// 此参数等同于 hypervisor=baremetal
|
||||
Baremetal bool `json:"baremetal"`
|
||||
|
||||
@@ -469,8 +469,14 @@ type ServerCreateInput struct {
|
||||
// swagger:ignore
|
||||
DefaultStorageType string `json:"default_storage_type,omitempty"`
|
||||
|
||||
// Guest Image ID
|
||||
GuestImageID string
|
||||
// 指定用于新建主机的主机镜像ID
|
||||
GuestImageID string `json:"guest_image_id"`
|
||||
}
|
||||
|
||||
func (input *ServerCreateInput) AfterUnmarshal() {
|
||||
if input.Baremetal {
|
||||
input.Hypervisor = HYPERVISOR_BAREMETAL
|
||||
}
|
||||
}
|
||||
|
||||
type ServerCloneInput struct {
|
||||
|
||||
@@ -89,3 +89,9 @@ func (input *BucketMetadataInput) Validate() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type BucketListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
@@ -98,3 +98,11 @@ func (i CloudaccountShareModeInput) Validate() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CloudaccountListInput struct {
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
CapabilityListInput
|
||||
}
|
||||
|
||||
@@ -14,6 +14,13 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
type CloudproviderDetails struct {
|
||||
Provider string `json:"provider,omitempty"`
|
||||
Brand string `json:"brand,omitempty"`
|
||||
@@ -36,63 +43,124 @@ type CloudproviderDetails struct {
|
||||
CloudEnv string `json:"cloud_env,omitempty"`
|
||||
}
|
||||
|
||||
type CloudaccountListInput struct {
|
||||
// List objects belonging to the cloud provider
|
||||
type ManagedResourceListInput struct {
|
||||
// 列出关联指定云订阅(ID或Name)的资源
|
||||
Cloudprovider string `json:"cloudprovider"`
|
||||
|
||||
// List objects belonging to the cloud provider
|
||||
// deprecate:true
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
Manager string `json:"manager"`
|
||||
// deprecate:true
|
||||
Manager string `json:"manager" deprecated-by:"cloudprovider"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
ManagerId string `json:"manager_id"`
|
||||
// deprecate:true
|
||||
ManagerId string `json:"manager_id" deprecated-by:"cloudprovider"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
CloudproviderId string `json:"cloudprovider_id"`
|
||||
CloudproviderId string `json:"cloudprovider_id" deprecated-by:"cloudprovider"`
|
||||
|
||||
// List objects belonging to the cloud account
|
||||
// 列出关联指定云账号(ID或Name)的资源
|
||||
Cloudaccount string `json:"cloudaccount"`
|
||||
// deprecate:true
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
CloudaccountId string `json:"cloudaccount_id"`
|
||||
// deprecate:true
|
||||
CloudaccountId string `json:"cloudaccount_id" deprecated-by:"cloudaccount"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
Account string `json:"account"`
|
||||
// deprecate:true
|
||||
Account string `json:"account" deprecated-by:"cloudaccount"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
AccountId string `json:"account_id"`
|
||||
AccountId string `json:"account_id" deprecated-by:"cloudaccount"`
|
||||
|
||||
// List objects from the providers, choices:"OneCloud|VMware|Aliyun|Qcloud|Azure|Aws|Huawei|OpenStack|Ucloud|ZStack|Google"
|
||||
Providers []string `json:"provider"`
|
||||
// 列出指定云平台的资源,支持的云平台如下
|
||||
// enum: OneCloud,VMware,Aliyun,Qcloud,Azure,Aws,Huawei,OpenStack,Ucloud,ZStack,Google,Ctyun,S3,Ceph,Xsky"
|
||||
Providers []string `json:"providers"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
Provider []string `json:"provider" deprecated-by:"providers"`
|
||||
|
||||
// List objects belonging to brands
|
||||
Brands []string `json:"brand"`
|
||||
}
|
||||
// 列出指定云平台品牌的资源
|
||||
Brands []string `json:"brands"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
Brand []string `json:"brand" deprecated-by:"brands"`
|
||||
|
||||
type CloudTypeListInput struct {
|
||||
// enum: public_cloud,private_cloud,on_premise
|
||||
// 列出指定云环境的资源,支持云环境如下:
|
||||
//
|
||||
// | CloudEnv | 说明 |
|
||||
// |-----------|--------|
|
||||
// | public | 公有云 |
|
||||
// | private | 私有云 |
|
||||
// | onpremise | 本地IDC |
|
||||
//
|
||||
// enum: public,private,onpremise
|
||||
CloudEnv string `json:"cloud_env"`
|
||||
|
||||
// deprecate:true
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
PublicCloud bool `json:"public_cloud"`
|
||||
// deprecate:true
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
IsPublic bool `json:"is_public"`
|
||||
|
||||
// deprecate:true
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
PrivateCloud bool `json:"private_cloud"`
|
||||
// deprecate:true
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
IsPrivate bool `json:"is_private"`
|
||||
|
||||
// deprecate:true
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
IsOnPremise bool `json:"is_on_premise"`
|
||||
|
||||
// List objects managed by external providers
|
||||
// 过滤资源,是否为非OneCloud内置私有云管理的资源
|
||||
// default: false
|
||||
IsManaged bool `json:"is_managed"`
|
||||
}
|
||||
|
||||
func (input *ManagedResourceListInput) AfterUnmarshal() {
|
||||
if len(input.CloudEnv) > 0 {
|
||||
return
|
||||
}
|
||||
if input.PublicCloud || input.IsPublic {
|
||||
input.CloudEnv = CLOUD_ENV_PUBLIC_CLOUD
|
||||
} else if input.PrivateCloud || input.IsPrivate {
|
||||
input.CloudEnv = CLOUD_ENV_PRIVATE_CLOUD
|
||||
} else if input.IsOnPremise {
|
||||
input.CloudEnv = CLOUD_ENV_ON_PREMISE
|
||||
}
|
||||
}
|
||||
|
||||
type CapabilityListInput struct {
|
||||
// 根据该云平台的功能对云账号或云订阅进行过滤
|
||||
Capability []string `json:"capability"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by HasObjectStorage
|
||||
HasObjectStorage *bool `json:"has_object_storage"`
|
||||
}
|
||||
|
||||
type CloudproviderListInput struct {
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
UsableResourceListInput
|
||||
|
||||
CapabilityListInput
|
||||
}
|
||||
|
||||
func (input *CapabilityListInput) AfterUnmarshal() {
|
||||
if input.HasObjectStorage != nil && *input.HasObjectStorage && !utils.IsInStringArray(cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE, input.Capability) {
|
||||
input.Capability = append(input.Capability, cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,5 +159,58 @@ type SDBInstanceRecoveryConfigInput struct {
|
||||
|
||||
DBInstancebackup string
|
||||
DBInstancebackupId string `json:"dbinstancebackup_id"`
|
||||
Databases map[string]string `json:"allowempty"`
|
||||
Databases map[string]string `json:"databases,allowempty"`
|
||||
}
|
||||
|
||||
type DBInstanceListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ZonalFilterListInput
|
||||
ManagedResourceListInput
|
||||
VpcFilterListInput
|
||||
}
|
||||
|
||||
type DBInstanceBackupListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
RegionalFilterListInput
|
||||
|
||||
DbinstanceFilterListInput
|
||||
}
|
||||
|
||||
type DBInstancePrivilegeListInput struct {
|
||||
apis.ResourceBaseListInput
|
||||
|
||||
// filter by dbinstanceaccount
|
||||
Dbinstanceaccount string `json:"dbinstanceaccount"`
|
||||
// filter by dbinstancedatabase
|
||||
Dbinstancedatabase string `json:"dbinstancedatabase"`
|
||||
}
|
||||
|
||||
type DBInstanceParameterListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
DbinstanceFilterListInput
|
||||
}
|
||||
|
||||
type DBInstanceDatabaseListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
DbinstanceFilterListInput
|
||||
}
|
||||
|
||||
type DBInstanceAccountListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
DbinstanceFilterListInput
|
||||
}
|
||||
|
||||
type DbinstanceFilterListInput struct {
|
||||
// filter by dbinstance
|
||||
Dbinstance string `json:"dbinstance"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by dbinstance_id
|
||||
DbinstanceId string `json:"dbinstance_id" deprecated-by:"dbinstance"`
|
||||
}
|
||||
|
||||
@@ -80,3 +80,51 @@ func (req *ServerCreateInput) ToDiskCreateInput() *DiskCreateInput {
|
||||
input.Domain = req.Domain
|
||||
return &input
|
||||
}
|
||||
|
||||
type SnapshotPolicyFilterListInput struct {
|
||||
// filter disk by snapshotpolicy
|
||||
Snapshotpolicy string `json:"snapshotpolicy"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter disk by snapshotpolicy_id
|
||||
SnapshotpolicyId string `json:"snapshotpolicy_id" deprecated-by:"snapshotpolicy"`
|
||||
}
|
||||
|
||||
type DiskListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
BillingFilterListInput
|
||||
StorageFilterListInput
|
||||
StorageShareFilterListInput
|
||||
SnapshotPolicyFilterListInput
|
||||
ServerFilterListInput
|
||||
|
||||
// filter disk by whether it is being used
|
||||
Unused *bool `json:"unused"`
|
||||
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by disk type
|
||||
Type string `json:"type" deprecated-by:"disk_type"`
|
||||
// 过滤指定disk_type的磁盘列表,可能的值为:sys, data, swap. volume
|
||||
//
|
||||
// | disk_type值 | 说明 |
|
||||
// |-------------|----------|
|
||||
// | sys | 虚拟机系统盘 |
|
||||
// | data | 虚拟机数据盘 |
|
||||
// | swap | 虚拟机内存交换盘 |
|
||||
// | volume | 容器volumn盘 |
|
||||
//
|
||||
DiskType string `json:"disk_type"`
|
||||
}
|
||||
|
||||
type DiskFilterListInput struct {
|
||||
// 以指定虚拟磁盘(ID或Name)过滤列表结果
|
||||
Disk string `json:"disk"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by disk_id
|
||||
DiskId string `json:"disk_id" deprecated-by:"disk"`
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
ELASTIC_CACHE_STATUS_RUNNING = "running" //(正常)
|
||||
ELASTIC_CACHE_STATUS_RESTARTING = "restarting" //(重启中)
|
||||
@@ -102,3 +106,28 @@ const (
|
||||
ELASTIC_CACHE_ARCH_TYPE_CLUSTER = "cluster" // 集群
|
||||
ELASTIC_CACHE_ARCH_TYPE_RWSPLIT = "rwsplit" // 读写分离
|
||||
)
|
||||
|
||||
type ElasticcacheListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ZonalFilterListInput
|
||||
VpcFilterListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
type ElasticcacheAccountListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
}
|
||||
|
||||
type ElasticcacheAclListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
type ElasticcacheBackupListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
}
|
||||
|
||||
type ElasticcacheParameterListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
EIP_MODE_INSTANCE_PUBLICIP = "public_ip"
|
||||
EIP_MODE_STANDALONE_EIP = "elastic_ip"
|
||||
@@ -48,3 +52,16 @@ const (
|
||||
var (
|
||||
EIP_ASSOCIATE_VALID_TYPES = []string{EIP_ASSOCIATE_TYPE_SERVER, EIP_ASSOCIATE_TYPE_NAT_GATEWAY}
|
||||
)
|
||||
|
||||
type ElasticipListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
RegionalFilterListInput
|
||||
UsableResourceListInput
|
||||
|
||||
// filter usable eip for given associate type
|
||||
UsableEipForAssociateType string `json:"usable_eip_for_associate_type"`
|
||||
// filter usable eip for given associate id
|
||||
UsableEipForAssociateId string `json:"usable_eip_for_associate_id"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
// 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 compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type RegionalFilterListInput struct {
|
||||
// 过滤位于指定城市区域的资源
|
||||
City string `json:"city"`
|
||||
|
||||
// 过滤处于指定区域内的资源
|
||||
Cloudregion string `json:"cloudregion"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
CloudregionId string `json:"cloudregion_id" deprecated-by:"cloudregion"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
Region string `json:"region" deprecated-by:"cloudregion"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// description: this param will be deprecate at 3.0
|
||||
RegionId string `json:"region_id" deprecated-by:"cloudregion"`
|
||||
}
|
||||
|
||||
type ZonalFilterListInput struct {
|
||||
RegionalFilterListInput
|
||||
|
||||
// 过滤处于指定可用区内的资源
|
||||
Zone string `json:"zone"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by zone_id
|
||||
ZoneId string `json:"zone_id" deprecated-by:"zone"`
|
||||
// 过滤处于多个指定可用区内的资源
|
||||
Zones []string `json:"zones"`
|
||||
}
|
||||
|
||||
func (input ZonalFilterListInput) ZoneList() []string {
|
||||
zoneStr := input.Zone
|
||||
if len(zoneStr) > 0 {
|
||||
input.Zones = append(input.Zones, zoneStr)
|
||||
}
|
||||
return input.Zones
|
||||
}
|
||||
|
||||
type HostFilterListInput struct {
|
||||
ZonalFilterListInput
|
||||
|
||||
// 过滤关联指定宿主机(ID或Name)的列表结果
|
||||
Host string `json:"host"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by host_id
|
||||
HostId string `json:"host_id" deprecated-by:"host"`
|
||||
}
|
||||
|
||||
type CloudregionListInput struct {
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
UsableResourceListInput
|
||||
UsableVpcResourceListInput
|
||||
|
||||
// 过滤位于指定城市的区域
|
||||
City string `json:"city"`
|
||||
// 过滤提供特定服务的区域
|
||||
Service string `json:"service"`
|
||||
}
|
||||
|
||||
type ZoneListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
RegionalFilterListInput
|
||||
|
||||
UsableResourceListInput
|
||||
UsableVpcResourceListInput
|
||||
|
||||
// 过滤提供特定服务的可用区
|
||||
Service string `json:"service"`
|
||||
}
|
||||
+53
-36
@@ -18,53 +18,70 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type ServerListInput struct {
|
||||
apis.BaseListInput
|
||||
type ServerFilterListInput struct {
|
||||
// 以关联主机(ID或Name)过滤列表
|
||||
Server string `json:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by guest Id
|
||||
ServerId string `json:"server_id" deprecated-by:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by guest Id
|
||||
Guest string `json:"guest" deprecated-by:"server"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by guest Id
|
||||
GuestId string `json:"guest_id" deprecated-by:"server"`
|
||||
}
|
||||
|
||||
// 过滤可用区底下的资源
|
||||
Zone string `json:"zone"`
|
||||
// 过滤连接此二层网络的资源
|
||||
Wire string `json:"wire"`
|
||||
// 过滤关联此网络的资源
|
||||
Network string `json:"network"`
|
||||
// Disk ID or Name
|
||||
Disk string `json:"disk"`
|
||||
// Host ID or Name
|
||||
Host string `json:"host"`
|
||||
// Show baremetal servers
|
||||
type ServerListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
HostFilterListInput
|
||||
NetworkFilterListInput
|
||||
BillingFilterListInput
|
||||
GroupFilterListInput
|
||||
SecgroupFilterListInput
|
||||
DiskFilterListInput
|
||||
|
||||
// 只列出裸金属主机
|
||||
Baremetal *bool `json:"baremetal"`
|
||||
// Show gpu servers
|
||||
// 只列出GPU主机
|
||||
Gpu *bool `json:"gpu"`
|
||||
// Secgroup ID or Name
|
||||
Secgroup string `json:"secgroup"`
|
||||
// AdminSecgroup ID or Name
|
||||
// 列出管理安全组为指定安全组的主机
|
||||
AdminSecgroup string `json:"admin_security"`
|
||||
// Show server of hypervisor choices:"kvm|esxi|container|baremetal|aliyun|azure|aws|huawei|ucloud|zstack|openstack"`
|
||||
Hypervisor string `json:"hypervisor"`
|
||||
// Show servers in cloudregion
|
||||
Region string `json:"region"`
|
||||
// Show Servers with EIP
|
||||
// 列出Hypervisor为指定值的主机
|
||||
// enum: kvm,esxi,baremetal,aliyun,azure,aws,huawei,ucloud,zstack,openstack,google,ctyun"`
|
||||
Hypervisor []string `json:"hypervisor"`
|
||||
// 列出绑定了弹性IP(EIP)的主机
|
||||
WithEip *bool `json:"with_eip"`
|
||||
// Show Servers without EIP
|
||||
// 列出未绑定弹性IP(EIO)的主机
|
||||
WithoutEip *bool `json:"without_eip"`
|
||||
// OS Type choices:"linux|windows|vmware"`
|
||||
// 列出操作系统为指定值的主机
|
||||
// enum: linux,windows,vmware
|
||||
OsType string `json:"os_type"`
|
||||
// Order by disk size choices:"asc|desc"
|
||||
// 对列表结果按照磁盘进行排序
|
||||
// enum: asc,desc
|
||||
OrderByDisk string `json:"order_by_disk"`
|
||||
// Order by host name choices:"asc|desc"
|
||||
// 对主机列表结果按照宿主机名称进行排序
|
||||
// enum: asc,desc
|
||||
OrderByHost string `json:"order_by_host"`
|
||||
// Vpc id or name
|
||||
Vpc string `json:"vpc"`
|
||||
// Eip id or name
|
||||
// 列出可以挂载指定EIP的主机
|
||||
UsableServerForEip string `json:"usable_server_for_eip"`
|
||||
// Show Servers without user metadata
|
||||
WithoutUserMeta *bool `json:"without_user_meta"`
|
||||
// Instance Group ID or Name
|
||||
Group string `json:"group"`
|
||||
// Resource type choices:"shared|prepaid|dedicated"
|
||||
|
||||
// 按主机资源类型进行排序
|
||||
// enum: shared,prepaid,dedicated
|
||||
ResourceType string `json:"resource_type"`
|
||||
// Billing type choices:"postpaid|prepaid"
|
||||
BillingType string `json:"billing_type"`
|
||||
// 返回开启主备机功能的主机
|
||||
GetBackupGuestsOnHost *bool `json:"get_backup_guests_on_host"`
|
||||
}
|
||||
|
||||
func (input *ServerListInput) AfterUnmarshal() {
|
||||
if input.Baremetal != nil && *input.Baremetal {
|
||||
input.Hypervisor = append(input.Hypervisor, HYPERVISOR_BAREMETAL)
|
||||
}
|
||||
}
|
||||
|
||||
type ServerRebuildRootInput struct {
|
||||
|
||||
@@ -43,3 +43,29 @@ type DiskSpec struct {
|
||||
EndIndex int `json:"end_index"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type HostListInput struct {
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
ZonalFilterListInput
|
||||
WireFilterListInput
|
||||
SchedtagFilterListInput
|
||||
|
||||
StorageFilterListInput
|
||||
UsableResourceListInput
|
||||
|
||||
// filter by ResourceType
|
||||
ResourceType string `json:"resource_type"`
|
||||
// filter by mac of any network interface
|
||||
AnyMac string `json:"any_mac"`
|
||||
// filter storages not attached to this host
|
||||
StorageNotAttached *bool `json:"storage_not_attached"`
|
||||
// filter by Hypervisor
|
||||
Hypervisor string `json:"hypervisor"`
|
||||
// filter host that is empty
|
||||
IsEmpty *bool `json:"is_empty"`
|
||||
// filter host that is baremetal
|
||||
Baremetal *bool `json:"baremetal"`
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type RegionalResourceCreateInput struct {
|
||||
Cloudregion string `json:"cloudregion"`
|
||||
CloudregionId string `json:"cloudregion_id"`
|
||||
@@ -29,3 +33,63 @@ type DeletePreventableCreateInput struct {
|
||||
//default: true
|
||||
DisableDelete *bool `json:"disable_delete"`
|
||||
}
|
||||
|
||||
type KeypairListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
apis.UserResourceListInput
|
||||
|
||||
// list in admin mode
|
||||
Admin *bool `json:"admin"`
|
||||
}
|
||||
|
||||
type CachedimageListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
ZonalFilterListInput
|
||||
}
|
||||
|
||||
type ExternalProjectListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
type RouteTableListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
RegionalFilterListInput
|
||||
VpcFilterListInput
|
||||
}
|
||||
|
||||
type SnapshotPolicyCacheListInput struct {
|
||||
apis.ResourceBaseListInput
|
||||
|
||||
// filter by snapshotpolicy Id or Name
|
||||
Snapshotpolicy string `json:"snapshotpolicy"`
|
||||
}
|
||||
|
||||
type BillingFilterListInput struct {
|
||||
// filter by billing_type
|
||||
BillingType string `json:"billing_type"`
|
||||
}
|
||||
|
||||
type NetworkInterfaceListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
type BaremetalagentListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
type DnsRecordListInput struct {
|
||||
apis.AdminSharableVirtualResourceListInput
|
||||
}
|
||||
|
||||
type DynamicschedtagListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
@@ -17,16 +17,14 @@ package compute
|
||||
import "yunion.io/x/onecloud/pkg/apis"
|
||||
|
||||
type InstanceGroupListInput struct {
|
||||
apis.BaseListInput
|
||||
apis.VirtualResourceListInput
|
||||
ZonalFilterListInput
|
||||
ServerFilterListInput
|
||||
|
||||
// Filter by service type
|
||||
// 以service_type过滤列表结果
|
||||
ServiceType string `json:"service_type"`
|
||||
// Filter by parent id
|
||||
// 以parent_id过滤列表结果
|
||||
ParentId string `json:"parent_id"`
|
||||
// Filter by zone id
|
||||
ZoneId string `json:"zone_id"`
|
||||
// Filter by guest id or name
|
||||
Server string `json:"server"`
|
||||
}
|
||||
|
||||
type InstanceGroupDetail struct {
|
||||
@@ -34,3 +32,12 @@ type InstanceGroupDetail struct {
|
||||
SGroup
|
||||
GuestCount int64 `json:"guest_count"`
|
||||
}
|
||||
|
||||
type GroupFilterListInput struct {
|
||||
// 以指定实例组(ID或Name)过滤列表结果
|
||||
Group string `json:"group"`
|
||||
// swagger:ignore
|
||||
// deprecated: true
|
||||
// Filter by instance group Id
|
||||
GroupId string `json:"group_id" deprecated-by:"group"`
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
DIRECT_PCI_TYPE = "PCI"
|
||||
GPU_HPC_TYPE = "GPU-HPC" // # for compute
|
||||
@@ -38,3 +42,17 @@ var VENDOR_ID_MAP = map[string]string{
|
||||
"NVIDIA": NVIDIA_VENDOR_ID,
|
||||
"AMD": AMD_VENDOR_ID,
|
||||
}
|
||||
|
||||
type IsolatedDeviceListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
HostFilterListInput
|
||||
|
||||
// filter by GPU type
|
||||
Gpu *bool `json:"gpu"`
|
||||
// filter by USB type
|
||||
Usb *bool `json:"usb"`
|
||||
// filter unused devices
|
||||
Unused *bool `json:"unused"`
|
||||
}
|
||||
|
||||
@@ -30,3 +30,87 @@ const (
|
||||
DeployMethodYum = "yum"
|
||||
DeployMethodCopy = "copy"
|
||||
)
|
||||
|
||||
type LoadbalancerListenerListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
RegionalFilterListInput
|
||||
|
||||
// filter by loadbalancer
|
||||
Loadbalancer string `json:"loadbalancer"`
|
||||
// filter by backend_group
|
||||
BackendGroup string `json:"backend_group"`
|
||||
// filter by acl
|
||||
Acl string `json:"acl"`
|
||||
}
|
||||
|
||||
type LoadbalancerListenerRuleListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
// filter by listener
|
||||
Listener string `json:"listener"`
|
||||
// filter by backend_group
|
||||
BackendGroup string `json:"backend_group"`
|
||||
}
|
||||
|
||||
type LoadbalancerListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
ZonalFilterListInput
|
||||
NetworkFilterListInput
|
||||
|
||||
// filter by cluster
|
||||
Cluster string `json:"cluster"`
|
||||
}
|
||||
|
||||
type LoadbalancerAgentListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
// filter by loadbalancercluster
|
||||
Cluster string `json:"cluster"`
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
UsableResourceListInput
|
||||
RegionalFilterListInput
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
type LoadbalancerBackendListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
RegionalFilterListInput
|
||||
|
||||
// filter by backend server
|
||||
Backend string `json:"backend"`
|
||||
// filter by backend group
|
||||
BackendGroup string `json:"backend_group"`
|
||||
}
|
||||
|
||||
type LoadbalancerBackendGroupListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
RegionalFilterListInput
|
||||
ManagedResourceListInput
|
||||
|
||||
// filter by loadbalancer
|
||||
Loadbalancer string `json:"loadbalancer"`
|
||||
// filter LoadbalancerBackendGroup with no reference
|
||||
NoRef *bool `json:"no_ref"`
|
||||
}
|
||||
|
||||
type LoadbalancerClusterListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
ZonalFilterListInput
|
||||
WireFilterListInput
|
||||
}
|
||||
|
||||
type LoadbalancerAclListInput struct {
|
||||
apis.SharableVirtualResourceListInput
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
NAT_STAUTS_AVAILABLE = "available" //可用
|
||||
NAT_STATUS_ALLOCATE = "allocate" //创建中
|
||||
@@ -33,3 +37,33 @@ const (
|
||||
QCLOUD_NAT_SPEC_MIDDLE = "middle"
|
||||
QCLOUD_NAT_SPEC_LARGE = "large"
|
||||
)
|
||||
|
||||
type NatGetewayListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
VpcFilterListInput
|
||||
RegionalFilterListInput
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
type NatEntryListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
type NatDEntryListInput struct {
|
||||
NatEntryListInput
|
||||
|
||||
// filter by natgateway
|
||||
Natgateway string `json:"natgateway"`
|
||||
}
|
||||
|
||||
type NatSEntryListInput struct {
|
||||
NatEntryListInput
|
||||
|
||||
// filter by natgateway
|
||||
Natgateway string `json:"natgateway"`
|
||||
// filter by network
|
||||
Network string `json:"network"`
|
||||
}
|
||||
|
||||
+35
-21
@@ -18,33 +18,47 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type NetworkListInput struct {
|
||||
apis.BaseListInput
|
||||
type VpcFilterListInput struct {
|
||||
// 过滤关联此VPC(ID或Name)的资源
|
||||
Vpc string `json:"vpc"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by vpc Id
|
||||
VpcId string `json:"vpc_id" deprecated-by:"vpc"`
|
||||
}
|
||||
|
||||
type WireFilterListInput struct {
|
||||
VpcFilterListInput
|
||||
|
||||
// 过滤连接此二层网络(ID或Name)的资源
|
||||
Wire string `json:"wire"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// fitler by wire id
|
||||
WireId string `json:"wire_id" deprecated-by:"wire"`
|
||||
}
|
||||
|
||||
type NetworkFilterListInput struct {
|
||||
WireFilterListInput
|
||||
|
||||
// 过滤关联此网络(ID或Name)的资源
|
||||
Network string `json:"network"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by networkId
|
||||
NetworkId string `json:"network_id" deprecated-by:"network"`
|
||||
}
|
||||
|
||||
type NetworkListInput struct {
|
||||
apis.SharableVirtualResourceListInput
|
||||
|
||||
CloudaccountListInput
|
||||
CloudTypeListInput
|
||||
HostFilterListInput
|
||||
|
||||
Zone string `json:"zone"`
|
||||
Zones []string `json:"zones"`
|
||||
ManagedResourceListInput
|
||||
|
||||
Vpc string `json:"vpc"`
|
||||
UsableResourceListInput
|
||||
|
||||
Cloudregion string `json:"cloudregion"`
|
||||
// deprecate:true
|
||||
// description: this param will be deprecate at 3.0
|
||||
CloudregionId string `json:"cloudregion_id"`
|
||||
// deprecate:true
|
||||
// description: this param will be deprecate at 3.0
|
||||
Region string `json:"region"`
|
||||
// deprecate:true
|
||||
// description: this param will be deprecate at 3.0
|
||||
RegionId string `json:"region_id"`
|
||||
|
||||
Usable bool `json:"usable"`
|
||||
Host string `json:"host"`
|
||||
City string `json:"city"`
|
||||
WireFilterListInput
|
||||
}
|
||||
|
||||
type NetworkCreateInput struct {
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
RESERVEDIP_TABLE = "reservedips_tbl"
|
||||
RESERVEDIP_RESOURCE_TYPE = "reservedip"
|
||||
@@ -23,3 +27,12 @@ const (
|
||||
RESERVEDIP_STATUS_OFFLINE = "offline"
|
||||
RESERVEDIP_STATUS_UNKNOWN = "unknown"
|
||||
)
|
||||
|
||||
type ReservedipListInput struct {
|
||||
apis.ResourceBaseListInput
|
||||
|
||||
NetworkFilterListInput
|
||||
|
||||
// list all reserved ips, including expired ones
|
||||
All *bool `json:"all"`
|
||||
}
|
||||
|
||||
@@ -38,3 +38,23 @@ type SchedtagCreateInput struct {
|
||||
// default: hosts
|
||||
ResourceType string `json:"resource_type"`
|
||||
}
|
||||
|
||||
type SchedtagFilterListInput struct {
|
||||
// 以关联的调度标签(ID或Name)过滤列表
|
||||
Schedtag string `json:"schedtag"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by schedtag_id
|
||||
SchedtagId string `json:"schedtag_id" deprecated-by:"schedtag"`
|
||||
}
|
||||
|
||||
type SchedtagListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
// fitler by resource_type
|
||||
ResourceType string `json:"resource_type"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by type, alias for resource_type
|
||||
Type string `json:"type" deprecated-by:"resource_type"`
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ package compute
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
|
||||
@@ -130,9 +129,38 @@ type SSecgroupCreateInput struct {
|
||||
Rules []SSecgroupRuleCreateInput `json:"rules"`
|
||||
}
|
||||
|
||||
type SSecgroupListFilterInput struct {
|
||||
apis.BaseListInput
|
||||
type SecgroupListInput struct {
|
||||
apis.SharableVirtualResourceListInput
|
||||
|
||||
// equals
|
||||
Equals string
|
||||
Server string
|
||||
|
||||
ServerFilterListInput
|
||||
}
|
||||
|
||||
type SecurityGroupCacheListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
SecgroupFilterListInput
|
||||
}
|
||||
|
||||
type SecurityGroupRuleListInput struct {
|
||||
apis.ResourceBaseListInput
|
||||
SecgroupFilterListInput
|
||||
|
||||
// 以direction字段过滤安全组规则
|
||||
Direction string `json:"direction"`
|
||||
// 以action字段过滤安全组规则
|
||||
Action string `json:"action"`
|
||||
// 以protocol字段过滤安全组规则
|
||||
Protocol string `json:"protocol"`
|
||||
}
|
||||
|
||||
type SecgroupFilterListInput struct {
|
||||
// 过滤关联指定安全组(ID或Name)的列表结果
|
||||
Secgroup string `json:"secgroup"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by secgroup_id
|
||||
SecgroupId string `json:"secgroup_id" deprecated-by:"secgroup"`
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
SkuCategoryGeneralPurpose = "general_purpose" // 通用型
|
||||
SkuCategoryBurstable = "burstable" // 突发性能型
|
||||
@@ -57,3 +61,41 @@ var SKU_FAMILIES = []string{
|
||||
SkuCategoryHighStorage,
|
||||
SkuCategoryHighMemory,
|
||||
}
|
||||
|
||||
type ServerSkuListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
ZonalFilterListInput
|
||||
BillingFilterListInput
|
||||
UsableResourceListInput
|
||||
|
||||
// filter sku by memory size in MB
|
||||
MemorySizeMb int `json:"memory_size_mb"`
|
||||
}
|
||||
|
||||
type ElasticcacheSkuListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
UsableResourceListInput
|
||||
BillingFilterListInput
|
||||
ZonalFilterListInput
|
||||
|
||||
// filter sku by memory size in MB
|
||||
MemorySizeMb int `json:"memory_size_mb"`
|
||||
}
|
||||
|
||||
type DBInstanceSkuListInput struct {
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
|
||||
RegionalFilterListInput
|
||||
BillingFilterListInput
|
||||
}
|
||||
|
||||
@@ -66,3 +66,23 @@ type SSnapshotPolicyCreateInternalInput struct {
|
||||
RepeatWeekdays uint8
|
||||
TimePoints uint32
|
||||
}
|
||||
|
||||
type SnapshotListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
StorageShareFilterListInput
|
||||
|
||||
// filter snapshot that is fake deleted
|
||||
FakeDeleted *bool `json:"fake_deleted"`
|
||||
// filter by disk type
|
||||
DiskType string `json:"disk_type"`
|
||||
// filter instance snapshot
|
||||
IsInstanceSnapshot *bool `json:"is_instance_snapshot"`
|
||||
}
|
||||
|
||||
type InstanceSnapshotListInput struct {
|
||||
apis.VirtualResourceListInput
|
||||
|
||||
ServerFilterListInput
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
STORAGE_LOCAL = "local"
|
||||
STORAGE_BAREMETAL = "baremetal"
|
||||
@@ -133,3 +137,36 @@ var (
|
||||
// 目前来说只支持这些
|
||||
SHARED_STORAGE = []string{STORAGE_NFS, STORAGE_GPFS, STORAGE_RBD}
|
||||
)
|
||||
|
||||
type StorageFilterListInput struct {
|
||||
// 过滤关联此存储(ID或Name)的列表结果
|
||||
Storage string `json:"storage"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by storage_id
|
||||
StorageId string `json:"storage_id" deprecated-by:"storage"`
|
||||
}
|
||||
|
||||
type StorageShareFilterListInput struct {
|
||||
// filter shared storage
|
||||
Share *bool `json:"share"`
|
||||
// filter local storage
|
||||
Local *bool `json:"local"`
|
||||
}
|
||||
|
||||
type StorageListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
ZonalFilterListInput
|
||||
UsableResourceListInput
|
||||
StorageShareFilterListInput
|
||||
}
|
||||
|
||||
type StoragecacheListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
const (
|
||||
VPC_STATUS_PENDING = "pending"
|
||||
VPC_STATUS_AVAILABLE = "available"
|
||||
@@ -32,3 +36,37 @@ const (
|
||||
DEFAULT_VPC_ID = "default"
|
||||
NORMAL_VPC_ID = "normal" // 没有关联VPC的安全组,统一使用normal
|
||||
)
|
||||
|
||||
type UsableResourceListInput struct {
|
||||
// filter by network usability of the resource
|
||||
Usable *bool `json:"usable"`
|
||||
}
|
||||
|
||||
type UsableVpcResourceListInput struct {
|
||||
// filter by Vpc usability of the resource
|
||||
UsableVpc *bool `json:"usable_vpc"`
|
||||
}
|
||||
|
||||
type VpcListInput struct {
|
||||
apis.StatusStandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
UsableResourceListInput
|
||||
|
||||
// filter by globalvpc
|
||||
Globalvpc string `json:"globalvpc"`
|
||||
}
|
||||
|
||||
type WireListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
VpcFilterListInput
|
||||
HostFilterListInput
|
||||
}
|
||||
|
||||
type GlobalVpcListInput struct {
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
}
|
||||
|
||||
@@ -126,7 +126,6 @@ type SCloudaccount struct {
|
||||
AccountId string `json:"account_id"`
|
||||
IsPublicCloud *bool `json:"is_public_cloud,omitempty"`
|
||||
IsOnPremise bool `json:"is_on_premise"`
|
||||
HasObjectStorage bool `json:"has_object_storage"`
|
||||
Provider string `json:"provider"`
|
||||
EnableAutoSync bool `json:"enable_auto_sync"`
|
||||
SyncIntervalSeconds int `json:"sync_interval_seconds"`
|
||||
@@ -156,6 +155,13 @@ type SCloudprovider struct {
|
||||
Provider string `json:"provider"`
|
||||
}
|
||||
|
||||
// SCloudproviderCapability is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudproviderCapability.
|
||||
type SCloudproviderCapability struct {
|
||||
apis.SResourceBase
|
||||
CloudproviderId string `json:"cloudprovider_id"`
|
||||
Capability string `json:"capability"`
|
||||
}
|
||||
|
||||
// SCloudproviderregion is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudproviderregion.
|
||||
type SCloudproviderregion struct {
|
||||
apis.SJointResourceBase
|
||||
@@ -173,7 +179,8 @@ type SCloudregion struct {
|
||||
SManagedResourceBase
|
||||
apis.SExternalizedResourceBase
|
||||
cloudprovider.SGeographicInfo
|
||||
Provider string `json:"provider"`
|
||||
Environment string `json:"environment"`
|
||||
Provider string `json:"provider"`
|
||||
}
|
||||
|
||||
// SCloudregionResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudregionResourceBase.
|
||||
@@ -306,7 +313,7 @@ type SDeletePreventableResourceBase struct {
|
||||
|
||||
// SDisk is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDisk.
|
||||
type SDisk struct {
|
||||
apis.SSharableVirtualResourceBase
|
||||
apis.SVirtualResourceBase
|
||||
apis.SExternalizedResourceBase
|
||||
SBillingResourceBase
|
||||
DiskFormat string `json:"disk_format"`
|
||||
@@ -529,6 +536,8 @@ type SGuest struct {
|
||||
FlavorId string `json:"flavor_id"`
|
||||
SecgrpId string `json:"secgrp_id"`
|
||||
AdminSecgrpId string `json:"admin_secgrp_id"`
|
||||
SrcIpCheck *bool `json:"omitempty,src_ip_check"`
|
||||
SrcMacCheck *bool `json:"omitempty,src_mac_check"`
|
||||
Hypervisor string `json:"hypervisor"`
|
||||
InstanceType string `json:"instance_type"`
|
||||
}
|
||||
|
||||
@@ -30,6 +30,111 @@ type EnabledIdentityBaseResourceCreateInput struct {
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type IdentityBaseResourceListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
apis.DomainizedResourceListInput
|
||||
}
|
||||
|
||||
type EnabledIdentityBaseResourceListInput struct {
|
||||
IdentityBaseResourceListInput
|
||||
|
||||
// filter by enabled status
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type ProjectFilterListInput struct {
|
||||
// 以项目(ID或Name)过滤列表结果
|
||||
Project string `json:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by project_id
|
||||
ProjectId string `json:"project_id" deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by tenant
|
||||
Tenant string `json:"tenant" deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by tenant_id
|
||||
TenantId string `json:"tenant_id" deprecated-by:"project"`
|
||||
}
|
||||
|
||||
type UserFilterListInput struct {
|
||||
// filter by user
|
||||
User string `json:"user"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by user_id
|
||||
UserId string `json:"user_id" deprecated-by:"user"`
|
||||
}
|
||||
|
||||
type GroupFilterListInput struct {
|
||||
// filter by group
|
||||
Group string `json:"group"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by group_id
|
||||
GroupId string `json:"group_id" deprecated-by:"group"`
|
||||
}
|
||||
|
||||
type RoleFilterListInput struct {
|
||||
// filter by role
|
||||
Role string `json:"role"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by role_id
|
||||
RoleId string `json:"role_id" deprecated-by:"role"`
|
||||
}
|
||||
|
||||
type ServiceFilterListInput struct {
|
||||
// filter by service, either id or name
|
||||
Service string `json:"service"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// filter by service_id
|
||||
ServiceId string `json:"service_id" deprecated-by:"service"`
|
||||
}
|
||||
|
||||
type RoleListInput struct {
|
||||
IdentityBaseResourceListInput
|
||||
|
||||
ProjectFilterListInput
|
||||
UserFilterListInput
|
||||
GroupFilterListInput
|
||||
}
|
||||
|
||||
type GroupListInput struct {
|
||||
IdentityBaseResourceListInput
|
||||
|
||||
UserFilterListInput
|
||||
ProjectFilterListInput
|
||||
}
|
||||
|
||||
type ProjectListInput struct {
|
||||
IdentityBaseResourceListInput
|
||||
|
||||
UserFilterListInput
|
||||
GroupFilterListInput
|
||||
}
|
||||
|
||||
type DomainListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
type UserListInput struct {
|
||||
EnabledIdentityBaseResourceListInput
|
||||
|
||||
GroupFilterListInput
|
||||
ProjectFilterListInput
|
||||
RoleFilterListInput
|
||||
}
|
||||
|
||||
type EndpointListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
|
||||
ServiceFilterListInput
|
||||
}
|
||||
|
||||
type SJoinProjectsInput struct {
|
||||
Projects []string
|
||||
Roles []string
|
||||
@@ -120,3 +225,24 @@ func (input SProjectRemoveUserGroupInput) Validate() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type IdentityProviderListInput struct {
|
||||
apis.EnabledStatusStandaloneResourceListInput
|
||||
}
|
||||
|
||||
type CredentialListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
type PolicyListInput struct {
|
||||
EnabledIdentityBaseResourceListInput
|
||||
apis.SharableResourceListInput
|
||||
}
|
||||
|
||||
type RegionListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
type ServiceListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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 image
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type ImageListInput struct {
|
||||
apis.SharableVirtualResourceListInput
|
||||
|
||||
// 以镜像的格式过滤,可能值为:qcow2, iso, vmdk, vhd, raw等
|
||||
DiskFormats []string `json:"disk_formats"`
|
||||
// 列出是否支持UEFI启动的镜像
|
||||
Uefi *bool `json:"uefi"`
|
||||
}
|
||||
|
||||
type GuestImageListInput struct {
|
||||
apis.SharableVirtualResourceListInput
|
||||
}
|
||||
@@ -14,6 +14,27 @@
|
||||
|
||||
package apis
|
||||
|
||||
type DomainizedResourceListInput struct {
|
||||
// swagger:ignore
|
||||
// Is an admin call? equivalent to scope=system
|
||||
// Deprecated
|
||||
Admin *bool `json:"admin"`
|
||||
|
||||
// 指定查询的权限范围,可能值为project, domain or system
|
||||
Scope string `json:"scope"`
|
||||
|
||||
// 查询指定的域(ID或名称)拥有的资源
|
||||
ProjectDomain string `json:"project_domain"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Project domain Id filter, alias for project_domain
|
||||
ProjectDomainId string `json:"project_domain_id" deprecated-by:"project_domain"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Domain Id filter, alias for project_domain
|
||||
DomainId string `json:"domain_id" deprecated-by:"project_domain"`
|
||||
}
|
||||
|
||||
type DomainizedResourceCreateInput struct {
|
||||
// description: the owner domain name or id
|
||||
// required: false
|
||||
@@ -24,6 +45,25 @@ type DomainizedResourceCreateInput struct {
|
||||
DomainId string `json:"domain_id"`
|
||||
}
|
||||
|
||||
type ProjectizedResourceListInput struct {
|
||||
DomainizedResourceListInput
|
||||
|
||||
// 查询指定的项目(ID或名称)拥有的资源
|
||||
Project string `json:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by project_id, alias for project
|
||||
ProjectId string `json:"project_id" deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by tenant ID or Name, alias for project
|
||||
Tenant string `json:"tenant" deprecated-by:"project"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by tenant_id, alias for project
|
||||
TenantId string `json:"tenant_id" deprecated-by:"project"`
|
||||
}
|
||||
|
||||
type ProjectizedResourceCreateInput struct {
|
||||
DomainizedResourceCreateInput
|
||||
|
||||
@@ -36,6 +76,25 @@ type ProjectizedResourceCreateInput struct {
|
||||
ProjectId string `json:"project_id"`
|
||||
}
|
||||
|
||||
type UserResourceListInput struct {
|
||||
// 查询指定的用户(ID或名称)拥有的资源
|
||||
User string `json:"user"`
|
||||
// swagger:ignore
|
||||
// Deprecated
|
||||
// Filter by userId
|
||||
UserId string `json:"user_id" deprecated-by:"user"`
|
||||
}
|
||||
|
||||
func (input UserResourceListInput) UserStr() string {
|
||||
if len(input.User) > 0 {
|
||||
return input.User
|
||||
}
|
||||
if len(input.UserId) > 0 {
|
||||
return input.UserId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type SharableVirtualResourceCreateInput struct {
|
||||
VirtualResourceCreateInput
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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 logger // import "yunion.io/x/onecloud/pkg/apis/logger"
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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 logger
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type BaremetalEventListInput struct {
|
||||
apis.ModelBaseListInput
|
||||
|
||||
// since
|
||||
Since time.Time `json:"since"`
|
||||
// until
|
||||
Until time.Time `json:"until"`
|
||||
}
|
||||
@@ -26,4 +26,65 @@ type ModelBaseShortDescDetail struct {
|
||||
}
|
||||
|
||||
type ModelBaseListInput struct {
|
||||
Meta
|
||||
|
||||
// 查询限制量
|
||||
// default: 20
|
||||
Limit *int `json:"limit"`
|
||||
// 查询偏移量
|
||||
// default: 0
|
||||
Offset *int `json:"offset"`
|
||||
// 列表排序时,用于排序的字段的名称,该字段不提供时,则按默认字段排序。一般时按照资源的新建时间逆序排序。
|
||||
OrderBy []string `json:"order_by"`
|
||||
// 列表排序时的顺序,desc为从高到低,asc为从低到高。默认是按照资源的创建时间desc排序。
|
||||
// example: desc|asc
|
||||
Order string `json:"order"`
|
||||
// 列表返回资源的更多详细信息。默认只显示基本字段,该字段为true则返回扩展字段信息。
|
||||
Details *bool `json:"details"`
|
||||
// 模糊搜索所有字段
|
||||
Search string `json:"search"`
|
||||
// 指定过滤条件,允许指定多个,每个条件的格式为"字段名称.操作符(匹配信息)",例如name字段等于test的过滤器为:name.equals('test')
|
||||
// 支持的操作符如下:
|
||||
//
|
||||
// | 操作符 | 参数个数 | 举例 | 说明 |
|
||||
// |---------------|---------|------------------------------------------------|-----------------------|
|
||||
// | in | > 0 | name.in("test", "good") | 在给定数组中 |
|
||||
// | notin | > 0 | name.notin('test') | 不在给定数组中 |
|
||||
// | between | 2 | created_at.between('2019-12-10', '2020-01-02') | 在两个值之间 |
|
||||
// | ge | 1 | created_at.ge('2020-01-01') | 大于或等于给定值 |
|
||||
// | gt | 1 | created_at.gt('2020-01-01') | 严格大于给定值 |
|
||||
// | le | 1 | created_at.le('2020-01-01') | 小于或等于给定值 |
|
||||
// | lt | 1 | sync_seconds.lt(900) | 严格大于给定值 |
|
||||
// | like | 1 | name.like('%test%') | sql字符串匹配 |
|
||||
// | contains | 1 | name.contains('test') | 包含给定字符串 |
|
||||
// | startswith | 1 | name.startswith('test') | 以给定字符串开头 |
|
||||
// | endswith | 1 | name.endswith('test') | 以给定字符串结尾 |
|
||||
// | equals | 1 | name.equals('test') | 等于给定值 |
|
||||
// | notequals | 1 | name.notequals('test') | 不等于给定值 |
|
||||
// | isnull | 0 | name.isnull() | 值为SQL的NULL |
|
||||
// | isnotnull | 0 | name.isnotnull() | 值不为SQL的NULL |
|
||||
// | isempty | 0 | name.isempty('test') | 值为空字符串 |
|
||||
// | isnotempty | 0 | name.isnotempty('test') | 值不是空字符串 |
|
||||
// | isnullorempty | 0 | name.isnullorempty('test') | 值为SQL的NULL或者空字符串 |
|
||||
//
|
||||
Filter []string `json:"filter"`
|
||||
// 指定关联过滤条件,允许指定多个,后端将根据关联过滤条件和其他表关联查询,支持的查询语法和filter相同,
|
||||
// 和其他表关联的语法如下:
|
||||
// joint_tbl.related_key(origin_key).filter_col.filter_ops(values)
|
||||
// 其中,joint_tbl为要关联的表,related_key为关联表column,origin_key为当前表column, filter_col为
|
||||
// 关联表用于查询匹配的field名称,field_ops为filter支持的操作,values为匹配的值
|
||||
// 举例:
|
||||
// guestnetworks_tbl.guest_id(id).ip_addr.equals('10.168.21.222')
|
||||
JointFilter []string `json:"joint_filter"`
|
||||
// 如果filter_any为true,则查询所有filter的并集,否则为交集
|
||||
FilterAny *bool `json:"filter_any"`
|
||||
// 返回结果只包含指定的字段
|
||||
Field []string `json:"field"`
|
||||
// 用于数据导出,指定导出的数据字段
|
||||
ExportKeys string `json:"export_keys"`
|
||||
}
|
||||
|
||||
type IncrementalListInput struct {
|
||||
// 用于指定增量加载的标记
|
||||
PagingMarker string `json:"paging_marker"`
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
// 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 apis
|
||||
|
||||
type BaseListInput struct {
|
||||
Meta
|
||||
|
||||
// 查询限制量
|
||||
// default: 20
|
||||
Limit *int `json:"limit"`
|
||||
// 查询偏移量
|
||||
// default: 0
|
||||
Offset *int `json:"offset"`
|
||||
// Name of the field to be ordered by
|
||||
OrderBy []string `json:"order_by"`
|
||||
// List Order
|
||||
// example: desc|asc
|
||||
Order string
|
||||
// Show more details
|
||||
Details *bool `json:"details"`
|
||||
// Filter results by a simple keyword search
|
||||
Search string `json:"search"`
|
||||
// Piggyback metadata information
|
||||
WithMeta *bool `json:"with_meta"`
|
||||
// Filters
|
||||
Filter []string `json:"filters"`
|
||||
// Filters with joint table col; joint_tbl.related_key(origin_key).filter_col.filter_cond(filters)
|
||||
JointFilter []string `json:"joint_filter"`
|
||||
// If true, match if any of the filters matches; otherwise, match if all of the filters match
|
||||
FilterAny *bool `json:"filter_any"`
|
||||
// Is an admin call?
|
||||
Admin *bool `json:"admin"`
|
||||
// Tenant ID or Name
|
||||
Tenant string `json:"tenant"`
|
||||
// Project domain filter
|
||||
ProjectDomain string `json:"project_domain"`
|
||||
// User ID or Name
|
||||
User string `json:"user"`
|
||||
// Show only specified fields
|
||||
Field []string `json:"field"`
|
||||
// Specify query scope, either project, domain or system
|
||||
Scope string `json:"scope"`
|
||||
// Show system resource
|
||||
System *bool `json:"system"`
|
||||
// Show only pending deleted resource
|
||||
PendingDelete *bool `json:"pending_delete"`
|
||||
// Show all resources including pending deleted
|
||||
// TODO: fix this???
|
||||
PendingDeleteAll *bool `json:"-"`
|
||||
// Show all resources including the emulated resources
|
||||
ShowEmulated *bool `json:"show_emulated"`
|
||||
// Export field keys
|
||||
ExportKeys string `json:"export_keys"`
|
||||
|
||||
// Marker for pagination
|
||||
PagingMarker string `json:"paging_marker"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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 apis
|
||||
|
||||
type ResourceBaseListInput struct {
|
||||
ModelBaseListInput
|
||||
}
|
||||
@@ -24,6 +24,18 @@ type SharableVirtualResourceDetails struct {
|
||||
VirtualResourceDetails
|
||||
}
|
||||
|
||||
type SharableResourceListInput struct {
|
||||
// 根据资源是否共享过滤列表
|
||||
IsPublic *bool `json:"is_public"`
|
||||
}
|
||||
|
||||
type SharableVirtualResourceListInput struct {
|
||||
StandaloneResourceListInput
|
||||
VirtualResourceListInput
|
||||
|
||||
// 根据资源的共享范围过滤列表,可能值为:system, domain, project
|
||||
PublicScope string `json:"public_scope"`
|
||||
}
|
||||
|
||||
type AdminSharableVirtualResourceListInput struct {
|
||||
SharableVirtualResourceListInput
|
||||
}
|
||||
|
||||
@@ -22,13 +22,40 @@ type StandaloneResourceShortDescDetail struct {
|
||||
}
|
||||
|
||||
type STag struct {
|
||||
Key string
|
||||
// 标签key
|
||||
Key string
|
||||
// 标签Value
|
||||
Value string
|
||||
}
|
||||
|
||||
type StandaloneResourceListInput struct {
|
||||
ModelBaseListInput
|
||||
ResourceBaseListInput
|
||||
|
||||
Tags []STag `json:"tags"`
|
||||
WithoutUserMeta bool `json:"without_user_meta"`
|
||||
// 通过标签过滤
|
||||
Tags []STag `json:"tags"`
|
||||
// 返回资源的标签不包含特定的用户标签
|
||||
WithoutUserMeta bool `json:"without_user_meta"`
|
||||
// 返回列表数据中包含资源的标签数据(Metadata)
|
||||
WithMeta *bool `json:"with_meta"`
|
||||
// 显示所有的资源,包括模拟的资源
|
||||
ShowEmulated *bool `json:"show_emulated"`
|
||||
|
||||
// 以资源名称过滤列表
|
||||
Names []string `json:"name"`
|
||||
// 以资源ID过滤列表
|
||||
Ids []string `json:"id"`
|
||||
}
|
||||
|
||||
type StatusStandaloneResourceListInput struct {
|
||||
StandaloneResourceListInput
|
||||
|
||||
// 以资源的状态过滤列表
|
||||
Status []string `json:"status"`
|
||||
}
|
||||
|
||||
type EnabledStatusStandaloneResourceListInput struct {
|
||||
StatusStandaloneResourceListInput
|
||||
|
||||
// 以资源是否启用/禁用过滤列表
|
||||
Enabled *bool `json:"enabled"`
|
||||
}
|
||||
|
||||
@@ -17,3 +17,17 @@ package apis
|
||||
type VirtualResourceDetails struct {
|
||||
ModelBaseDetails
|
||||
}
|
||||
|
||||
type VirtualResourceListInput struct {
|
||||
StatusStandaloneResourceListInput
|
||||
|
||||
ProjectizedResourceListInput
|
||||
|
||||
// 列表中包含标记为"系统资源"的资源
|
||||
System *bool `json:"system"`
|
||||
// 是否显示回收站内的资源,默认不显示(对实现了回收站的资源有效,例如主机,磁盘,镜像)
|
||||
PendingDelete *bool `json:"pending_delete"`
|
||||
// 是否显示所有资源,包括回收站和不再回收站的资源
|
||||
// TODO: fix this???
|
||||
PendingDeleteAll *bool `json:"-"`
|
||||
}
|
||||
|
||||
@@ -19,8 +19,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -161,3 +164,11 @@ func (model *SAdminSharableVirtualResourceBase) setInfo(ctx context.Context,
|
||||
func (model *SAdminSharableVirtualResourceBase) GetIAdminSharableVirtualModel() IAdminSharableVirtualModel {
|
||||
return model.GetVirtualObject().(IAdminSharableVirtualModel)
|
||||
}
|
||||
|
||||
func (manager *SAdminSharableVirtualResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input apis.AdminSharableVirtualResourceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SSharableVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, input.SharableVirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SSharableVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -89,3 +90,18 @@ func (manager *SEnabledStatusStandaloneResourceBaseManager) ValidateCreateData(c
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (manager *SEnabledStatusStandaloneResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query apis.EnabledStatusStandaloneResourceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
if query.Enabled != nil {
|
||||
if *query.Enabled {
|
||||
q = q.IsTrue("enabled")
|
||||
} else {
|
||||
q = q.IsFalse("enabled")
|
||||
}
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -123,11 +123,7 @@ func (manager *SModelBaseManager) ValidateListConditions(ctx context.Context, us
|
||||
return query, nil
|
||||
}
|
||||
|
||||
func (manager *SModelBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SModelBaseManager) ListItemFilterV2(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input *apis.ModelBaseListInput) (*sqlchemy.SQuery, error) {
|
||||
func (manager *SModelBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query apis.ModelBaseListInput) (*sqlchemy.SQuery, error) {
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -120,3 +120,11 @@ func (manager *SResourceBaseManager) ValidateCreateData(ctx context.Context, use
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (manager *SResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query apis.ResourceBaseListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SModelBaseManager.ListItemFilter(ctx, q, userCred, query.ModelBaseListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SModelBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -322,3 +322,11 @@ func (manager *SSharableVirtualResourceBaseManager) ValidateCreateData(ctx conte
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (manager *SSharableVirtualResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query apis.SharableVirtualResourceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -135,20 +135,18 @@ func (manager *SStandaloneResourceBaseManager) FetchByIdOrName(userCred mcclient
|
||||
return FetchByIdOrName(manager.GetIStandaloneModelManager(), userCred, idStr)
|
||||
}
|
||||
|
||||
func (manager *SStandaloneResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
input := &apis.StandaloneResourceListInput{}
|
||||
err := query.Unmarshal(input)
|
||||
func (manager *SStandaloneResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input apis.StandaloneResourceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SResourceBaseManager.ListItemFilter(ctx, q, userCred, input.ResourceBaseListInput)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid input error: %v", err)
|
||||
return q, errors.Wrap(err, "SResourceBaseManager.ListItemFilte")
|
||||
}
|
||||
|
||||
return manager.ListItemFilterV2(ctx, q, userCred, input)
|
||||
}
|
||||
if len(input.Names) > 0 {
|
||||
q = q.In("name", input.Names)
|
||||
}
|
||||
|
||||
func (manager *SStandaloneResourceBaseManager) ListItemFilterV2(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input *apis.StandaloneResourceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SResourceBaseManager.ListItemFilterV2(ctx, q, userCred, &input.ModelBaseListInput)
|
||||
if err != nil {
|
||||
return q, err
|
||||
if len(input.Ids) > 0 {
|
||||
q = q.In("id", input.Ids)
|
||||
}
|
||||
|
||||
tags := map[string][]string{}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -100,3 +101,14 @@ func (manager *SStatusStandaloneResourceBaseManager) ValidateCreateData(ctx cont
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (manager *SStatusStandaloneResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query apis.StatusStandaloneResourceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
if len(query.Status) > 0 {
|
||||
q = q.In("status", query.Status)
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -568,3 +568,11 @@ func (manager *SVirtualResourceBaseManager) OrderByExtraFields(ctx context.Conte
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SVirtualResourceBaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query apis.VirtualResourceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/cloudevent"
|
||||
@@ -75,12 +76,25 @@ func (self *SCloudevent) AllowUpdateItem(ctx context.Context, userCred mcclient.
|
||||
return false
|
||||
}
|
||||
|
||||
func (manager *SCloudeventManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input *api.CloudeventListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SModelBaseManager.ListItemFilter(ctx, q, userCred, input.JSON(input))
|
||||
func (manager *SCloudeventManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input api.CloudeventListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SModelBaseManager.ListItemFilter(ctx, q, userCred, input.ModelBaseListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
/* input.Cloudprovider = input.CloudproviderStr()
|
||||
if len(input.Cloudprovider) > 0 {
|
||||
providerObj, err := CloudproviderManager.FetchByIdOrName(userCred, input.Cloudprovider)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudproviderManager.Keyword(), input.Cloudprovider)
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
q = q.Equals("cloudprovider_id", providerObj.GetId())
|
||||
}*/
|
||||
|
||||
if len(input.Providers) > 0 {
|
||||
q = q.In("provider", input.Providers)
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
cnutils "yunion.io/x/onecloud/pkg/cloudnet/utils"
|
||||
@@ -78,9 +79,14 @@ func (man *SIfaceManager) ValidateCreateData(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (man *SIfaceManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
input := apis.StandaloneResourceListInput{}
|
||||
err := query.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "query.Unmarshal")
|
||||
}
|
||||
q, err = man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
|
||||
@@ -115,7 +115,12 @@ func (man *SRouteManager) ValidateCreateData(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (man *SRouteManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
input := apis.StandaloneResourceListInput{}
|
||||
err := query.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q, err = man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -213,9 +213,14 @@ func (man *SRuleManager) ValidateCreateData(ctx context.Context, userCred mcclie
|
||||
}
|
||||
|
||||
func (man *SRuleManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
input := apis.StandaloneResourceListInput{}
|
||||
err := query.Unmarshal(&input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "query.Unmarshal")
|
||||
}
|
||||
q, err = man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
|
||||
@@ -158,10 +158,6 @@ type ICloudProviderFactory interface {
|
||||
IsSupportPrepaidResources() bool
|
||||
NeedSyncSkuFromCloud() bool
|
||||
|
||||
IsSupportObjectStorage() bool
|
||||
IsSupportComputeEngine() bool
|
||||
IsSupportNetworkManage() bool
|
||||
|
||||
IsCloudeventRegional() bool
|
||||
GetMaxCloudEventSyncDays() int
|
||||
GetMaxCloudEventKeepDays() int
|
||||
@@ -375,22 +371,10 @@ func (factory *SPremiseBaseProviderFactory) IsOnPremise() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (factory *SPremiseBaseProviderFactory) IsSupportObjectStorage() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (factory *SPremiseBaseProviderFactory) NeedSyncSkuFromCloud() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (factory *SPremiseBaseProviderFactory) IsSupportComputeEngine() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (factory *SPremiseBaseProviderFactory) IsSupportNetworkManage() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type SPublicCloudBaseProviderFactor struct {
|
||||
baseProviderFactory
|
||||
}
|
||||
@@ -403,22 +387,10 @@ func (factory *SPublicCloudBaseProviderFactor) IsSupportPrepaidResources() bool
|
||||
return true
|
||||
}
|
||||
|
||||
func (factory *SPublicCloudBaseProviderFactor) IsSupportObjectStorage() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (factory *SPublicCloudBaseProviderFactor) NeedSyncSkuFromCloud() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (factory *SPublicCloudBaseProviderFactor) IsSupportComputeEngine() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (factory *SPublicCloudBaseProviderFactor) IsSupportNetworkManage() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type SPrivateCloudBaseProviderFactor struct {
|
||||
baseProviderFactory
|
||||
}
|
||||
@@ -431,18 +403,6 @@ func (factory *SPrivateCloudBaseProviderFactor) IsSupportPrepaidResources() bool
|
||||
return false
|
||||
}
|
||||
|
||||
func (factory *SPrivateCloudBaseProviderFactor) IsSupportObjectStorage() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (factory *SPrivateCloudBaseProviderFactor) NeedSyncSkuFromCloud() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (factory *SPrivateCloudBaseProviderFactor) IsSupportComputeEngine() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (factory *SPrivateCloudBaseProviderFactor) IsSupportNetworkManage() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ const (
|
||||
const (
|
||||
CLOUD_CAPABILITY_PROJECT = "project"
|
||||
CLOUD_CAPABILITY_COMPUTE = "compute"
|
||||
CLOUD_CAPABILITY_NETWORK = "network"
|
||||
CLOUD_CAPABILITY_LOADBALANCER = "loadbalancer"
|
||||
CLOUD_CAPABILITY_OBJECTSTORE = "objectstore"
|
||||
CLOUD_CAPABILITY_RDS = "rds"
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
@@ -274,3 +275,7 @@ func (agent *SBaremetalagent) setStoragecacheId(cacheId string) error {
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (manager *SBaremetalagentManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.BaremetalagentListInput) (*sqlchemy.SQuery, error) {
|
||||
return manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
}
|
||||
|
||||
@@ -576,23 +576,23 @@ func (bucket *SBucket) getCloudProviderInfo() SCloudProviderInfo {
|
||||
return MakeCloudProviderInfo(region, nil, provider)
|
||||
}
|
||||
|
||||
func (manager *SBucketManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*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 = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q = managedResourceFilterByCloudType(q, query, "", nil)
|
||||
|
||||
q, err = managedResourceFilterByDomain(q, query, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = managedResourceFilterByDomain(q, query.DomainizedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByDomain")
|
||||
}
|
||||
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
|
||||
@@ -587,10 +587,10 @@ func (image *SCachedimage) GetCloudprovider() (*SCloudprovider, error) {
|
||||
return cloudprovider, nil
|
||||
}
|
||||
|
||||
func (manager *SCachedimageManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
func (manager *SCachedimageManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.CachedimageListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = managedResourceFilterByAccount(q, query, "id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "id", func() *sqlchemy.SQuery {
|
||||
cachedImages := CachedimageManager.Query().SubQuery()
|
||||
storagecachedImages := StoragecachedimageManager.Query().SubQuery()
|
||||
storageCaches := StoragecacheManager.Query().SubQuery()
|
||||
@@ -601,26 +601,15 @@ func (manager *SCachedimageManager) ListItemFilter(ctx context.Context, q *sqlch
|
||||
return subq
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
|
||||
q = managedResourceFilterByCloudType(q, query, "id", func() *sqlchemy.SQuery {
|
||||
cachedImages := CachedimageManager.Query().SubQuery()
|
||||
storagecachedImages := StoragecachedimageManager.Query().SubQuery()
|
||||
storageCaches := StoragecacheManager.Query().SubQuery()
|
||||
|
||||
subq := cachedImages.Query(cachedImages.Field("id"))
|
||||
subq = subq.Join(storagecachedImages, sqlchemy.Equals(cachedImages.Field("id"), storagecachedImages.Field("cachedimage_id")))
|
||||
subq = subq.Join(storageCaches, sqlchemy.Equals(storagecachedImages.Field("storagecache_id"), storageCaches.Field("id")))
|
||||
return subq
|
||||
})
|
||||
|
||||
q, err = manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByRegion(q, query, "id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "id", func() *sqlchemy.SQuery {
|
||||
storagecachedImages := StoragecachedimageManager.Query().SubQuery()
|
||||
storageCaches := StoragecacheManager.Query().SubQuery()
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
@@ -634,10 +623,10 @@ func (manager *SCachedimageManager) ListItemFilter(ctx context.Context, q *sqlch
|
||||
return subq
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByZone(q, query, "id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByZone(q, query.ZonalFilterListInput, "id", func() *sqlchemy.SQuery {
|
||||
storagecachedImages := StoragecachedimageManager.Query().SubQuery()
|
||||
storageCaches := StoragecacheManager.Query().SubQuery()
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
@@ -649,58 +638,8 @@ func (manager *SCachedimageManager) ListItemFilter(ctx context.Context, q *sqlch
|
||||
return subq
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
|
||||
/*regionStr := jsonutils.GetAnyString(query, []string{"region", "region_id", "cloudregion", "cloudregion_id"})
|
||||
if len(regionStr) > 0 {
|
||||
regionObj, err := CloudregionManager.FetchByIdOrName(nil, regionStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudregionManager.Keyword(), regionStr)
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
cachedImages := CachedimageManager.Query().SubQuery()
|
||||
storagecachedImages := StoragecachedimageManager.Query().SubQuery()
|
||||
storageCaches := StoragecacheManager.Query().SubQuery()
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
zones := ZoneManager.Query().SubQuery()
|
||||
|
||||
subq := cachedImages.Query(cachedImages.Field("id"))
|
||||
subq = subq.Join(storagecachedImages, sqlchemy.Equals(cachedImages.Field("id"), storagecachedImages.Field("cachedimage_id")))
|
||||
subq = subq.Join(storageCaches, sqlchemy.Equals(storagecachedImages.Field("storagecache_id"), storageCaches.Field("id")))
|
||||
subq = subq.Join(storages, sqlchemy.Equals(storageCaches.Field("id"), storages.Field("storagecache_id")))
|
||||
subq = subq.Join(zones, sqlchemy.Equals(storages.Field("zone_id"), zones.Field("id")))
|
||||
subq = subq.Filter(sqlchemy.Equals(zones.Field("cloudregion_id"), regionObj.GetId())).Filter(sqlchemy.Equals(storagecachedImages.Field("status"), api.CACHED_IMAGE_STATUS_READY))
|
||||
|
||||
q = q.Filter(sqlchemy.In(q.Field("id"), subq.SubQuery()))
|
||||
}*/
|
||||
|
||||
/* zoneStr := jsonutils.GetAnyString(query, []string{"zone", "zone_id"})
|
||||
if len(zoneStr) > 0 {
|
||||
zoneObj, err := ZoneManager.FetchByIdOrName(nil, zoneStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(ZoneManager.Keyword(), zoneStr)
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
cachedImages := CachedimageManager.Query().SubQuery()
|
||||
storagecachedImages := StoragecachedimageManager.Query().SubQuery()
|
||||
storageCaches := StoragecacheManager.Query().SubQuery()
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
|
||||
subq := cachedImages.Query(cachedImages.Field("id"))
|
||||
subq = subq.Join(storagecachedImages, sqlchemy.Equals(cachedImages.Field("id"), storagecachedImages.Field("cachedimage_id")))
|
||||
subq = subq.Join(storageCaches, sqlchemy.Equals(storagecachedImages.Field("storagecache_id"), storageCaches.Field("id")))
|
||||
subq = subq.Join(storages, sqlchemy.Equals(storageCaches.Field("id"), storages.Field("storagecache_id")))
|
||||
subq = subq.Filter(sqlchemy.Equals(storages.Field("zone_id"), zoneObj.GetId())).Filter(sqlchemy.Equals(storagecachedImages.Field("status"), api.CACHED_IMAGE_STATUS_READY))
|
||||
|
||||
q = q.Filter(sqlchemy.In(q.Field("id"), subq.SubQuery()))
|
||||
}*/
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
@@ -29,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
@@ -202,118 +202,25 @@ func getDBInstanceInfo(region *SCloudregion, zone *SZone) map[string]map[string]
|
||||
|
||||
// set all brands, compute engine brands, network manage brands, object storage brands
|
||||
func getBrands(region *SCloudregion, zone *SZone, domainId string, capa *SCapabilities) {
|
||||
q := CloudaccountManager.Query()
|
||||
providers := CloudproviderManager.Query().SubQuery()
|
||||
q = q.Join(providers, sqlchemy.Equals(q.Field("id"), providers.Field("cloudaccount_id")))
|
||||
if zone != nil {
|
||||
region = zone.GetRegion()
|
||||
}
|
||||
if region != nil {
|
||||
providerregions := CloudproviderRegionManager.Query().SubQuery()
|
||||
q = q.Join(providerregions, sqlchemy.Equals(providers.Field("id"), providerregions.Field("cloudprovider_id")))
|
||||
q = q.Filter(sqlchemy.Equals(providerregions.Field("cloudregion_id"), region.Id))
|
||||
}
|
||||
if len(domainId) > 0 {
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.AND(
|
||||
sqlchemy.Equals(q.Field("share_mode"), api.CLOUD_ACCOUNT_SHARE_MODE_ACCOUNT_DOMAIN),
|
||||
sqlchemy.Equals(q.Field("domain_id"), domainId),
|
||||
),
|
||||
sqlchemy.Equals(q.Field("share_mode"), api.CLOUD_ACCOUNT_SHARE_MODE_SYSTEM),
|
||||
sqlchemy.AND(
|
||||
sqlchemy.Equals(q.Field("share_mode"), api.CLOUD_ACCOUNT_SHARE_MODE_PROVIDER_DOMAIN),
|
||||
sqlchemy.Equals(providers.Field("domain_id"), domainId),
|
||||
),
|
||||
))
|
||||
}
|
||||
cloudAccounts := make([]SCloudaccount, 0)
|
||||
err := q.All(&cloudAccounts)
|
||||
if err != nil {
|
||||
log.Errorf("get brands failed %s", err)
|
||||
return
|
||||
}
|
||||
capa.Brands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, "")
|
||||
capa.ComputeEngineBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_COMPUTE)
|
||||
capa.NetworkManageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_NETWORK)
|
||||
capa.ObjectStorageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE)
|
||||
|
||||
enabledBrandAccountMap := make(map[string]*SCloudaccount, 0)
|
||||
disabledBrandAccountMap := make(map[string]*SCloudaccount, 0)
|
||||
for i := 0; i < len(cloudAccounts); i++ {
|
||||
if _, ok := enabledBrandAccountMap[cloudAccounts[i].Brand]; ok {
|
||||
continue
|
||||
} else if _, ok := disabledBrandAccountMap[cloudAccounts[i].Brand]; ok {
|
||||
if cloudAccounts[i].Enabled {
|
||||
delete(disabledBrandAccountMap, cloudAccounts[i].Brand)
|
||||
enabledBrandAccountMap[cloudAccounts[i].Brand] = &cloudAccounts[i]
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
if cloudAccounts[i].Enabled {
|
||||
enabledBrandAccountMap[cloudAccounts[i].Brand] = &cloudAccounts[i]
|
||||
} else {
|
||||
disabledBrandAccountMap[cloudAccounts[i].Brand] = &cloudAccounts[i]
|
||||
}
|
||||
}
|
||||
if utils.IsInStringArray(api.HYPERVISOR_KVM, capa.Hypervisors) || utils.IsInStringArray(api.HYPERVISOR_BAREMETAL, capa.Hypervisors) {
|
||||
capa.Brands = append(capa.Brands, api.ONECLOUD_BRAND_ONECLOUD)
|
||||
capa.ComputeEngineBrands = append(capa.ComputeEngineBrands, api.ONECLOUD_BRAND_ONECLOUD)
|
||||
}
|
||||
b, c, n, o := getBrandsFromBrandAccountMap(enabledBrandAccountMap, capa.Hypervisors, true)
|
||||
capa.Brands, capa.ComputeEngineBrands, capa.NetworkManageBrands, capa.ObjectStorageBrands = b, c, n, o
|
||||
b, c, n, o = getBrandsFromBrandAccountMap(disabledBrandAccountMap, capa.Hypervisors, false)
|
||||
capa.DisabledBrands, capa.DisabledComputeEngineBrands, capa.DisabledNetworkManageBrands, capa.DisabledObjectStorageBrands = b, c, n, o
|
||||
capa.NetworkManageBrands = append(capa.NetworkManageBrands, api.ONECLOUD_BRAND_ONECLOUD)
|
||||
|
||||
capa.DisabledBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, "")
|
||||
capa.DisabledComputeEngineBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_COMPUTE)
|
||||
capa.DisabledNetworkManageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_NETWORK)
|
||||
capa.DisabledObjectStorageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getBrandsFromBrandAccountMap(bam map[string]*SCloudaccount, hypervisors []string, enabled bool,
|
||||
) ([]string, []string, []string, []string) {
|
||||
var (
|
||||
brands []string = make([]string, 0)
|
||||
computeEngineBrands []string
|
||||
networkManageBrands []string
|
||||
objectStorageBrands []string
|
||||
)
|
||||
for brand, cloudAccount := range bam {
|
||||
brands = append(brands, brand)
|
||||
factory, err := cloudAccount.GetProviderFactory()
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
continue
|
||||
}
|
||||
if factory.IsSupportComputeEngine() {
|
||||
if computeEngineBrands == nil {
|
||||
computeEngineBrands = make([]string, 0)
|
||||
}
|
||||
computeEngineBrands = append(computeEngineBrands, brand)
|
||||
}
|
||||
if factory.IsSupportNetworkManage() {
|
||||
if networkManageBrands == nil {
|
||||
networkManageBrands = make([]string, 0)
|
||||
}
|
||||
networkManageBrands = append(networkManageBrands, brand)
|
||||
}
|
||||
if factory.IsSupportObjectStorage() {
|
||||
if objectStorageBrands == nil {
|
||||
objectStorageBrands = make([]string, 0)
|
||||
}
|
||||
objectStorageBrands = append(objectStorageBrands, brand)
|
||||
}
|
||||
}
|
||||
|
||||
if enabled {
|
||||
for _, hyper := range api.ONECLOUD_HYPERVISORS {
|
||||
if utils.IsInStringArray(hyper, hypervisors) {
|
||||
brands = append(brands, api.CLOUD_PROVIDER_ONECLOUD)
|
||||
if computeEngineBrands == nil {
|
||||
computeEngineBrands = make([]string, 0)
|
||||
}
|
||||
computeEngineBrands = append(computeEngineBrands, api.CLOUD_PROVIDER_ONECLOUD)
|
||||
if networkManageBrands == nil {
|
||||
networkManageBrands = make([]string, 0)
|
||||
}
|
||||
networkManageBrands = append(networkManageBrands, api.CLOUD_PROVIDER_ONECLOUD)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return brands, computeEngineBrands, networkManageBrands, objectStorageBrands
|
||||
}
|
||||
|
||||
func getHypervisors(region *SCloudregion, zone *SZone, domainId string) []string {
|
||||
q := HostManager.Query("host_type", "manager_id")
|
||||
if region != nil {
|
||||
|
||||
@@ -91,8 +91,6 @@ type SCloudaccount struct {
|
||||
IsPublicCloud tristate.TriState `nullable:"false" get:"user" create:"optional" list:"user" default:"true"`
|
||||
IsOnPremise bool `nullable:"false" get:"user" create:"optional" list:"user" default:"false"`
|
||||
|
||||
HasObjectStorage bool `nullable:"false" get:"user" create:"optional" list:"user" default:"false"`
|
||||
|
||||
Provider string `width:"64" charset:"ascii" list:"domain" create:"domain_required"`
|
||||
|
||||
EnableAutoSync bool `default:"false" create:"domain_optional" list:"domain"`
|
||||
@@ -763,18 +761,6 @@ func (self *SCloudaccount) importSubAccount(ctx context.Context, userCred mcclie
|
||||
return newCloudprovider, isNew, nil
|
||||
}
|
||||
|
||||
//func (self *SCloudaccount) AllowPerformImport(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
// return db.IsAdminAllowPerform(userCred, self, "import")
|
||||
//}
|
||||
|
||||
//func (self *SCloudaccount) PerformImport(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
// autoCreateProject := jsonutils.QueryBoolean(data, "auto_create_project", false)
|
||||
// autoSync := jsonutils.QueryBoolean(data, "auto_sync", false)
|
||||
// err := self.startImportSubAccountTask(ctx, userCred, autoCreateProject, autoSync, "")
|
||||
// noop
|
||||
// return nil, nil
|
||||
//}
|
||||
|
||||
func (manager *SCloudaccountManager) FetchCloudaccountById(accountId string) *SCloudaccount {
|
||||
providerObj, err := manager.FetchById(accountId)
|
||||
if err != nil {
|
||||
@@ -1153,10 +1139,9 @@ func (self *SCloudaccount) PerformChangeProject(ctx context.Context, userCred mc
|
||||
return providers[0].PerformChangeProject(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (manager *SCloudaccountManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
accountStr, _ := query.GetString("account")
|
||||
func (manager *SCloudaccountManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.CloudaccountListInput) (*sqlchemy.SQuery, error) {
|
||||
accountStr := query.Cloudaccount
|
||||
if len(accountStr) > 0 {
|
||||
query.(*jsonutils.JSONDict).Remove("account")
|
||||
accountObj, err := manager.FetchByIdOrName(userCred, accountStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -1168,11 +1153,11 @@ func (manager *SCloudaccountManager) ListItemFilter(ctx context.Context, q *sqlc
|
||||
q = q.Equals("id", accountObj.GetId())
|
||||
}
|
||||
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager")
|
||||
}
|
||||
managerStr, _ := query.GetString("manager")
|
||||
managerStr := query.Cloudprovider
|
||||
if len(managerStr) > 0 {
|
||||
providerObj, err := CloudproviderManager.FetchByIdOrName(userCred, managerStr)
|
||||
if err != nil {
|
||||
@@ -1186,19 +1171,29 @@ func (manager *SCloudaccountManager) ListItemFilter(ctx context.Context, q *sqlc
|
||||
q = q.Equals("id", provider.CloudaccountId)
|
||||
}
|
||||
|
||||
cloudEnvStr, _ := query.GetString("cloud_env")
|
||||
if cloudEnvStr == api.CLOUD_ENV_PUBLIC_CLOUD || jsonutils.QueryBoolean(query, "public_cloud", false) {
|
||||
cloudEnvStr := query.CloudEnv
|
||||
if cloudEnvStr == api.CLOUD_ENV_PUBLIC_CLOUD {
|
||||
q = q.IsTrue("is_public_cloud").IsFalse("is_on_premise")
|
||||
}
|
||||
|
||||
if cloudEnvStr == api.CLOUD_ENV_PRIVATE_CLOUD || jsonutils.QueryBoolean(query, "private_cloud", false) {
|
||||
if cloudEnvStr == api.CLOUD_ENV_PRIVATE_CLOUD {
|
||||
q = q.IsFalse("is_public_cloud").IsFalse("is_on_premise")
|
||||
}
|
||||
|
||||
if cloudEnvStr == api.CLOUD_ENV_ON_PREMISE || jsonutils.QueryBoolean(query, "is_on_premise", false) {
|
||||
if cloudEnvStr == api.CLOUD_ENV_ON_PREMISE {
|
||||
q = q.IsTrue("is_on_premise").IsFalse("is_public_cloud")
|
||||
}
|
||||
|
||||
capabilities := query.Capability
|
||||
if len(capabilities) > 0 {
|
||||
cloudproviders := CloudproviderManager.Query().SubQuery()
|
||||
cloudprovidercapabilities := CloudproviderCapabilityManager.Query().SubQuery()
|
||||
subq := cloudproviders.Query(cloudproviders.Field("cloudaccount_id"))
|
||||
subq = subq.Join(cloudprovidercapabilities, sqlchemy.Equals(cloudprovidercapabilities.Field("cloudprovider_id"), cloudproviders.Field("id")))
|
||||
subq = subq.Filter(sqlchemy.In(cloudprovidercapabilities.Field("capability"), capabilities))
|
||||
q = q.In("id", subq.SubQuery())
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -1409,7 +1404,6 @@ func (account *SCloudaccount) probeAccountStatus(ctx context.Context, userCred m
|
||||
isPublic := factory.IsPublicCloud()
|
||||
account.IsPublicCloud = tristate.NewFromBool(isPublic)
|
||||
account.IsOnPremise = factory.IsOnPremise()
|
||||
account.HasObjectStorage = factory.IsSupportObjectStorage()
|
||||
account.Balance = balance
|
||||
if !options.Options.CloudaccountHealthStatusCheck {
|
||||
status = api.CLOUD_PROVIDER_HEALTH_NORMAL
|
||||
@@ -1787,3 +1781,64 @@ func (account *SCloudaccount) PerformSyncSkus(ctx context.Context, userCred mccl
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (manager *SCloudaccountManager) queryCloudAccountByCapability(region *SCloudregion, zone *SZone, domainId string, enabled tristate.TriState, capability string) *sqlchemy.SQuery {
|
||||
providers := CloudproviderManager.Query().SubQuery()
|
||||
q := manager.Query()
|
||||
q = q.Join(providers, sqlchemy.Equals(q.Field("id"), providers.Field("cloudaccount_id")))
|
||||
if len(capability) > 0 {
|
||||
cloudproviderCapabilities := CloudproviderCapabilityManager.Query().SubQuery()
|
||||
q = q.Join(cloudproviderCapabilities, sqlchemy.Equals(providers.Field("id"), cloudproviderCapabilities.Field("cloudprovider_id")))
|
||||
q = q.Filter(sqlchemy.Equals(cloudproviderCapabilities.Field("capability"), capability))
|
||||
}
|
||||
if enabled.IsTrue() {
|
||||
q = q.IsTrue("enabled")
|
||||
} else if enabled.IsFalse() {
|
||||
q = q.IsFalse("enabled")
|
||||
}
|
||||
if zone != nil {
|
||||
region = zone.GetRegion()
|
||||
}
|
||||
if region != nil {
|
||||
providerregions := CloudproviderRegionManager.Query().SubQuery()
|
||||
q = q.Join(providerregions, sqlchemy.Equals(providers.Field("id"), providerregions.Field("cloudprovider_id")))
|
||||
q = q.Filter(sqlchemy.Equals(providerregions.Field("cloudregion_id"), region.Id))
|
||||
}
|
||||
if len(domainId) > 0 {
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.AND(
|
||||
sqlchemy.Equals(q.Field("share_mode"), api.CLOUD_ACCOUNT_SHARE_MODE_ACCOUNT_DOMAIN),
|
||||
sqlchemy.Equals(q.Field("domain_id"), domainId),
|
||||
),
|
||||
sqlchemy.Equals(q.Field("share_mode"), api.CLOUD_ACCOUNT_SHARE_MODE_SYSTEM),
|
||||
sqlchemy.AND(
|
||||
sqlchemy.Equals(q.Field("share_mode"), api.CLOUD_ACCOUNT_SHARE_MODE_PROVIDER_DOMAIN),
|
||||
sqlchemy.Equals(providers.Field("domain_id"), domainId),
|
||||
),
|
||||
))
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (manager *SCloudaccountManager) getBrandsOfCapability(region *SCloudregion, zone *SZone, domainId string, enabled tristate.TriState, capability string) ([]string, error) {
|
||||
subq := manager.queryCloudAccountByCapability(region, zone, domainId, enabled, capability).SubQuery()
|
||||
q := subq.Query(subq.Field("brand")).Distinct()
|
||||
rows, err := q.Rows()
|
||||
if err != nil {
|
||||
if errors.Cause(err) != sql.ErrNoRows {
|
||||
return nil, errors.Wrap(err, "rows")
|
||||
}
|
||||
return []string{}, nil
|
||||
}
|
||||
ret := make([]string, 0)
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var brand string
|
||||
err := rows.Scan(&brand)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "rows.Scan")
|
||||
}
|
||||
ret = append(ret, brand)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
// 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"
|
||||
"sort"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
type SCloudproviderCapabilityManager struct {
|
||||
db.SResourceBaseManager
|
||||
}
|
||||
|
||||
var CloudproviderCapabilityManager *SCloudproviderCapabilityManager
|
||||
|
||||
func init() {
|
||||
CloudproviderCapabilityManager = &SCloudproviderCapabilityManager{
|
||||
SResourceBaseManager: db.NewResourceBaseManager(
|
||||
SCloudproviderCapability{},
|
||||
"cloudprovider_capabilities_tbl",
|
||||
"cloudprovider_capability",
|
||||
"cloudprovider_capabilities",
|
||||
),
|
||||
}
|
||||
CloudproviderCapabilityManager.SetVirtualObject(CloudproviderCapabilityManager)
|
||||
}
|
||||
|
||||
type SCloudproviderCapability struct {
|
||||
db.SResourceBase
|
||||
|
||||
CloudproviderId string `width:"36" charset:"ascii" nullable:"false" primary:"true"`
|
||||
Capability string `width:"18" charset:"ascii" nullable:"false" primary:"true"`
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderCapabilityManager) setCapabilities(ctx context.Context, userCred mcclient.TokenCredential, cloudproviderId string, capabilities []string) error {
|
||||
oldCapabilities, err := manager.getCapabilities(cloudproviderId)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "manager.getCapabilities")
|
||||
}
|
||||
oldCapas := stringutils2.NewSortedStrings(oldCapabilities)
|
||||
newCapas := stringutils2.NewSortedStrings(capabilities)
|
||||
deleted, _, added := stringutils2.Split(oldCapas, newCapas)
|
||||
|
||||
cpc := SCloudproviderCapability{
|
||||
CloudproviderId: cloudproviderId,
|
||||
}
|
||||
cpc.SetModelManager(manager, &cpc)
|
||||
|
||||
for _, capability := range added {
|
||||
cpc.Capability = capability
|
||||
err := manager.TableSpec().InsertOrUpdate(&cpc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "manager.TableSpec().InsertOrUpdate")
|
||||
}
|
||||
}
|
||||
for _, capability := range deleted {
|
||||
cpc.Capability = capability
|
||||
err := cpc.Delete(ctx, userCred)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cpc.Delete")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderCapabilityManager) getCapabilities(cloudproviderId string) ([]string, error) {
|
||||
q := manager.Query().Equals("cloudprovider_id", cloudproviderId)
|
||||
capabilities := make([]SCloudproviderCapability, 0)
|
||||
err := db.FetchModelObjects(manager, q, &capabilities)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "db.FetchModelObjects")
|
||||
}
|
||||
capaStrs := make([]string, len(capabilities))
|
||||
for i := range capabilities {
|
||||
capaStrs[i] = capabilities[i].Capability
|
||||
}
|
||||
sort.Strings(capaStrs)
|
||||
return capaStrs, nil
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderCapabilityManager) removeCapabilities(ctx context.Context, userCred mcclient.TokenCredential, cloudproviderId string) error {
|
||||
return manager.setCapabilities(ctx, userCred, cloudproviderId, []string{})
|
||||
}
|
||||
@@ -139,6 +139,10 @@ func (manager *SCloudproviderManager) GetOnPremiseProviderIdsQuery() *sqlchemy.S
|
||||
return manager.GetProviderIdsQuery(tristate.None, tristate.True, nil, nil)
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) GetPrivateOrOnPremiseProviderIdsQuery() *sqlchemy.SSubQuery {
|
||||
return manager.GetProviderIdsQuery(tristate.False, tristate.None, nil, nil)
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) GetProviderIdsQuery(isPublic tristate.TriState, isOnPremise tristate.TriState, providers []string, brands []string) *sqlchemy.SSubQuery {
|
||||
return manager.GetProviderFieldQuery("id", isPublic, isOnPremise, providers, brands)
|
||||
}
|
||||
@@ -870,6 +874,10 @@ func (self *SCloudprovider) getMoreDetails(ctx context.Context, extra *jsonutils
|
||||
extra.Add(jsonutils.NewString(account.GetName()), "cloudaccount")
|
||||
}
|
||||
extra.Set("sync_status2", jsonutils.NewString(self.getSyncStatus2()))
|
||||
capabilities, _ := CloudproviderCapabilityManager.getCapabilities(self.Id)
|
||||
if len(capabilities) > 0 {
|
||||
extra.Add(jsonutils.NewStringArray(capabilities), "capabilities")
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
@@ -963,11 +971,9 @@ func (manager *SCloudproviderManager) migrateVCenterInfo(vc *SVCenter) error {
|
||||
return manager.TableSpec().Insert(&cp)
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
accountStr, _ := query.GetString("account")
|
||||
func (manager *SCloudproviderManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.CloudproviderListInput) (*sqlchemy.SQuery, error) {
|
||||
accountStr := query.Cloudaccount
|
||||
if len(accountStr) > 0 {
|
||||
queryDict := query.(*jsonutils.JSONDict)
|
||||
queryDict.Remove("account")
|
||||
accountObj, err := CloudaccountManager.FetchByIdOrName(userCred, accountStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -979,7 +985,7 @@ func (manager *SCloudproviderManager) ListItemFilter(ctx context.Context, q *sql
|
||||
q = q.Equals("cloudaccount_id", accountObj.GetId())
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "usable", false) {
|
||||
if query.Usable != nil && *query.Usable {
|
||||
providers := CloudproviderManager.Query().SubQuery()
|
||||
networks := NetworkManager.Query().SubQuery()
|
||||
wires := WireManager.Query().SubQuery()
|
||||
@@ -1009,11 +1015,11 @@ func (manager *SCloudproviderManager) ListItemFilter(ctx context.Context, q *sql
|
||||
))
|
||||
}
|
||||
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
managerStr, _ := query.GetString("manager")
|
||||
managerStr := query.Cloudprovider
|
||||
if len(managerStr) > 0 {
|
||||
providerObj, err := manager.FetchByIdOrName(userCred, managerStr)
|
||||
if err != nil {
|
||||
@@ -1026,37 +1032,32 @@ func (manager *SCloudproviderManager) ListItemFilter(ctx context.Context, q *sql
|
||||
q = q.Equals("id", providerObj.GetId())
|
||||
}
|
||||
|
||||
cloudEnvStr, _ := query.GetString("cloud_env")
|
||||
if cloudEnvStr == api.CLOUD_ENV_PUBLIC_CLOUD || jsonutils.QueryBoolean(query, "public_cloud", false) {
|
||||
cloudEnvStr := query.CloudEnv
|
||||
if cloudEnvStr == api.CLOUD_ENV_PUBLIC_CLOUD {
|
||||
cloudaccounts := CloudaccountManager.Query().SubQuery()
|
||||
q = q.Join(cloudaccounts, sqlchemy.Equals(cloudaccounts.Field("id"), q.Field("cloudaccount_id")))
|
||||
q = q.Filter(sqlchemy.IsTrue(cloudaccounts.Field("is_public_cloud")))
|
||||
q = q.Filter(sqlchemy.IsFalse(cloudaccounts.Field("is_on_premise")))
|
||||
}
|
||||
|
||||
if cloudEnvStr == api.CLOUD_ENV_PRIVATE_CLOUD || jsonutils.QueryBoolean(query, "private_cloud", false) {
|
||||
if cloudEnvStr == api.CLOUD_ENV_PRIVATE_CLOUD {
|
||||
cloudaccounts := CloudaccountManager.Query().SubQuery()
|
||||
q = q.Join(cloudaccounts, sqlchemy.Equals(cloudaccounts.Field("id"), q.Field("cloudaccount_id")))
|
||||
q = q.Filter(sqlchemy.IsFalse(cloudaccounts.Field("is_public_cloud")))
|
||||
q = q.Filter(sqlchemy.IsFalse(cloudaccounts.Field("is_on_premise")))
|
||||
}
|
||||
|
||||
if cloudEnvStr == api.CLOUD_ENV_ON_PREMISE || jsonutils.QueryBoolean(query, "is_on_premise", false) {
|
||||
if cloudEnvStr == api.CLOUD_ENV_ON_PREMISE {
|
||||
cloudaccounts := CloudaccountManager.Query().SubQuery()
|
||||
q = q.Join(cloudaccounts, sqlchemy.Equals(cloudaccounts.Field("id"), q.Field("cloudaccount_id")))
|
||||
q = q.Filter(sqlchemy.IsFalse(cloudaccounts.Field("is_public_cloud")))
|
||||
q = q.Filter(sqlchemy.IsTrue(cloudaccounts.Field("is_on_premise")))
|
||||
}
|
||||
|
||||
if query.Contains("has_object_storage") {
|
||||
hasObjectStorage, _ := query.Bool("has_object_storage")
|
||||
cloudaccounts := CloudaccountManager.Query().SubQuery()
|
||||
q = q.Join(cloudaccounts, sqlchemy.Equals(cloudaccounts.Field("id"), q.Field("cloudaccount_id")))
|
||||
if hasObjectStorage {
|
||||
q = q.Filter(sqlchemy.IsTrue(cloudaccounts.Field("has_object_storage")))
|
||||
} else {
|
||||
q = q.Filter(sqlchemy.IsFalse(cloudaccounts.Field("has_object_storage")))
|
||||
}
|
||||
capabilities := query.Capability
|
||||
if len(capabilities) > 0 {
|
||||
subq := CloudproviderCapabilityManager.Query("cloudprovider_id").In("capability", capabilities).Distinct().SubQuery()
|
||||
q = q.In("id", subq)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
@@ -1092,7 +1093,11 @@ func (provider *SCloudprovider) markProviderConnected(ctx context.Context, userC
|
||||
func (provider *SCloudprovider) prepareCloudproviderRegions(ctx context.Context, userCred mcclient.TokenCredential) ([]SCloudproviderregion, error) {
|
||||
driver, err := provider.GetProvider()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "provider.GetProvider")
|
||||
}
|
||||
err = CloudproviderCapabilityManager.setCapabilities(ctx, userCred, provider.Id, driver.GetCapabilities())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CloudproviderCapabilityManager.setCapabilities")
|
||||
}
|
||||
if driver.GetFactory().IsOnPremise() {
|
||||
cpr := CloudproviderRegionManager.FetchByIdsOrCreate(provider.Id, api.DEFAULT_REGION_ID)
|
||||
@@ -1199,6 +1204,8 @@ func (self *SCloudprovider) RealDelete(ctx context.Context, userCred mcclient.To
|
||||
log.Debugf("%s purgeall success!", manager.Keyword())
|
||||
}
|
||||
|
||||
CloudproviderCapabilityManager.removeCapabilities(ctx, userCred, self.Id)
|
||||
|
||||
return self.SEnabledStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
|
||||
@@ -579,36 +579,34 @@ func queryCloudregionIdsByProviders(providerField string, providerStrs []string)
|
||||
return q
|
||||
}
|
||||
|
||||
func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
providerStrs := jsonutils.GetQueryStringArray(query, "provider")
|
||||
func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.CloudregionListInput) (*sqlchemy.SQuery, error) {
|
||||
providerStrs := query.Providers
|
||||
if len(providerStrs) > 0 {
|
||||
query.(*jsonutils.JSONDict).Remove("provider")
|
||||
subq := queryCloudregionIdsByProviders("provider", providerStrs)
|
||||
q = q.In("id", subq.SubQuery())
|
||||
}
|
||||
|
||||
brandStrs := jsonutils.GetQueryStringArray(query, "brand")
|
||||
brandStrs := query.Brands
|
||||
if len(brandStrs) > 0 {
|
||||
query.(*jsonutils.JSONDict).Remove("brand")
|
||||
subq := queryCloudregionIdsByProviders("brand", brandStrs)
|
||||
q = q.In("id", subq.SubQuery())
|
||||
}
|
||||
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
cloudEnvStr, _ := query.GetString("cloud_env")
|
||||
if cloudEnvStr == api.CLOUD_ENV_PUBLIC_CLOUD || jsonutils.QueryBoolean(query, "is_public", false) || jsonutils.QueryBoolean(query, "public_cloud", false) {
|
||||
cloudEnvStr := query.CloudEnv
|
||||
if cloudEnvStr == api.CLOUD_ENV_PUBLIC_CLOUD {
|
||||
q = q.In("provider", cloudprovider.GetPublicProviders())
|
||||
}
|
||||
|
||||
if cloudEnvStr == api.CLOUD_ENV_PRIVATE_CLOUD || jsonutils.QueryBoolean(query, "is_private", false) || jsonutils.QueryBoolean(query, "private_cloud", false) {
|
||||
if cloudEnvStr == api.CLOUD_ENV_PRIVATE_CLOUD {
|
||||
q = q.In("provider", cloudprovider.GetPrivateProviders())
|
||||
}
|
||||
|
||||
if cloudEnvStr == api.CLOUD_ENV_ON_PREMISE || jsonutils.QueryBoolean(query, "is_on_premise", false) {
|
||||
if cloudEnvStr == api.CLOUD_ENV_ON_PREMISE {
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.In(q.Field("provider"), cloudprovider.GetOnPremiseProviders()),
|
||||
sqlchemy.Equals(q.Field("provider"), api.CLOUD_PROVIDER_ONECLOUD),
|
||||
@@ -623,35 +621,34 @@ func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlch
|
||||
))
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "is_managed", false) {
|
||||
if query.IsManaged {
|
||||
q = q.IsNotEmpty("external_id")
|
||||
}
|
||||
|
||||
managerStr, _ := query.GetString("manager")
|
||||
managerStr := query.Cloudprovider
|
||||
if len(managerStr) > 0 {
|
||||
subq := CloudproviderRegionManager.QueryRelatedRegionIds("", managerStr)
|
||||
q = q.In("id", subq)
|
||||
}
|
||||
accountStr, _ := query.GetString("account")
|
||||
accountStr := query.Cloudaccount
|
||||
if len(accountStr) > 0 {
|
||||
subq := CloudproviderRegionManager.QueryRelatedRegionIds(accountStr)
|
||||
q = q.In("id", subq)
|
||||
}
|
||||
|
||||
domainId, err := db.FetchQueryDomain(ctx, userCred, query)
|
||||
domainId, err := db.FetchQueryDomain(ctx, userCred, jsonutils.Marshal(query))
|
||||
if len(domainId) > 0 {
|
||||
q = q.In("id", getCloudRegionIdByDomainId(domainId))
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "usable", false) || jsonutils.QueryBoolean(query, "usable_vpc", false) {
|
||||
usableNet := (query.Usable != nil && *query.Usable)
|
||||
usableVpc := (query.UsableVpc != nil && *query.UsableVpc)
|
||||
if usableNet || usableVpc {
|
||||
providers := CloudproviderManager.Query().SubQuery()
|
||||
networks := NetworkManager.Query().SubQuery()
|
||||
wires := WireManager.Query().SubQuery()
|
||||
vpcs := VpcManager.Query().SubQuery()
|
||||
|
||||
usableNet := jsonutils.QueryBoolean(query, "usable", false)
|
||||
usableVpc := jsonutils.QueryBoolean(query, "usable_vpc", false)
|
||||
|
||||
sq := vpcs.Query(sqlchemy.DISTINCT("cloudregion_id", vpcs.Field("cloudregion_id")))
|
||||
if usableNet {
|
||||
sq = sq.Join(wires, sqlchemy.Equals(vpcs.Field("id"), wires.Field("vpc_id")))
|
||||
@@ -684,7 +681,7 @@ func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlch
|
||||
sqlchemy.In(q.Field("id"), sq2.SubQuery()),
|
||||
))
|
||||
|
||||
service, _ := query.GetString("service")
|
||||
service := query.Service
|
||||
switch service {
|
||||
case DBInstanceManager.KeywordPlural():
|
||||
skusSQ := DBInstanceSkuManager.Query("cloudregion_id").Equals("status", api.DBINSTANCE_SKU_AVAILABLE).IsTrue("enabled").SubQuery()
|
||||
@@ -699,10 +696,11 @@ func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlch
|
||||
}
|
||||
}
|
||||
|
||||
cityStr, _ := query.GetString("city")
|
||||
cityStr := query.City
|
||||
if cityStr == "Other" {
|
||||
q = q.IsNullOrEmpty("city")
|
||||
query.(*jsonutils.JSONDict).Remove("city")
|
||||
} else if len(cityStr) > 0 {
|
||||
q = q.Equals("city", cityStr)
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ func (self *SDBInstanceAccount) GetExtraDetails(ctx context.Context, userCred mc
|
||||
return self.getMoreDetails(ctx, userCred, extra)
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceAccountManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (manager *SDBInstanceAccountManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstanceAccountListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "dbinstance", ModelKeyword: "dbinstance", OwnerId: userCred},
|
||||
})
|
||||
|
||||
@@ -97,28 +97,30 @@ func (self *SDBInstanceBackup) AllowDeleteItem(ctx context.Context, userCred mcc
|
||||
return db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceBackupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (manager *SDBInstanceBackupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstanceBackupListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
|
||||
q = managedResourceFilterByCloudType(q, query, "", nil)
|
||||
|
||||
q, err = managedResourceFilterByDomain(q, query, "", nil)
|
||||
q, err = managedResourceFilterByDomain(q, query.DomainizedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByDomain")
|
||||
}
|
||||
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "dbinstance", ModelKeyword: "dbinstance", OwnerId: userCred},
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -131,12 +131,12 @@ func (self *SDBInstanceDatabase) AllowDeleteItem(ctx context.Context, userCred m
|
||||
return db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceDatabaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (manager *SDBInstanceDatabaseManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstanceDatabaseListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "dbinstance", ModelKeyword: "dbinstance", OwnerId: userCred},
|
||||
})
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
@@ -84,12 +85,12 @@ func (self *SDBInstanceParameter) AllowDeleteItem(ctx context.Context, userCred
|
||||
return db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceParameterManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (manager *SDBInstanceParameterManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstanceParameterListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "dbinstance", ModelKeyword: "dbinstance", OwnerId: userCred},
|
||||
})
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
@@ -123,12 +124,12 @@ func (self *SDBInstancePrivilege) GetDetailedJson() (*jsonutils.JSONDict, error)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (manager *SDBInstancePrivilegeManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
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, err
|
||||
return nil, errors.Wrap(err, "SResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "dbinstanceaccount", ModelKeyword: "dbinstanceaccount", OwnerId: userCred},
|
||||
{Key: "dbinstancedatabase", ModelKeyword: "dbinstancedatabase", OwnerId: userCred},
|
||||
|
||||
@@ -27,9 +27,9 @@ import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -108,18 +108,31 @@ func (manager *SDBInstanceSkuManager) fetchDBInstanceSkus(provider string, regio
|
||||
return skus, nil
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceSkuManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (manager *SDBInstanceSkuManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstanceSkuListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
|
||||
q = listItemDomainFilter(q, data)
|
||||
if domainStr := query.ProjectDomain; len(domainStr) > 0 {
|
||||
domain, err := db.TenantCacheManager.FetchDomainByIdOrName(context.Background(), domainStr)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2("domains", domainStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
query.ProjectDomain = domain.GetId()
|
||||
}
|
||||
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
})
|
||||
q = listItemDomainFilter(q, query.Providers, query.ProjectDomain)
|
||||
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceSkuManager) GetDBStringArray(q *sqlchemy.SQuery) ([]string, error) {
|
||||
@@ -146,9 +159,14 @@ func (manager *SDBInstanceSkuManager) AllowGetPropertyInstanceSpecs(ctx context.
|
||||
}
|
||||
|
||||
func (manager *SDBInstanceSkuManager) GetPropertyInstanceSpecs(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
q, err := manager.ListItemFilter(ctx, manager.Query(), userCred, query)
|
||||
listQuery := api.DBInstanceSkuListInput{}
|
||||
err := query.Unmarshal(&listQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "query.Unmarshal")
|
||||
}
|
||||
q, err := manager.ListItemFilter(ctx, manager.Query(), userCred, listQuery)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "manager.ListItemFilter")
|
||||
}
|
||||
|
||||
input := &SDBInstanceSku{}
|
||||
|
||||
@@ -124,32 +124,37 @@ func (self *SDBInstance) AllowDeleteItem(ctx context.Context, userCred mcclient.
|
||||
return db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (man *SDBInstanceManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SDBInstanceManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DBInstanceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "vpc", ModelKeyword: "vpc", OwnerId: userCred},
|
||||
{Key: "zone", ModelKeyword: "zone", OwnerId: userCred},
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
|
||||
q = managedResourceFilterByCloudType(q, query, "", nil)
|
||||
|
||||
q, err = managedResourceFilterByDomain(q, query, "", nil)
|
||||
q, err = managedResourceFilterByDomain(q, query.DomainizedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByDomain")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByZone(q, query.ZonalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
+15
-99
@@ -113,25 +113,17 @@ func (manager *SDiskManager) FetchDiskById(diskId string) *SDisk {
|
||||
return disk.(*SDisk)
|
||||
}
|
||||
|
||||
func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
queryDict, ok := query.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid querystring format")
|
||||
}
|
||||
|
||||
func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DiskListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
storages := StorageManager.Query().SubQuery()
|
||||
q, err = managedResourceFilterByAccount(q, query, "storage_id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "storage_id", func() *sqlchemy.SQuery {
|
||||
return storages.Query(storages.Field("id"))
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
q = managedResourceFilterByCloudType(q, query, "storage_id", func() *sqlchemy.SQuery {
|
||||
return storages.Query(storages.Field("id"))
|
||||
})
|
||||
|
||||
billingTypeStr, _ := queryDict.GetString("billing_type")
|
||||
billingTypeStr := query.BillingType
|
||||
if len(billingTypeStr) > 0 {
|
||||
if billingTypeStr == billing_api.BILLING_TYPE_POSTPAID {
|
||||
q = q.Filter(
|
||||
@@ -143,71 +135,35 @@ func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
} else {
|
||||
q = q.Equals("billing_type", billingTypeStr)
|
||||
}
|
||||
queryDict.Remove("billing_type")
|
||||
}
|
||||
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if query.Contains("unused") {
|
||||
if query.Unused != nil {
|
||||
guestdisks := GuestdiskManager.Query().SubQuery()
|
||||
sq := guestdisks.Query(guestdisks.Field("disk_id"))
|
||||
if jsonutils.QueryBoolean(query, "unused", false) {
|
||||
if *query.Unused {
|
||||
q = q.Filter(sqlchemy.NotIn(q.Field("id"), sq))
|
||||
} else {
|
||||
q = q.Filter(sqlchemy.In(q.Field("id"), sq))
|
||||
}
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "share", false) {
|
||||
if query.Share != nil && *query.Share {
|
||||
sq := storages.Query(storages.Field("id")).Filter(sqlchemy.NotIn(storages.Field("storage_type"), api.STORAGE_LOCAL_TYPES))
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
|
||||
}
|
||||
|
||||
/*if jsonutils.QueryBoolean(query, "public_cloud", false) {
|
||||
sq :=
|
||||
sq = sq.Filter(sqlchemy.In(storages.Field("manager_id"), CloudproviderManager.GetPublicProviderIdsQuery()))
|
||||
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "private_cloud", false) {
|
||||
sq := storages.Query(storages.Field("id"))
|
||||
sq = sq.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.In(storages.Field("manager_id"), CloudproviderManager.GetPrivateProviderIdsQuery()),
|
||||
sqlchemy.IsNullOrEmpty(storages.Field("manager_id")),
|
||||
),
|
||||
)
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "is_on_premise", false) {
|
||||
sq := storages.Query(storages.Field("id"))
|
||||
sq = sq.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.In(storages.Field("manager_id"), CloudproviderManager.GetOnPremiseProviderIdsQuery()),
|
||||
sqlchemy.IsNullOrEmpty(storages.Field("manager_id")),
|
||||
),
|
||||
)
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "is_managed", false) {
|
||||
sq := storages.Query(storages.Field("id"))
|
||||
sq = sq.Filter(sqlchemy.IsNotEmpty(storages.Field("manager_id")))
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
|
||||
}*/
|
||||
|
||||
if jsonutils.QueryBoolean(query, "local", false) {
|
||||
if query.Local != nil && *query.Local {
|
||||
sq := storages.Query(storages.Field("id")).Filter(sqlchemy.In(storages.Field("storage_type"), api.STORAGE_LOCAL_TYPES))
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq))
|
||||
}
|
||||
|
||||
guestId, _ := queryDict.GetString("guest")
|
||||
if len(guestId) != 0 {
|
||||
guestId := query.Server
|
||||
if len(guestId) > 0 {
|
||||
iGuest, err := GuestManager.FetchByIdOrName(userCred, guestId)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("guest %q not found", guestId)
|
||||
@@ -222,7 +178,7 @@ func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
))
|
||||
}
|
||||
|
||||
storageStr := jsonutils.GetAnyString(queryDict, []string{"storage", "storage_id"})
|
||||
storageStr := query.Storage
|
||||
if len(storageStr) > 0 {
|
||||
storageObj, err := StorageManager.FetchByIdOrName(userCred, storageStr)
|
||||
if err != nil {
|
||||
@@ -231,52 +187,12 @@ func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("storage_id"), storageObj.GetId()))
|
||||
}
|
||||
|
||||
/* managerStr := jsonutils.GetAnyString(query, []string{"manager", "cloudprovider", "cloudprovider_id", "manager_id"})
|
||||
if len(managerStr) > 0 {
|
||||
provider, err := CloudproviderManager.FetchByIdOrName(nil, managerStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudproviderManager.Keyword(), managerStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
subq := storages.Query(storages.Field("id")).Equals("manager_id", provider.GetId())
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), subq.SubQuery()))
|
||||
}
|
||||
|
||||
accountStr := jsonutils.GetAnyString(query, []string{"account", "account_id", "cloudaccount", "cloudaccount_id"})
|
||||
if len(accountStr) > 0 {
|
||||
account, err := CloudaccountManager.FetchByIdOrName(nil, accountStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudaccountManager.Keyword(), accountStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
cloudproviders := CloudproviderManager.Query().SubQuery()
|
||||
subq := storages.Query(storages.Field("id"))
|
||||
subq = subq.Join(cloudproviders, sqlchemy.Equals(cloudproviders.Field("id"), storages.Field("manager_id")))
|
||||
subq = subq.Filter(sqlchemy.Equals(cloudproviders.Field("cloudaccount_id"), account.GetId()))
|
||||
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), subq.SubQuery()))
|
||||
}
|
||||
|
||||
if provier, _ := queryDict.GetString("provider"); len(provier) > 0 {
|
||||
cloudproviders := CloudproviderManager.Query().SubQuery()
|
||||
sq := storages.Query(storages.Field("id"))
|
||||
sq = sq.Join(cloudproviders, sqlchemy.Equals(cloudproviders.Field("id"), storages.Field("manager_id")))
|
||||
sq = sq.Filter(sqlchemy.Equals(cloudproviders.Field("provider"), provier))
|
||||
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq.SubQuery()))
|
||||
}*/
|
||||
|
||||
if diskType := jsonutils.GetAnyString(query, []string{"type", "disk_type"}); diskType != "" {
|
||||
if diskType := query.DiskType; diskType != "" {
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("disk_type"), diskType))
|
||||
}
|
||||
|
||||
// for snapshotpolicy_id
|
||||
snapshotpolicyStr := jsonutils.GetAnyString(queryDict, []string{"snapshotpolicy", "snapshotpolicy_id"})
|
||||
snapshotpolicyStr := query.Snapshotpolicy
|
||||
if len(snapshotpolicyStr) > 0 {
|
||||
snapshotpolicyObj, err := SnapshotPolicyManager.FetchByIdOrName(userCred, snapshotpolicyStr)
|
||||
if err != nil {
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"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"
|
||||
@@ -486,3 +487,7 @@ func (rec *SDnsRecord) PerformDisable(ctx context.Context, userCred mcclient.Tok
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (manager *SDnsRecordManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.DnsRecordListInput) (*sqlchemy.SQuery, error) {
|
||||
return manager.SAdminSharableVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.AdminSharableVirtualResourceListInput)
|
||||
}
|
||||
|
||||
@@ -21,10 +21,12 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
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"
|
||||
@@ -302,3 +304,11 @@ func FetchDynamicResourceObject(man IDynamicResourceManager, userCred mcclient.T
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (manager *SDynamicschedtagManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input api.DynamicschedtagListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -462,3 +462,11 @@ func (self *SElasticcacheAccount) GetDetailsLoginInfo(ctx context.Context, userC
|
||||
func (self *SElasticcacheAccount) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAccountManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input api.ElasticcacheAccountListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -342,3 +342,11 @@ func (self *SElasticcacheAcl) StartDeleteElasticcacheAclTask(ctx context.Context
|
||||
func (self *SElasticcacheAcl) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheAclManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input api.ElasticcacheAclListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -366,3 +366,11 @@ func (self *SElasticcacheBackup) ValidateDeleteCondition(ctx context.Context) er
|
||||
func (self *SElasticcacheBackup) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheBackupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input api.ElasticcacheBackupListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -250,12 +250,13 @@ func (manager *SElasticcacheManager) GetOwnerIdByElasticcacheId(elasticcacheId s
|
||||
return ec.(*SElasticcache).GetOwnerId()
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
// 列出弹性缓存(redis等)
|
||||
func (manager *SElasticcacheManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.ElasticcacheListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "vpc", ModelKeyword: "vpc", OwnerId: userCred},
|
||||
{Key: "zone", ModelKeyword: "zone", OwnerId: userCred},
|
||||
@@ -264,9 +265,9 @@ func (manager *SElasticcacheManager) ListItemFilter(ctx context.Context, q *sqlc
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -235,3 +235,11 @@ func (self *SElasticcacheParameter) StartUpdateElasticcacheParameterTask(ctx con
|
||||
func (self *SElasticcacheParameter) ValidatePurgeCondition(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheParameterManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input api.ElasticcacheParameterListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, input.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -30,6 +31,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
@@ -166,20 +168,19 @@ func (manager *SElasticcacheSkuManager) FetchCustomizeColumns(ctx context.Contex
|
||||
return ret
|
||||
}
|
||||
|
||||
func (manager *SElasticcacheSkuManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, data)
|
||||
func (manager *SElasticcacheSkuManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.ElasticcacheSkuListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if usable, _ := query.Bool("usable"); usable {
|
||||
if query.Usable != nil && *query.Usable {
|
||||
q = usableFilter(q, true)
|
||||
sq := sqlchemy.OR(sqlchemy.Equals(q.Field("prepaid_status"), api.SkuStatusAvailable), sqlchemy.Equals(q.Field("postpaid_status"), api.SkuStatusAvailable))
|
||||
q = q.Filter(sq)
|
||||
}
|
||||
|
||||
if b, _ := query.GetString("billing_type"); len(b) > 0 {
|
||||
if b := query.BillingType; len(b) > 0 {
|
||||
switch b {
|
||||
case billing.BILLING_TYPE_POSTPAID:
|
||||
q = q.Equals("postpaid_status", api.SkuStatusAvailable)
|
||||
@@ -188,33 +189,37 @@ func (manager *SElasticcacheSkuManager) ListItemFilter(ctx context.Context, q *s
|
||||
}
|
||||
}
|
||||
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "zone", ModelKeyword: "zone", OwnerId: userCred},
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
})
|
||||
q, err = managedResourceFilterByZone(q, query.ZonalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
|
||||
q = listItemDomainFilter(q, data)
|
||||
if domainStr := query.ProjectDomain; len(domainStr) > 0 {
|
||||
domain, err := db.TenantCacheManager.FetchDomainByIdOrName(context.Background(), domainStr)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2("domains", domainStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
query.ProjectDomain = domain.GetId()
|
||||
}
|
||||
q = listItemDomainFilter(q, query.Providers, query.ProjectDomain)
|
||||
|
||||
city, _ := query.GetString("city")
|
||||
if len(city) > 0 {
|
||||
regionTable := CloudregionManager.Query().SubQuery()
|
||||
q = q.Join(regionTable, sqlchemy.Equals(regionTable.Field("id"), q.Field("cloudregion_id"))).Filter(sqlchemy.Equals(regionTable.Field("city"), city))
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
// 按区间查询内存, 避免0.75G这样的套餐不好过滤
|
||||
memSizeMB, _ := query.Int("memory_size_mb")
|
||||
memSizeMB := query.MemorySizeMb
|
||||
if memSizeMB > 0 {
|
||||
s, e := intervalMem(int(memSizeMB))
|
||||
q.GT("memory_size_mb", s)
|
||||
q.LE("memory_size_mb", e)
|
||||
queryDict := query.(*jsonutils.JSONDict)
|
||||
queryDict.Remove("memory_size_mb")
|
||||
}
|
||||
|
||||
return q, err
|
||||
return q, nil
|
||||
}
|
||||
|
||||
// 获取region下所有Available状态的sku id
|
||||
@@ -319,12 +324,17 @@ func (manager *SElasticcacheSkuManager) GetPropertyInstanceSpecs(ctx context.Con
|
||||
q := manager.Query("memory_size_mb")
|
||||
q, err := db.ListItemQueryFilters(manager, ctx, q, userCred, query, policy.PolicyActionList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "db.ListItemQueryFilters")
|
||||
}
|
||||
|
||||
q, err = manager.ListItemFilter(ctx, q, userCred, query)
|
||||
listQuery := api.ElasticcacheSkuListInput{}
|
||||
err = query.Unmarshal(&listQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "query.Unmarshal")
|
||||
}
|
||||
q, err = manager.ListItemFilter(ctx, q, userCred, listQuery)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "manager.ListItemFilter")
|
||||
}
|
||||
|
||||
q = q.GroupBy(q.Field("memory_size_mb")).Asc(q.Field("memory_size_mb")).Distinct()
|
||||
@@ -332,10 +342,10 @@ func (manager *SElasticcacheSkuManager) GetPropertyInstanceSpecs(ctx context.Con
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
mems := map[int]bool{}
|
||||
mems_mb := jsonutils.NewArray()
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var ms int
|
||||
err := rows.Scan(&ms)
|
||||
@@ -365,12 +375,17 @@ func (manager *SElasticcacheSkuManager) GetPropertyCapability(ctx context.Contex
|
||||
q := manager.Query("engine", "engine_version", "local_category", "node_type", "performance_type")
|
||||
q, err := db.ListItemQueryFilters(manager, ctx, q, userCred, query, policy.PolicyActionList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "db.ListItemQueryFilters")
|
||||
}
|
||||
|
||||
q, err = manager.ListItemFilter(ctx, q, userCred, query)
|
||||
listQuery := api.ElasticcacheSkuListInput{}
|
||||
err = query.Unmarshal(&listQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "query.Unmarshal")
|
||||
}
|
||||
q, err = manager.ListItemFilter(ctx, q, userCred, listQuery)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "manager.ListItemFilter")
|
||||
}
|
||||
|
||||
f1 := q.Field("engine")
|
||||
|
||||
@@ -83,41 +83,33 @@ type SElasticip struct {
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required"`
|
||||
}
|
||||
|
||||
func (manager *SElasticipManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
// 列出弹性公网IP
|
||||
func (manager *SElasticipManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.ElasticipListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
q = managedResourceFilterByCloudType(q, query, "", nil)
|
||||
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
regionFilter, _ := query.GetString("region")
|
||||
if len(regionFilter) > 0 {
|
||||
regionObj, err := CloudregionManager.FetchByIdOrName(userCred, regionFilter)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("cloud region %s not found", regionFilter)
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
q = q.Equals("cloudregion_id", regionObj.GetId())
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
associateType, _ := query.GetString("usable_eip_for_associate_type")
|
||||
associateId, _ := query.GetString("usable_eip_for_associate_id")
|
||||
associateType := query.UsableEipForAssociateType
|
||||
associateId := query.UsableEipForAssociateId
|
||||
if len(associateType) > 0 && len(associateId) > 0 {
|
||||
switch associateType {
|
||||
case api.EIP_ASSOCIATE_TYPE_SERVER:
|
||||
serverObj, err := GuestManager.FetchByIdOrName(userCred, associateId)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("server %s not found", regionFilter)
|
||||
return nil, httperrors.NewResourceNotFoundError("server %s not found", associateId)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
@@ -141,12 +133,9 @@ func (manager *SElasticipManager) ListItemFilter(ctx context.Context, q *sqlchem
|
||||
}
|
||||
}
|
||||
|
||||
if query.Contains("usable") {
|
||||
usable := jsonutils.QueryBoolean(query, "usable", false)
|
||||
if usable {
|
||||
q = q.Equals("status", api.EIP_STATUS_READY)
|
||||
q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("associate_id")), sqlchemy.IsEmpty(q.Field("associate_id"))))
|
||||
}
|
||||
if query.Usable != nil && *query.Usable {
|
||||
q = q.Equals("status", api.EIP_STATUS_READY)
|
||||
q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("associate_id")), sqlchemy.IsEmpty(q.Field("associate_id"))))
|
||||
}
|
||||
|
||||
return q, nil
|
||||
|
||||
@@ -20,9 +20,11 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -274,17 +276,16 @@ func (self *SExternalProject) PerformChangeProject(ctx context.Context, userCred
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (manager *SExternalProjectManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
func (manager *SExternalProjectManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.ExternalProjectListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
q = managedResourceFilterByCloudType(q, query, "", nil)
|
||||
|
||||
q, err = manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
|
||||
@@ -96,8 +96,8 @@ func (self *SGlobalVpc) ValidateUpdateData(ctx context.Context, userCred mcclien
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (manager *SGlobalVpcManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
return manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (manager *SGlobalVpcManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.GlobalVpcListInput) (*sqlchemy.SQuery, error) {
|
||||
return manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
}
|
||||
|
||||
func (self *SGlobalVpc) ValidateUpdateCondition(ctx context.Context) error {
|
||||
|
||||
@@ -74,7 +74,7 @@ type SGroup struct {
|
||||
}
|
||||
|
||||
func (sm *SGroupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential,
|
||||
input *api.InstanceGroupListInput) (*sqlchemy.SQuery, error) {
|
||||
input api.InstanceGroupListInput) (*sqlchemy.SQuery, error) {
|
||||
guestFilter := input.Server
|
||||
if len(guestFilter) != 0 {
|
||||
guestObj, err := GuestManager.FetchByIdOrName(userCred, guestFilter)
|
||||
@@ -84,6 +84,12 @@ func (sm *SGroupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery,
|
||||
ggSub := GroupguestManager.Query("group_id").Equals("guest_id", guestObj.GetId()).SubQuery()
|
||||
q = q.Join(ggSub, sqlchemy.Equals(ggSub.Field("group_id"), q.Field("id")))
|
||||
}
|
||||
if len(input.ParentId) > 0 {
|
||||
q = q.Equals("parent_id", input.ParentId)
|
||||
}
|
||||
if len(input.ServiceType) > 0 {
|
||||
q = q.Equals("service_type", input.ServiceType)
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -132,26 +132,17 @@ func (manager *SGuestManager) AllowListItems(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
// 按指定条件列出云主机实例
|
||||
func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
queryDict, ok := query.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid querystring format")
|
||||
}
|
||||
|
||||
func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.ServerListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = managedResourceFilterByAccount(q, query, "host_id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "host_id", func() *sqlchemy.SQuery {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
return hosts.Query(hosts.Field("id"))
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
q = managedResourceFilterByCloudType(q, query, "host_id", func() *sqlchemy.SQuery {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
return hosts.Query(hosts.Field("id"))
|
||||
})
|
||||
|
||||
billingTypeStr, _ := queryDict.GetString("billing_type")
|
||||
billingTypeStr := query.BillingType
|
||||
if len(billingTypeStr) > 0 {
|
||||
if billingTypeStr == billing_api.BILLING_TYPE_POSTPAID {
|
||||
q = q.Filter(
|
||||
@@ -163,24 +154,19 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
} else {
|
||||
q = q.Equals("billing_type", billingTypeStr)
|
||||
}
|
||||
queryDict.Remove("billing_type")
|
||||
}
|
||||
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
isBMstr, _ := queryDict.GetString("baremetal")
|
||||
if len(isBMstr) > 0 && utils.ToBool(isBMstr) {
|
||||
queryDict.Add(jsonutils.NewString(api.HYPERVISOR_BAREMETAL), "hypervisor")
|
||||
queryDict.Remove("baremetal")
|
||||
}
|
||||
hypervisor, _ := queryDict.GetString("hypervisor")
|
||||
if len(hypervisor) > 0 {
|
||||
q = q.Equals("hypervisor", hypervisor)
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
resourceTypeStr := jsonutils.GetAnyString(queryDict, []string{"resource_type"})
|
||||
hypervisorList := query.Hypervisor
|
||||
if len(hypervisorList) > 0 {
|
||||
q = q.In("hypervisor", hypervisorList)
|
||||
}
|
||||
|
||||
resourceTypeStr := query.ResourceType
|
||||
if len(resourceTypeStr) > 0 {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
subq := hosts.Query(hosts.Field("id"))
|
||||
@@ -199,13 +185,13 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
q = q.In("host_id", subq.SubQuery())
|
||||
}
|
||||
|
||||
hostFilter, _ := queryDict.GetString("host")
|
||||
hostFilter := query.Host
|
||||
if len(hostFilter) > 0 {
|
||||
host, _ := HostManager.FetchByIdOrName(nil, hostFilter)
|
||||
if host == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("host %s not found", hostFilter)
|
||||
}
|
||||
if jsonutils.QueryBoolean(queryDict, "get_backup_guests_on_host", false) {
|
||||
if query.GetBackupGuestsOnHost != nil && *query.GetBackupGuestsOnHost {
|
||||
q.Filter(sqlchemy.OR(sqlchemy.Equals(q.Field("host_id"), host.GetId()),
|
||||
sqlchemy.Equals(q.Field("backup_host_id"), host.GetId())))
|
||||
} else {
|
||||
@@ -213,7 +199,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
}
|
||||
}
|
||||
|
||||
secgrpFilter, _ := queryDict.GetString("secgroup")
|
||||
secgrpFilter := query.Secgroup
|
||||
if len(secgrpFilter) > 0 {
|
||||
var notIn = false
|
||||
// HACK FOR NOT IN SECGROUP
|
||||
@@ -237,7 +223,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
}
|
||||
|
||||
isAdmin := false
|
||||
admin, _ := query.Bool("admin")
|
||||
admin := (query.Admin != nil && *query.Admin)
|
||||
if consts.IsRbacEnabled() {
|
||||
allowScope := policy.PolicyManager.AllowScope(userCred, consts.GetServiceType(), manager.KeywordPlural(), policy.PolicyActionList)
|
||||
if allowScope == rbacutils.ScopeSystem || allowScope == rbacutils.ScopeDomain {
|
||||
@@ -267,7 +253,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
}
|
||||
}
|
||||
|
||||
usableServerForEipFilter, _ := queryDict.GetString("usable_server_for_eip")
|
||||
usableServerForEipFilter := query.UsableServerForEip
|
||||
if len(usableServerForEipFilter) > 0 {
|
||||
eipObj, err := ElasticipManager.FetchByIdOrName(userCred, usableServerForEipFilter)
|
||||
if err != nil {
|
||||
@@ -299,20 +285,26 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
}
|
||||
}
|
||||
|
||||
zoneFilter, _ := queryDict.GetString("zone")
|
||||
if len(zoneFilter) > 0 {
|
||||
zone, _ := ZoneManager.FetchByIdOrName(nil, zoneFilter)
|
||||
if zone == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("zone %s not found", zoneFilter)
|
||||
}
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "host_id", func() *sqlchemy.SQuery {
|
||||
hostTable := HostManager.Query().SubQuery()
|
||||
zoneTable := ZoneManager.Query().SubQuery()
|
||||
sq := hostTable.Query(hostTable.Field("id")).Join(zoneTable,
|
||||
sqlchemy.Equals(zoneTable.Field("id"), hostTable.Field("zone_id"))).Filter(sqlchemy.Equals(zoneTable.Field("id"), zone.GetId())).SubQuery()
|
||||
q = q.In("host_id", sq)
|
||||
sq := hostTable.Query(hostTable.Field("id"))
|
||||
sq = sq.Join(zoneTable, sqlchemy.Equals(zoneTable.Field("id"), hostTable.Field("zone_id")))
|
||||
return sq
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
wireFilter, _ := queryDict.GetString("wire")
|
||||
q, err = managedResourceFilterByZone(q, query.ZonalFilterListInput, "host_id", func() *sqlchemy.SQuery {
|
||||
hostTable := HostManager.Query().SubQuery()
|
||||
return hostTable.Query(hostTable.Field("id"))
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
|
||||
wireFilter := query.Wire
|
||||
if len(wireFilter) > 0 {
|
||||
wire, _ := WireManager.FetchByIdOrName(nil, wireFilter)
|
||||
if wire == nil {
|
||||
@@ -324,7 +316,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
q = q.In("host_id", sq)
|
||||
}
|
||||
|
||||
networkFilter, _ := queryDict.GetString("network")
|
||||
networkFilter := query.Network
|
||||
if len(networkFilter) > 0 {
|
||||
netI, _ := NetworkManager.FetchByIdOrName(userCred, networkFilter)
|
||||
if netI == nil {
|
||||
@@ -338,8 +330,8 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
q = q.In("host_id", sq)
|
||||
}
|
||||
|
||||
vpcFilter, err := queryDict.GetString("vpc")
|
||||
if err == nil {
|
||||
vpcFilter := query.Vpc
|
||||
if len(vpcFilter) > 0 {
|
||||
IVpc, err := VpcManager.FetchByIdOrName(userCred, vpcFilter)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("Vpc %s not found", vpcFilter)
|
||||
@@ -355,7 +347,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
q = q.In("id", sq)
|
||||
}
|
||||
|
||||
diskFilter, _ := queryDict.GetString("disk")
|
||||
diskFilter := query.Disk
|
||||
if len(diskFilter) > 0 {
|
||||
diskI, _ := DiskManager.FetchByIdOrName(userCred, diskFilter)
|
||||
if diskI == nil {
|
||||
@@ -382,65 +374,45 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
}
|
||||
}
|
||||
|
||||
regionFilter, _ := queryDict.GetString("region")
|
||||
if len(regionFilter) > 0 {
|
||||
regionObj, err := CloudregionManager.FetchByIdOrName(userCred, regionFilter)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("cloud region %s not found", regionFilter)
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
zones := ZoneManager.Query().SubQuery()
|
||||
sq := hosts.Query(hosts.Field("id"))
|
||||
sq = sq.Join(zones, sqlchemy.Equals(hosts.Field("zone_id"), zones.Field("id")))
|
||||
sq = sq.Filter(sqlchemy.Equals(zones.Field("cloudregion_id"), regionObj.GetId()))
|
||||
q = q.In("host_id", sq)
|
||||
}
|
||||
|
||||
withEip, _ := queryDict.GetString("with_eip")
|
||||
withoutEip, _ := queryDict.GetString("without_eip")
|
||||
if len(withEip) > 0 || len(withoutEip) > 0 {
|
||||
withEip := (query.WithEip != nil && *query.WithEip)
|
||||
withoutEip := (query.WithoutEip != nil && *query.WithoutEip)
|
||||
if withEip || withoutEip {
|
||||
eips := ElasticipManager.Query().SubQuery()
|
||||
sq := eips.Query(eips.Field("associate_id")).Equals("associate_type", api.EIP_ASSOCIATE_TYPE_SERVER)
|
||||
sq = sq.IsNotNull("associate_id").IsNotEmpty("associate_id")
|
||||
|
||||
if utils.ToBool(withEip) {
|
||||
if withEip {
|
||||
q = q.In("id", sq)
|
||||
} else if utils.ToBool(withoutEip) {
|
||||
} else if withoutEip {
|
||||
q = q.NotIn("id", sq)
|
||||
}
|
||||
}
|
||||
|
||||
gpu, _ := queryDict.GetString("gpu")
|
||||
if len(gpu) != 0 {
|
||||
if query.Gpu != nil {
|
||||
isodev := IsolatedDeviceManager.Query().SubQuery()
|
||||
sgq := isodev.Query(isodev.Field("guest_id")).
|
||||
Filter(sqlchemy.AND(
|
||||
sqlchemy.IsNotNull(isodev.Field("guest_id")),
|
||||
sqlchemy.Startswith(isodev.Field("dev_type"), "GPU")))
|
||||
showGpu := utils.ToBool(gpu)
|
||||
cond := sqlchemy.NotIn
|
||||
if showGpu {
|
||||
if *query.Gpu {
|
||||
cond = sqlchemy.In
|
||||
}
|
||||
q = q.Filter(cond(q.Field("id"), sgq))
|
||||
}
|
||||
|
||||
groupFilter := jsonutils.GetAnyString(queryDict, []string{"group", "group_id"})
|
||||
groupFilter := query.Group
|
||||
if len(groupFilter) != 0 {
|
||||
groupObj, err := GroupManager.FetchByIdOrName(userCred, groupFilter)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewNotFoundError("group %s not found", groupFilter)
|
||||
}
|
||||
queryDict.Add(jsonutils.NewString(groupObj.GetId()), "group")
|
||||
// queryDict.Add(jsonutils.NewString(groupObj.GetId()), "group")
|
||||
ggSub := GroupguestManager.Query("guest_id").Equals("group_id", groupObj.GetId()).SubQuery()
|
||||
q = q.Join(ggSub, sqlchemy.Equals(ggSub.Field("guest_id"), q.Field("id")))
|
||||
}
|
||||
|
||||
orderByDisk, _ := queryDict.GetString("order_by_disk")
|
||||
orderByDisk := query.OrderByDisk
|
||||
if orderByDisk == "asc" || orderByDisk == "desc" {
|
||||
guestdisks := GuestdiskManager.Query().SubQuery()
|
||||
disks := DiskManager.Query().SubQuery()
|
||||
@@ -461,7 +433,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ
|
||||
}
|
||||
}
|
||||
|
||||
orderByHost, _ := queryDict.GetString("order_by_host")
|
||||
orderByHost := query.OrderByHost
|
||||
if orderByHost == "asc" {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
q = q.Join(hosts, sqlchemy.Equals(q.Field("host_id"), hosts.Field("id"))).
|
||||
|
||||
+29
-54
@@ -170,25 +170,20 @@ func (self *SHost) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenC
|
||||
return db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.HostListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q = managedResourceFilterByCloudType(q, query, "", nil)
|
||||
|
||||
q, err = managedResourceFilterByDomain(q, query, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
|
||||
queryDict := query.(*jsonutils.JSONDict)
|
||||
q, err = managedResourceFilterByDomain(q, query.DomainizedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByDomain")
|
||||
}
|
||||
|
||||
resType, _ := query.GetString("resource_type")
|
||||
resType := query.ResourceType
|
||||
if len(resType) > 0 {
|
||||
queryDict.Remove("resource_type")
|
||||
|
||||
switch resType {
|
||||
case api.HostResourceTypeShared:
|
||||
q = q.Filter(
|
||||
@@ -202,12 +197,12 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
}
|
||||
}
|
||||
|
||||
q, err = manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = manager.SEnabledStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.EnabledStatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SEnabledStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
anyMac, _ := query.GetString("any_mac")
|
||||
anyMac := query.AnyMac
|
||||
if len(anyMac) > 0 {
|
||||
anyMac := netutils.FormatMacAddr(anyMac)
|
||||
if len(anyMac) == 0 {
|
||||
@@ -222,7 +217,7 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
}
|
||||
// var scopeQuery *sqlchemy.SSubQuery
|
||||
|
||||
schedTagStr := jsonutils.GetAnyString(query, []string{"schedtag", "schedtag_id"})
|
||||
schedTagStr := query.Schedtag
|
||||
if len(schedTagStr) > 0 {
|
||||
schedTag, _ := SchedtagManager.FetchByIdOrName(nil, schedTagStr)
|
||||
if schedTag == nil {
|
||||
@@ -233,7 +228,7 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
q = q.In("id", scopeQuery)
|
||||
}
|
||||
|
||||
wireStr := jsonutils.GetAnyString(query, []string{"wire", "wire_id"})
|
||||
wireStr := query.Wire
|
||||
if len(wireStr) > 0 {
|
||||
wire, _ := WireManager.FetchByIdOrName(nil, wireStr)
|
||||
if wire == nil {
|
||||
@@ -244,8 +239,7 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
q = q.In("id", scopeQuery)
|
||||
}
|
||||
|
||||
storageStr := jsonutils.GetAnyString(query, []string{"storage", "storage_id"})
|
||||
notAttached := jsonutils.QueryBoolean(query, "storage_not_attached", false)
|
||||
storageStr := query.Storage
|
||||
if len(storageStr) > 0 {
|
||||
storage, _ := StorageManager.FetchByIdOrName(nil, storageStr)
|
||||
if storage == nil {
|
||||
@@ -253,6 +247,7 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
}
|
||||
hoststorages := HoststorageManager.Query().SubQuery()
|
||||
scopeQuery := hoststorages.Query(hoststorages.Field("host_id")).Equals("storage_id", storage.GetId()).SubQuery()
|
||||
notAttached := (query.StorageNotAttached != nil && *query.StorageNotAttached)
|
||||
if !notAttached {
|
||||
q = q.In("id", scopeQuery)
|
||||
} else {
|
||||
@@ -260,39 +255,19 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
}
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByZone(q, query, "", nil)
|
||||
/*zoneStr := jsonutils.GetAnyString(query, []string{"zone", "zone_id"})
|
||||
if len(zoneStr) > 0 {
|
||||
zone, err := ZoneManager.FetchByIdOrName(nil, zoneStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(ZoneManager.Keyword(), zoneStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("zone_id"), zone.GetId()))
|
||||
q, err = managedResourceFilterByZone(q, query.ZonalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
|
||||
queryDict.Remove("zone_id")
|
||||
}*/
|
||||
|
||||
q, err = managedResourceFilterByRegion(q, query, "zone_id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "zone_id", func() *sqlchemy.SQuery {
|
||||
return ZoneManager.Query("id")
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
/*regionStr := jsonutils.GetAnyString(query, []string{"region", "region_id"})
|
||||
if len(regionStr) > 0 {
|
||||
region, err := CloudregionManager.FetchByIdOrName(nil, regionStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudregionManager.Keyword(), regionStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
subq := ZoneManager.Query("id").Equals("cloudregion_id", region.GetId()).SubQuery()
|
||||
q = q.Filter(sqlchemy.In(q.Field("zone_id"), subq))
|
||||
}*/
|
||||
|
||||
hypervisorStr := jsonutils.GetAnyString(query, []string{"hypervisor"})
|
||||
hypervisorStr := query.Hypervisor
|
||||
if len(hypervisorStr) > 0 {
|
||||
hostType, ok := api.HYPERVISOR_HOSTTYPE[hypervisorStr]
|
||||
if !ok {
|
||||
@@ -301,7 +276,7 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("host_type"), hostType))
|
||||
}
|
||||
|
||||
usable := jsonutils.QueryBoolean(query, "usable", false)
|
||||
usable := (query.Usable != nil && *query.Usable)
|
||||
if usable {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
hostwires := HostwireManager.Query().SubQuery()
|
||||
@@ -347,8 +322,8 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
)
|
||||
}
|
||||
|
||||
if query.Contains("is_empty") {
|
||||
isEmpty := jsonutils.QueryBoolean(query, "is_empty", false)
|
||||
if query.IsEmpty != nil {
|
||||
isEmpty := *query.IsEmpty
|
||||
sq := GuestManager.Query("host_id").IsNotEmpty("host_id").GroupBy("host_id").SubQuery()
|
||||
if isEmpty {
|
||||
q = q.NotIn("id", sq)
|
||||
@@ -357,8 +332,8 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu
|
||||
}
|
||||
}
|
||||
|
||||
if query.Contains("baremetal") {
|
||||
isBaremetal := jsonutils.QueryBoolean(query, "baremetal", false)
|
||||
if query.Baremetal != nil {
|
||||
isBaremetal := *query.Baremetal
|
||||
if isBaremetal {
|
||||
q = q.Equals("host_type", api.HOST_TYPE_BAREMETAL)
|
||||
} else {
|
||||
|
||||
@@ -17,7 +17,6 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -25,7 +24,7 @@ import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
schedapi "yunion.io/x/onecloud/pkg/apis/scheduler"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
@@ -72,14 +71,25 @@ func (manager *SInstanceSnapshotManager) AllowCreateItem(
|
||||
return false
|
||||
}
|
||||
|
||||
func (manager *SInstanceSnapshotManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
queryDict, ok := query.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid querystring format")
|
||||
func (manager *SInstanceSnapshotManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.InstanceSnapshotListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
if guestId, _ := queryDict.GetString("guest_id"); len(guestId) > 0 {
|
||||
q = q.Equals("guest_id", guestId)
|
||||
|
||||
guestStr := query.Server
|
||||
if len(guestStr) > 0 {
|
||||
guestObj, err := GuestManager.FetchByIdOrName(userCred, guestStr)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2("guests", guestStr)
|
||||
} else {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
}
|
||||
q = q.Equals("guest_id", guestObj.GetId())
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -102,7 +112,7 @@ func (self *SInstanceSnapshot) getMoreDetails(userCred mcclient.TokenCredential,
|
||||
snapshots, _ := self.GetSnapshots()
|
||||
snapshotsDesc := jsonutils.NewArray()
|
||||
for i := 0; i < len(snapshots); i++ {
|
||||
if snapshots[i].DiskType == compute.DISK_TYPE_SYS {
|
||||
if snapshots[i].DiskType == api.DISK_TYPE_SYS {
|
||||
osType = snapshots[i].OsType
|
||||
}
|
||||
jsonDict := jsonutils.Marshal(&snapshots[i]).(*jsonutils.JSONDict)
|
||||
@@ -221,7 +231,7 @@ func (manager *SInstanceSnapshotManager) CreateInstanceSnapshot(
|
||||
}
|
||||
|
||||
func (self *SInstanceSnapshot) ToInstanceCreateInput(
|
||||
sourceInput *compute.ServerCreateInput) (*compute.ServerCreateInput, error) {
|
||||
sourceInput *api.ServerCreateInput) (*api.ServerCreateInput, error) {
|
||||
|
||||
serverConfig := new(schedapi.ServerConfig)
|
||||
if err := self.ServerConfig.Unmarshal(serverConfig); err != nil {
|
||||
@@ -286,7 +296,7 @@ func (self *SInstanceSnapshot) GetInstanceSnapshotJointAt(diskIndex int) (*SInst
|
||||
}
|
||||
|
||||
func (self *SInstanceSnapshot) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if self.Status == compute.INSTANCE_SNAPSHOT_START_DELETE {
|
||||
if self.Status == api.INSTANCE_SNAPSHOT_START_DELETE {
|
||||
return httperrors.NewBadRequestError("can't delete snapshot in deleting")
|
||||
}
|
||||
return nil
|
||||
@@ -308,7 +318,7 @@ func (self *SInstanceSnapshot) StartInstanceSnapshotDeleteTask(
|
||||
log.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
self.SetStatus(userCred, compute.INSTANCE_SNAPSHOT_START_DELETE, "InstanceSnapshotDeleteTask")
|
||||
self.SetStatus(userCred, api.INSTANCE_SNAPSHOT_START_DELETE, "InstanceSnapshotDeleteTask")
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
@@ -136,23 +136,26 @@ func (self *SIsolatedDevice) AllowUpdateItem(ctx context.Context, userCred mccli
|
||||
return db.IsAdminAllowUpdate(userCred, self)
|
||||
}
|
||||
|
||||
func (manager *SIsolatedDeviceManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (manager *SIsolatedDeviceManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.IsolatedDeviceListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByDomain(q, query, "host_id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByDomain(q, query.DomainizedResourceListInput, "host_id", func() *sqlchemy.SQuery {
|
||||
return HostManager.Query("id")
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByDomain")
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(query, "gpu", false) {
|
||||
if query.Gpu != nil && *query.Gpu {
|
||||
q = q.Startswith("dev_type", "GPU")
|
||||
}
|
||||
if jsonutils.QueryBoolean(query, "usb", false) {
|
||||
if query.Usb != nil && *query.Usb {
|
||||
q = q.Equals("dev_type", "USB")
|
||||
}
|
||||
hostStr, _ := query.GetString("host")
|
||||
hostStr := query.Host
|
||||
var sq *sqlchemy.SSubQuery
|
||||
if len(hostStr) > 0 {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
@@ -163,32 +166,29 @@ func (manager *SIsolatedDeviceManager) ListItemFilter(ctx context.Context, q *sq
|
||||
if sq != nil {
|
||||
q = q.Filter(sqlchemy.In(q.Field("host_id"), sq))
|
||||
}
|
||||
if jsonutils.QueryBoolean(query, "unused", false) {
|
||||
if query.Unused != nil && *query.Unused {
|
||||
q = q.IsEmpty("guest_id")
|
||||
}
|
||||
regionStr := jsonutils.GetAnyString(query, []string{"region", "region_id"})
|
||||
if len(regionStr) > 0 {
|
||||
region, err := CloudregionManager.FetchByIdOrName(nil, regionStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudregionManager.Keyword(), regionStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "host_id", func() *sqlchemy.SQuery {
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
subq := ZoneManager.Query("id").Equals("cloudregion_id", region.GetId()).SubQuery()
|
||||
q.Join(hosts, sqlchemy.Equals(q.Field("host_id"), hosts.Field("id"))).Filter(sqlchemy.In(hosts.Field("zone_id"), subq))
|
||||
zones := ZoneManager.Query().SubQuery()
|
||||
|
||||
q := hosts.Query(hosts.Field("id"))
|
||||
q = q.Join(zones, sqlchemy.Equals(hosts.Field("zone_id"), zones.Field("id")))
|
||||
return q
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
zoneStr := jsonutils.GetAnyString(query, []string{"zone", "zone_id"})
|
||||
if len(zoneStr) > 0 {
|
||||
zone, _ := ZoneManager.FetchByIdOrName(nil, zoneStr)
|
||||
if zone == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("Zone %s not found", zoneStr)
|
||||
}
|
||||
hosts := HostManager.Query().SubQuery()
|
||||
sq := hosts.Query(hosts.Field("id")).Filter(sqlchemy.Equals(hosts.Field("zone_id"), zone.GetId()))
|
||||
q = q.Filter(sqlchemy.In(q.Field("host_id"), sq))
|
||||
|
||||
q, err = managedResourceFilterByZone(q, query.ZonalFilterListInput, "host_id", func() *sqlchemy.SQuery {
|
||||
return HostManager.Query("id")
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -61,13 +61,14 @@ type SKeypair struct {
|
||||
OwnerId string `width:"128" charset:"ascii" index:"true" nullable:"false" create:"required"` // Column(VARCHAR(length=36, charset='ascii'), index=True, nullable=False)
|
||||
}
|
||||
|
||||
func (manager *SKeypairManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
// 列出ssh密钥对
|
||||
func (manager *SKeypairManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.KeypairListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if jsonutils.QueryBoolean(query, "admin", false) && db.IsAdminAllowList(userCred, manager) {
|
||||
user, _ := query.GetString("user")
|
||||
if query.Admin != nil && *query.Admin && db.IsAdminAllowList(userCred, manager) {
|
||||
user := query.UserStr()
|
||||
if len(user) > 0 {
|
||||
uc, _ := db.UserCacheManager.FetchUserByIdOrName(ctx, user)
|
||||
if uc == nil {
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
@@ -413,3 +414,11 @@ func (manager *SLoadbalancerAclManager) InitializeData() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerAclManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input api.LoadbalancerAclListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := manager.SSharableVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, input.SharableVirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SSharableVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
@@ -379,12 +380,12 @@ func (man *SLoadbalancerAgentManager) ValidateCreateData(ctx context.Context, us
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerAgentManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SLoadbalancerAgentManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerAgentListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "cluster", ModelKeyword: "loadbalancercluster", OwnerId: userCred},
|
||||
})
|
||||
|
||||
@@ -75,13 +75,13 @@ func (man *SLoadbalancerBackendGroupManager) pendingDeleteSubs(ctx context.Conte
|
||||
}
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerBackendGroupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SLoadbalancerBackendGroupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerBackendGroupListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
// userProjId := userCred.GetProjectId()
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "loadbalancer", ModelKeyword: "loadbalancer", OwnerId: userCred},
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
@@ -91,7 +91,7 @@ func (man *SLoadbalancerBackendGroupManager) ListItemFilter(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if noRef, _ := data.Bool("no_ref"); noRef {
|
||||
if query.NoRef != nil && *query.NoRef {
|
||||
q, err = man.FilterZeroRefBackendGroup(q)
|
||||
if err != nil {
|
||||
log.Errorf("SLoadbalancerBackendGroupManager ListItemFilter %s", err)
|
||||
|
||||
@@ -82,13 +82,13 @@ func (man *SLoadbalancerBackendManager) pendingDeleteSubs(ctx context.Context, u
|
||||
}
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerBackendManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SLoadbalancerBackendManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerBackendListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
// userProjId := userCred.GetProjectId()
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "backend_group", ModelKeyword: "loadbalancerbackendgroup", OwnerId: userCred},
|
||||
{Key: "backend", ModelKeyword: "server", OwnerId: userCred}, // NOTE extend this when new backend_type was added
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
@@ -219,16 +220,15 @@ func (man *SLoadbalancerCertificateManager) validateCertKey(ctx context.Context,
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerCertificateManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SLoadbalancerCertificateManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerCertificateListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
if jsonutils.QueryBoolean(query, "usable", false) {
|
||||
region, _ := data.GetString("cloudregion")
|
||||
manager, _ := data.GetString("manager")
|
||||
if query.Usable != nil && *query.Usable {
|
||||
region := query.Cloudregion
|
||||
manager := query.Cloudprovider
|
||||
|
||||
// 证书可用包含两类:1.本地证书内容不为空 2.公有云中已经存在,但是证书内容不完整的证书
|
||||
if len(region) > 0 || len(manager) > 0 {
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -73,12 +74,12 @@ func (lbc *SLoadbalancerCluster) AllowDeleteItem(ctx context.Context, userCred m
|
||||
return db.IsAdminAllowDelete(userCred, lbc)
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerClusterManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SLoadbalancerClusterManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerClusterListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "zone", ModelKeyword: "zone", OwnerId: userCred},
|
||||
{Key: "wire", ModelKeyword: "wire", OwnerId: userCred},
|
||||
|
||||
@@ -379,13 +379,13 @@ func (man *SLoadbalancerListenerRuleManager) pendingDeleteSubs(ctx context.Conte
|
||||
}
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerListenerRuleManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SLoadbalancerListenerRuleManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerListenerRuleListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
// userProjId := userCred.GetProjectId()
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "listener", ModelKeyword: "loadbalancerlistener", OwnerId: userCred},
|
||||
{Key: "backend_group", ModelKeyword: "loadbalancerbackendgroup", OwnerId: userCred},
|
||||
|
||||
@@ -195,19 +195,28 @@ func (man *SLoadbalancerListenerManager) pendingDeleteSubs(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerListenerManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SLoadbalancerListenerManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerListenerListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
// userProjId := userCred.GetProjectId()
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "loadbalancer", ModelKeyword: "loadbalancer", OwnerId: userCred},
|
||||
{Key: "backend_group", ModelKeyword: "loadbalancerbackendgroup", OwnerId: userCred},
|
||||
{Key: "acl", ModelKeyword: "cachedloadbalanceracl", OwnerId: userCred},
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
{Key: "manager", ModelKeyword: "cloudprovider", OwnerId: userCred},
|
||||
// {Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
// {Key: "manager", ModelKeyword: "cloudprovider", OwnerId: userCred},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -92,25 +92,32 @@ type SLoadbalancer struct {
|
||||
LBInfo jsonutils.JSONObject `charset:"utf8" nullable:"true" list:"user" update:"admin" create:"admin_optional"`
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
func (man *SLoadbalancerManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.LoadbalancerListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
q = managedResourceFilterByCloudType(q, query, "", nil)
|
||||
|
||||
q, err = man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
q, err = man.SVirtualResourceBaseManager.ListItemFilter(ctx, q, userCred, query.VirtualResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SVirtualResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByRegion(q, query.RegionalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByRegion")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByZone(q, query.ZonalFilterListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByZone")
|
||||
}
|
||||
|
||||
ownerId := userCred
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "network", ModelKeyword: "network", OwnerId: ownerId},
|
||||
{Key: "zone", ModelKeyword: "zone", OwnerId: ownerId},
|
||||
{Key: "manager", ModelKeyword: "cloudprovider", OwnerId: ownerId},
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: ownerId},
|
||||
{Key: "cluster", ModelKeyword: "loadbalancercluster", OwnerId: userCred},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/appctx"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
@@ -145,10 +146,9 @@ func (self *SManagedResourceBase) IsManaged() bool {
|
||||
return len(self.ManagerId) > 0
|
||||
}
|
||||
|
||||
func managedResourceFilterByDomain(q *sqlchemy.SQuery, query jsonutils.JSONObject, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
domainStr, key := jsonutils.GetAnyString2(query, []string{"domain_id", "project_domain", "project_domain_id"})
|
||||
func managedResourceFilterByDomain(q *sqlchemy.SQuery, query apis.DomainizedResourceListInput, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
domainStr := query.ProjectDomain
|
||||
if len(domainStr) > 0 {
|
||||
query.(*jsonutils.JSONDict).Remove(key)
|
||||
domain, err := db.TenantCacheManager.FetchDomainByIdOrName(context.Background(), domainStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -231,19 +231,13 @@ func filterByProviderStrs(q *sqlchemy.SQuery, filterField string, subqFunc func(
|
||||
return q
|
||||
}
|
||||
|
||||
func managedResourceFilterByAccountV2(q *sqlchemy.SQuery, input *api.CloudaccountListInput, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
// deprecate at 3.0
|
||||
for _, provider := range []string{input.Cloudprovider, input.Manager, input.ManagerId, input.CloudproviderId} {
|
||||
if len(provider) > 0 {
|
||||
input.Cloudprovider = provider
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(input.Cloudprovider) > 0 {
|
||||
provider, err := CloudproviderManager.FetchByIdOrName(nil, input.Cloudprovider)
|
||||
func managedResourceFilterByAccount(q *sqlchemy.SQuery, input api.ManagedResourceListInput, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
cloudproviderStr := input.Cloudprovider
|
||||
if len(cloudproviderStr) > 0 {
|
||||
provider, err := CloudproviderManager.FetchByIdOrName(nil, cloudproviderStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudproviderManager.Keyword(), input.Cloudprovider)
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudproviderManager.Keyword(), cloudproviderStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
@@ -256,19 +250,12 @@ func managedResourceFilterByAccountV2(q *sqlchemy.SQuery, input *api.Cloudaccoun
|
||||
}
|
||||
}
|
||||
|
||||
// deprecate at 3.0
|
||||
for _, account := range []string{input.Cloudaccount, input.CloudaccountId, input.Account, input.AccountId} {
|
||||
if len(account) > 0 {
|
||||
input.Cloudaccount = account
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(input.Cloudaccount) > 0 {
|
||||
account, err := CloudaccountManager.FetchByIdOrName(nil, input.Cloudaccount)
|
||||
cloudaccountStr := input.Cloudaccount
|
||||
if len(cloudaccountStr) > 0 {
|
||||
account, err := CloudaccountManager.FetchByIdOrName(nil, cloudaccountStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudaccountManager.Keyword(), input.Cloudaccount)
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudaccountManager.Keyword(), cloudaccountStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
@@ -290,78 +277,14 @@ func managedResourceFilterByAccountV2(q *sqlchemy.SQuery, input *api.Cloudaccoun
|
||||
q = filterByProviderStrs(q, filterField, subqFunc, "brand", input.Brands)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func managedResourceFilterByAccount(q *sqlchemy.SQuery, query jsonutils.JSONObject, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
queryDict := query.(*jsonutils.JSONDict)
|
||||
|
||||
managerStr, key := jsonutils.GetAnyString2(query, []string{"manager", "cloudprovider", "cloudprovider_id", "manager_id"})
|
||||
if len(managerStr) > 0 {
|
||||
queryDict.Remove("manager")
|
||||
queryDict.Remove(key)
|
||||
provider, err := CloudproviderManager.FetchByIdOrName(nil, managerStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudproviderManager.Keyword(), managerStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("manager_id"), provider.GetId()))
|
||||
queryDict.Remove("manager_id")
|
||||
} else {
|
||||
sq := subqFunc()
|
||||
sq = sq.Filter(sqlchemy.Equals(sq.Field("manager_id"), provider.GetId()))
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
queryDict.Remove(filterField)
|
||||
}
|
||||
}
|
||||
|
||||
accountStr, key := jsonutils.GetAnyString2(query, []string{"account", "account_id", "cloudaccount", "cloudaccount_id"})
|
||||
if len(accountStr) > 0 {
|
||||
queryDict.Remove("account")
|
||||
queryDict.Remove(key)
|
||||
account, err := CloudaccountManager.FetchByIdOrName(nil, accountStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(CloudaccountManager.Keyword(), accountStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
subq := CloudproviderManager.Query("id").Equals("cloudaccount_id", account.GetId()).SubQuery()
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(sqlchemy.In(q.Field("manager_id"), subq))
|
||||
queryDict.Remove("manager_id")
|
||||
} else {
|
||||
sq := subqFunc()
|
||||
sq = sq.Filter(sqlchemy.In(sq.Field("manager_id"), subq))
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
queryDict.Remove(filterField)
|
||||
}
|
||||
}
|
||||
|
||||
providerStrs := jsonutils.GetQueryStringArray(query, "provider")
|
||||
if len(providerStrs) > 0 {
|
||||
q = filterByProviderStrs(q, filterField, subqFunc, "provider", providerStrs)
|
||||
queryDict.Remove(filterField)
|
||||
queryDict.Remove("provider")
|
||||
}
|
||||
|
||||
brandStrs := jsonutils.GetQueryStringArray(query, "brand")
|
||||
if len(brandStrs) > 0 {
|
||||
q = filterByProviderStrs(q, filterField, subqFunc, "brand", brandStrs)
|
||||
queryDict.Remove(filterField)
|
||||
queryDict.Remove("brand")
|
||||
}
|
||||
q = filterByCloudType(q, input, filterField, subqFunc)
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func managedResourceFilterByZone(q *sqlchemy.SQuery, query jsonutils.JSONObject, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
zoneStr, key := jsonutils.GetAnyString2(query, []string{"zone", "zone_id"})
|
||||
func managedResourceFilterByZone(q *sqlchemy.SQuery, query api.ZonalFilterListInput, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
zoneStr := query.Zone
|
||||
if len(zoneStr) > 0 {
|
||||
query.(*jsonutils.JSONDict).Remove(key)
|
||||
zoneObj, err := ZoneManager.FetchByIdOrName(nil, zoneStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -378,13 +301,13 @@ func managedResourceFilterByZone(q *sqlchemy.SQuery, query jsonutils.JSONObject,
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
}
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func managedResourceFilterByRegion(q *sqlchemy.SQuery, query jsonutils.JSONObject, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
regionStr, key := jsonutils.GetAnyString2(query, []string{"region", "region_id", "cloudregion", "cloudregion_id"})
|
||||
func managedResourceFilterByRegion(q *sqlchemy.SQuery, query api.RegionalFilterListInput, filterField string, subqFunc func() *sqlchemy.SQuery) (*sqlchemy.SQuery, error) {
|
||||
regionStr := query.Cloudregion
|
||||
if len(regionStr) > 0 {
|
||||
query.(*jsonutils.JSONDict).Remove(key)
|
||||
regionObj, err := CloudregionManager.FetchByIdOrName(nil, regionStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -394,24 +317,31 @@ func managedResourceFilterByRegion(q *sqlchemy.SQuery, query jsonutils.JSONObjec
|
||||
}
|
||||
}
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(sqlchemy.In(q.Field("cloudregion_id"), regionObj.GetId()))
|
||||
q = q.Filter(sqlchemy.Equals(q.Field("cloudregion_id"), regionObj.GetId()))
|
||||
} else {
|
||||
sq := subqFunc()
|
||||
sq = sq.Filter(sqlchemy.In(sq.Field("cloudregion_id"), regionObj.GetId()))
|
||||
sq = sq.Filter(sqlchemy.Equals(sq.Field("cloudregion_id"), regionObj.GetId()))
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
}
|
||||
}
|
||||
if len(query.City) > 0 {
|
||||
subq := CloudregionManager.Query("id").Equals("city", query.City).SubQuery()
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(sqlchemy.In(q.Field("cloudregion_id"), subq))
|
||||
} else {
|
||||
sq := subqFunc()
|
||||
sq = sq.Filter(sqlchemy.In(sq.Field("cloudregion_id"), subq))
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
}
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func managedResourceFilterByCloudType(q *sqlchemy.SQuery, query jsonutils.JSONObject, filterField string, subqFunc func() *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
input := &api.CloudTypeListInput{}
|
||||
query.Unmarshal(input)
|
||||
return managedResourceFilterByCloudTypeV2(q, input, filterField, subqFunc)
|
||||
}
|
||||
func filterByCloudType(q *sqlchemy.SQuery, input api.ManagedResourceListInput, filterField string, subqFunc func() *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
cloudEnvStr := input.CloudEnv
|
||||
|
||||
func managedResourceFilterByCloudTypeV2(q *sqlchemy.SQuery, input *api.CloudTypeListInput, filterField string, subqFunc func() *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if input.CloudEnv == api.CLOUD_ENV_PUBLIC_CLOUD || input.PublicCloud || input.IsPublic {
|
||||
switch cloudEnvStr {
|
||||
case api.CLOUD_ENV_PUBLIC_CLOUD:
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(sqlchemy.In(q.Field("manager_id"), CloudproviderManager.GetPublicProviderIdsQuery()))
|
||||
} else {
|
||||
@@ -419,9 +349,7 @@ func managedResourceFilterByCloudTypeV2(q *sqlchemy.SQuery, input *api.CloudType
|
||||
sq = sq.Filter(sqlchemy.In(sq.Field("manager_id"), CloudproviderManager.GetPublicProviderIdsQuery()))
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
}
|
||||
}
|
||||
|
||||
if input.CloudEnv == api.CLOUD_ENV_PRIVATE_CLOUD || input.PrivateCloud || input.IsPrivate {
|
||||
case api.CLOUD_ENV_PRIVATE_CLOUD:
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(sqlchemy.In(q.Field("manager_id"), CloudproviderManager.GetPrivateProviderIdsQuery()))
|
||||
} else {
|
||||
@@ -429,9 +357,7 @@ func managedResourceFilterByCloudTypeV2(q *sqlchemy.SQuery, input *api.CloudType
|
||||
sq = sq.Filter(sqlchemy.In(sq.Field("manager_id"), CloudproviderManager.GetPrivateProviderIdsQuery()))
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
}
|
||||
}
|
||||
|
||||
if input.CloudEnv == api.CLOUD_ENV_ON_PREMISE || input.IsOnPremise {
|
||||
case api.CLOUD_ENV_ON_PREMISE:
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(
|
||||
sqlchemy.OR(
|
||||
@@ -449,6 +375,24 @@ func managedResourceFilterByCloudTypeV2(q *sqlchemy.SQuery, input *api.CloudType
|
||||
)
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
}
|
||||
case api.CLOUD_ENV_PRIVATE_ON_PREMISE:
|
||||
if len(filterField) == 0 {
|
||||
q = q.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.In(q.Field("manager_id"), CloudproviderManager.GetPrivateOrOnPremiseProviderIdsQuery()),
|
||||
sqlchemy.IsNullOrEmpty(q.Field("manager_id")),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
sq := subqFunc()
|
||||
sq = sq.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.In(sq.Field("manager_id"), CloudproviderManager.GetPrivateOrOnPremiseProviderIdsQuery()),
|
||||
sqlchemy.IsNullOrEmpty(sq.Field("manager_id")),
|
||||
),
|
||||
)
|
||||
q = q.Filter(sqlchemy.In(q.Field(filterField), sq.SubQuery()))
|
||||
}
|
||||
}
|
||||
|
||||
if input.IsManaged {
|
||||
|
||||
@@ -64,12 +64,12 @@ type SNatDEntry struct {
|
||||
IpProtocol string `width:"8" charset:"ascii" list:"user" create:"required"`
|
||||
}
|
||||
|
||||
func (man *SNatDEntryManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SNatEntryManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SNatDEntryManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.NatDEntryListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SNatEntryManager.ListItemFilter(ctx, q, userCred, query.NatEntryListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SNatEntryManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
return validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "natgateway", ModelKeyword: "natgateway", OwnerId: userCred},
|
||||
})
|
||||
|
||||
@@ -89,12 +89,12 @@ func (self *SNatGateway) AllowDeleteItem(ctx context.Context, userCred mcclient.
|
||||
return db.IsAdminAllowDelete(userCred, self)
|
||||
}
|
||||
|
||||
func (man *SNatGetewayManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SNatGetewayManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.NatGetewayListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
data := query.(*jsonutils.JSONDict)
|
||||
data := jsonutils.Marshal(query).(*jsonutils.JSONDict)
|
||||
q, err = validators.ApplyModelFilters(q, data, []*validators.ModelFilterOptions{
|
||||
{Key: "vpc", ModelKeyword: "vpc", OwnerId: userCred},
|
||||
{Key: "cloudregion", ModelKeyword: "cloudregion", OwnerId: userCred},
|
||||
@@ -102,9 +102,9 @@ func (man *SNatGetewayManager) ListItemFilter(ctx context.Context, q *sqlchemy.S
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q, err = managedResourceFilterByAccount(q, query, "", nil)
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "managedResourceFilterByAccount")
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
@@ -596,13 +596,13 @@ func (self *SNatEntry) GetNatgateway() (*SNatGateway, error) {
|
||||
return model.(*SNatGateway), nil
|
||||
}
|
||||
|
||||
func (man *SNatEntryManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query)
|
||||
func (man *SNatEntryManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query api.NatEntryListInput) (*sqlchemy.SQuery, error) {
|
||||
q, err := man.SStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
q, err = managedResourceFilterByAccount(q, query, "natgateway_id", func() *sqlchemy.SQuery {
|
||||
q, err = managedResourceFilterByAccount(q, query.ManagedResourceListInput, "natgateway_id", func() *sqlchemy.SQuery {
|
||||
natgateways := NatGatewayManager.Query().SubQuery()
|
||||
return natgateways.Query(natgateways.Field("id"))
|
||||
})
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user