diff --git a/cmd/climc/shell/compute/disks.go b/cmd/climc/shell/compute/disks.go index d3423b2edc..7b8c449de1 100644 --- a/cmd/climc/shell/compute/disks.go +++ b/cmd/climc/shell/compute/disks.go @@ -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"` } diff --git a/pkg/apis/compute/storage_const.go b/pkg/apis/compute/storage_const.go index 19070f6c7c..d8bd8cd235 100644 --- a/pkg/apis/compute/storage_const.go +++ b/pkg/apis/compute/storage_const.go @@ -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"` diff --git a/pkg/compute/models/storageresource.go b/pkg/compute/models/storageresource.go index 5354243234..508c2651c4 100644 --- a/pkg/compute/models/storageresource.go +++ b/pkg/compute/models/storageresource.go @@ -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 { diff --git a/pkg/mcclient/options/base.go b/pkg/mcclient/options/base.go index 2346139540..01b8e642d5 100644 --- a/pkg/mcclient/options/base.go +++ b/pkg/mcclient/options/base.go @@ -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 { diff --git a/pkg/mcclient/options/compute/disks.go b/pkg/mcclient/options/compute/disks.go index 19576bf939..89f2925a4e 100644 --- a/pkg/mcclient/options/compute/disks.go +++ b/pkg/mcclient/options/compute/disks.go @@ -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 +} diff --git a/pkg/mcclient/options/compute/network.go b/pkg/mcclient/options/compute/network.go index 2700d72c7e..d72819b4e7 100644 --- a/pkg/mcclient/options/compute/network.go +++ b/pkg/mcclient/options/compute/network.go @@ -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"`