Merge pull request #3966 from zexi/feature/list-base-input

add list input and rewrite codegen use python
This commit is contained in:
yunion-ci-robot
2019-11-29 10:27:29 +08:00
committed by GitHub
11 changed files with 434 additions and 124 deletions
+1
View File
@@ -46,5 +46,6 @@ type BucketCreateInput struct {
}
type BucketDetail struct {
apis.Meta
SBucket
}
+49
View File
@@ -18,6 +18,55 @@ import (
"yunion.io/x/onecloud/pkg/apis"
)
type ServerListInput struct {
apis.BaseListInput
// 过滤可用区底下的资源
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
Baremetal *bool `json:"baremetal"`
// Show gpu servers
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
WithEip *bool `json:"with_eip"`
// Show Servers without EIP
WithoutEip *bool `json:"without_eip"`
// OS Type choices:"linux|windows|vmware"`
OsType string `json:"os_type"`
// Order by disk size choices:"asc|desc"
OrderByDisk string `json:"order_by_disk"`
// Order by host name choices:"asc|desc"
OrderByHost string `json:"order_by_host"`
// Vpc id or name
Vpc string `json:"vpc"`
// Eip id or name
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"
ResourceType string `json:"resource_type"`
// Billing type choices:"postpaid|prepaid"
BillingType string `json:"billing_type"`
}
type ServerRebuildRootInput struct {
apis.Meta
+22
View File
@@ -0,0 +1,22 @@
package compute
import "yunion.io/x/onecloud/pkg/apis"
type InstanceGroupListInput struct {
apis.BaseListInput
// Filter by service type
ServiceType string `json:"service_type"`
// Filter by parent id
ParentId string `json:"parent_id"`
// Filter by zone id
ZoneId string `json:"zone_id"`
// Filter by guest id or name
Guest string `json:"guest"`
}
type InstanceGroupDetail struct {
apis.Meta
SGroup
GuestCount int64 `json:"guest_count"`
}
+25 -5
View File
@@ -190,7 +190,7 @@ type SDBInstance struct {
SManagedResourceBase
SBillingResourceBase
SCloudregionResourceBase
DisableDelete *bool `json:"disable_delete,omitempty"`
SDeletePreventableResourceBase
MasterInstanceId string `json:"master_instance_id"`
VcpuCount int `json:"vcpu_count"`
VmemSizeMb int `json:"vmem_size_mb"`
@@ -214,7 +214,7 @@ type SDBInstance struct {
// SDBInstanceAccount is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceAccount.
type SDBInstanceAccount struct {
apis.SVirtualResourceBase
apis.SStatusStandaloneResourceBase
apis.SExternalizedResourceBase
Secret string `json:"secret"`
DBInstanceId string `json:"db_instance_id"`
@@ -238,7 +238,7 @@ type SDBInstanceBackup struct {
// SDBInstanceDatabase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDBInstanceDatabase.
type SDBInstanceDatabase struct {
apis.SVirtualResourceBase
apis.SStatusStandaloneResourceBase
apis.SExternalizedResourceBase
CharacterSet string `json:"character_set"`
DBInstanceId string `json:"db_instance_id"`
@@ -301,6 +301,11 @@ type SDBInstanceSku struct {
ZoneId string `json:"zone_id"`
}
// SDeletePreventableResourceBase is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDeletePreventableResourceBase.
type SDeletePreventableResourceBase struct {
DisableDelete *bool `json:"disable_delete,omitempty"`
}
// SDisk is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SDisk.
type SDisk struct {
apis.SSharableVirtualResourceBase
@@ -340,10 +345,10 @@ type SElasticcache struct {
apis.SExternalizedResourceBase
SBillingResourceBase
SManagedResourceBase
SDeletePreventableResourceBase
SCloudregionResourceBase
SZoneResourceBase
SlaveZones string `json:"slave_zones"`
DisableDelete *bool `json:"disable_delete,omitempty"`
InstanceType string `json:"instance_type"`
CapacityMB int `json:"capacity_mb"`
LocalCategory string `json:"local_category"`
@@ -466,6 +471,21 @@ type SExternalProject struct {
apis.SExternalizedResourceBase
}
// SGlobalNetwork is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGlobalNetwork.
type SGlobalNetwork struct {
apis.SEnabledStatusStandaloneResourceBase
apis.SExternalizedResourceBase
SManagedResourceBase
Provider string `json:"provider"`
}
// SGlobalnetworkVpc is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGlobalnetworkVpc.
type SGlobalnetworkVpc struct {
apis.SJointResourceBase
GlobalnetworkId string `json:"globalnetwork_id"`
VpcId string `json:"vpc_id"`
}
// SGroup is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SGroup.
type SGroup struct {
apis.SVirtualResourceBase
@@ -505,10 +525,10 @@ type SGuest struct {
apis.SVirtualResourceBase
apis.SExternalizedResourceBase
SBillingResourceBase
SDeletePreventableResourceBase
VcpuCount int `json:"vcpu_count"`
VmemSize int `json:"vmem_size"`
BootOrder string `json:"boot_order"`
DisableDelete *bool `json:"disable_delete,omitempty"`
ShutdownBehavior string `json:"shutdown_behavior"`
KeypairId string `json:"keypair_id"`
HostId string `json:"host_id"`
+77
View File
@@ -0,0 +1,77 @@
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"`
// TODO: support this tags
// Tags []string `help:"Tags info, eg: hypervisor=aliyun, os_type=Linux, os_version" json:"-"`
// UserTags []string `help:"UserTags info, eg: group=rd" json:"-"`
// CloudTags []string `help:"CloudTags info, eg: price_key=cn-beijing" json:"-"`
// List objects belonging to the cloud provider
Manager string `json:"manager,omitempty"`
// List objects belonging to the cloud account
Account string `json:"account,omitempty"`
// List objects from the provider, choices:"OneCloud|VMware|Aliyun|Qcloud|Azure|Aws|Huawei|OpenStack|Ucloud|ZStack"
Provider []string `json:"provider,omitempty"`
// List objects belonging to a special brand
Brand []string `json:"brand"`
// Cloud environment, choices:"public|private|onpremise|private_or_onpremise"
CloudEnv string `json:"cloud_env,omitempty"`
// List objects belonging to public cloud
PublicCloud *bool `json:"public_cloud"`
// List objects belonging to private cloud
PrivateCloud *bool `json:"private_cloud"`
// List objects belonging to on premise infrastructures
IsOnPremise *bool `json:"is_on_premise"`
// List objects managed by external providers
IsManaged *bool `json:"is_managed"`
// Marker for pagination
PagingMarker string `json:"paging_marker"`
}
+3 -3
View File
@@ -724,15 +724,15 @@ func getItemDetails(manager IModelManager, item IModel, ctx context.Context, use
jsonDict := jsonutils.Marshal(item).(*jsonutils.JSONDict)
jsonDict = jsonDict.CopyIncludes(getFields...)
jsonDict.Update(extraDict)
extraDict.Update(jsonDict)
// jsonDict = getModelExtraDetails(item, ctx, jsonDict)
extraRows := manager.FetchCustomizeColumns(ctx, userCred, query, []IModel{item}, stringutils2.NewSortedStrings(fieldFilter))
if len(extraRows) == 1 {
jsonDict.Update(extraRows[0])
extraDict.Update(extraRows[0])
}
return jsonDict, nil
return extraDict, nil
}
func (dispatcher *DBModelDispatcher) tryGetModelProperty(ctx context.Context, property string, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
+11 -8
View File
@@ -27,6 +27,7 @@ import (
"yunion.io/x/pkg/util/sets"
"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"
@@ -73,9 +74,8 @@ type SGroup struct {
}
func (sm *SGroupManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential,
query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
guestFilter := jsonutils.GetAnyString(query, []string{"server", "guest"})
input *api.InstanceGroupListInput) (*sqlchemy.SQuery, error) {
guestFilter := input.Guest
if len(guestFilter) != 0 {
guestObj, err := GuestManager.FetchByIdOrName(userCred, guestFilter)
if err != nil {
@@ -91,11 +91,11 @@ func (group *SGroup) GetCustomizeColumns(ctx context.Context, userCred mcclient.
query jsonutils.JSONObject) *jsonutils.JSONDict {
extra := group.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
ret, _ := group.getMoreDetails(ctx, userCred, extra)
return ret
return ret.JSON(ret)
}
func (group *SGroup) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential,
query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
query jsonutils.JSONObject) (*api.InstanceGroupDetail, error) {
extra, err := group.SVirtualResourceBase.GetExtraDetails(ctx, userCred, query)
if err != nil {
return nil, err
@@ -104,12 +104,15 @@ func (group *SGroup) GetExtraDetails(ctx context.Context, userCred mcclient.Toke
}
func (group *SGroup) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential,
query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
ret := query.(*jsonutils.JSONDict)
data jsonutils.JSONObject) (*api.InstanceGroupDetail, error) {
ret := data.(*jsonutils.JSONDict)
q := GroupguestManager.Query().Equals("group_id", group.Id)
count, _ := q.CountWithError()
ret.Add(jsonutils.NewInt(int64(count)), "guest_count")
return ret, nil
output := new(api.InstanceGroupDetail)
data.Unmarshal(ret)
log.Errorf("output is %#v", output)
return output, nil
}
func (group *SGroup) ValidateDeleteCondition(ctx context.Context) error {
+1
View File
@@ -127,6 +127,7 @@ func (manager *SGuestManager) AllowListItems(ctx context.Context, userCred mccli
return manager.SVirtualResourceBaseManager.AllowListItems(ctx, userCred, query)
}
// 按指定条件列出云主机实例
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 {