mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: disk filter by storage host (#21500)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -41,49 +41,11 @@ import (
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(&modules.Disks)
|
||||
cmd.List(&compute_options.DiskListOptions{})
|
||||
cmd.Perform("set-class-metadata", &options.ResourceMetadataOptions{})
|
||||
cmd.Perform("rebuild", &options.ResourceIdOptions{})
|
||||
cmd.Perform("migrate", &compute_options.DiskMigrateOptions{})
|
||||
|
||||
type DiskListOptions struct {
|
||||
options.BaseListOptions
|
||||
Unused *bool `help:"Show unused disks"`
|
||||
Share *bool `help:"Show Share storage disks"`
|
||||
Local *bool `help:"Show Local storage disks"`
|
||||
Guest string `help:"Guest ID or name"`
|
||||
GuestStatus string `help:"Guest Status"`
|
||||
OrderByServer string `help:"Order By Server"`
|
||||
Storage string `help:"Storage ID or name"`
|
||||
Type string `help:"Disk type" choices:"sys|data|swap|volume"`
|
||||
CloudType string `help:"Public cloud or private cloud" choices:"Public|Private"`
|
||||
|
||||
OrderByGuestCount string `help:"Order By Guest Count"`
|
||||
|
||||
BillingType string `help:"billing type" choices:"postpaid|prepaid"`
|
||||
|
||||
SnapshotpolicyId string `help:"snapshotpolicy id"`
|
||||
}
|
||||
R(&DiskListOptions{}, "disk-list", "List virtual disks", func(s *mcclient.ClientSession, opts *DiskListOptions) error {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(opts.CloudType) > 0 {
|
||||
if opts.CloudType == "Public" {
|
||||
params.Add(jsonutils.JSONTrue, "public_cloud")
|
||||
} else if opts.CloudType == "Private" {
|
||||
params.Add(jsonutils.JSONTrue, "private_cloud")
|
||||
}
|
||||
}
|
||||
|
||||
result, err := modules.Disks.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Disks.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type DiskDetailOptions struct {
|
||||
ID string `help:"ID or Name of disk"`
|
||||
}
|
||||
|
||||
@@ -223,6 +223,9 @@ type StorageResourceInput struct {
|
||||
type StorageFilterListInputBase struct {
|
||||
StorageResourceInput
|
||||
|
||||
// 以host过滤
|
||||
StorageHostId string `json:"storage_host_id"`
|
||||
|
||||
// 以存储名称排序
|
||||
// pattern:asc|desc
|
||||
OrderByStorage string `json:"order_by_storage"`
|
||||
|
||||
@@ -128,6 +128,17 @@ func (manager *SStorageResourceBaseManager) ListItemFilter(
|
||||
}
|
||||
q = q.Equals("storage_id", storageObj.GetId())
|
||||
}
|
||||
if len(query.StorageHostId) > 0 {
|
||||
hostInput := api.HostResourceInput{}
|
||||
hostInput.HostId = query.StorageHostId
|
||||
var err error
|
||||
_, hostInput, err = ValidateHostResourceInput(ctx, userCred, hostInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ValidateHostResourceInput")
|
||||
}
|
||||
hostStoragesQ := HoststorageManager.Query().Equals("host_id", hostInput.HostId).SubQuery()
|
||||
q = q.Join(hostStoragesQ, sqlchemy.Equals(q.Field("storage_id"), hostStoragesQ.Field("storage_id")))
|
||||
}
|
||||
subq := StorageManager.Query("id").Snapshot()
|
||||
subq, err := manager.SZoneResourceBaseManager.ListItemFilter(ctx, subq, userCred, query.ZonalFilterListInput)
|
||||
if err != nil {
|
||||
|
||||
@@ -262,6 +262,8 @@ type BaseListOptions struct {
|
||||
|
||||
Id []string `help:"filter by id"`
|
||||
// Name []string `help:"fitler by name"`
|
||||
|
||||
Status []string `help:"filter by status"`
|
||||
}
|
||||
|
||||
func (opts *BaseListOptions) addTag(keyPrefix, tagstr string, idx int, params *jsonutils.JSONDict) error {
|
||||
|
||||
@@ -91,3 +91,39 @@ func (o *DiskMigrateOptions) GetId() string {
|
||||
func (o *DiskMigrateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(o)
|
||||
}
|
||||
|
||||
type DiskListOptions struct {
|
||||
options.BaseListOptions
|
||||
Unused *bool `help:"Show unused disks"`
|
||||
Share *bool `help:"Show Share storage disks"`
|
||||
Local *bool `help:"Show Local storage disks"`
|
||||
Guest string `help:"Guest ID or name"`
|
||||
GuestStatus string `help:"Guest Status"`
|
||||
OrderByServer string `help:"Order By Server"`
|
||||
Storage string `help:"Storage ID or name"`
|
||||
Type string `help:"Disk type" choices:"sys|data|swap|volume"`
|
||||
CloudType string `help:"Public cloud or private cloud" choices:"Public|Private"`
|
||||
|
||||
OrderByGuestCount string `help:"Order By Guest Count"`
|
||||
|
||||
BillingType string `help:"billing type" choices:"postpaid|prepaid"`
|
||||
|
||||
SnapshotpolicyId string `help:"snapshotpolicy id"`
|
||||
|
||||
StorageHostId string `help:"filter disk by host"`
|
||||
}
|
||||
|
||||
func (opts *DiskListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(opts.CloudType) > 0 {
|
||||
if opts.CloudType == "Public" {
|
||||
params.Add(jsonutils.JSONTrue, "public_cloud")
|
||||
} else if opts.CloudType == "Private" {
|
||||
params.Add(jsonutils.JSONTrue, "private_cloud")
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ type NetworkListOptions struct {
|
||||
IsAutoAlloc *bool `help:"search network with is_auto_alloc"`
|
||||
IsClassic *bool `help:"search classic on-premise network"`
|
||||
|
||||
Status string `help:"filter by network status"`
|
||||
// Status string `help:"filter by network status"`
|
||||
|
||||
GuestIpStart []string `help:"search by guest_ip_start"`
|
||||
GuestIpEnd []string `help:"search by guest_ip_end"`
|
||||
|
||||
Reference in New Issue
Block a user