diff --git a/pkg/apis/compute/host.go b/pkg/apis/compute/host.go index b6b32730c6..ecd85b1550 100644 --- a/pkg/apis/compute/host.go +++ b/pkg/apis/compute/host.go @@ -101,8 +101,10 @@ type HostListInput struct { CpuCount []int `json:"cpu_count"` // 内存大小,单位Mb MemSize []int `json:"mem_size"` - // 存储类型 + // 存储类型(磁盘类型,sdd, rotate, hybrid) StorageType []string `json:"storage_type"` + // 宿主机绑定存储类型 + HostStorageType []string `json:"host_storage_type"` // IPMI地址 IpmiIp []string `json:"ipmi_ip"` // 宿主机状态 diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index f539bd427b..8f83b28bfd 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -332,6 +332,15 @@ func (manager *SHostManager) ListItemFilter( } } + hostStorageType := query.HostStorageType + if len(hostStorageType) > 0 { + hoststorages := HoststorageManager.Query() + storages := StorageManager.Query().In("storage_type", hostStorageType).SubQuery() + hq := hoststorages.Join(storages, sqlchemy.Equals(hoststorages.Field("storage_id"), storages.Field("id"))).SubQuery() + scopeQuery := hq.Query(hq.Field("host_id")).SubQuery() + q = q.In("id", scopeQuery) + } + hypervisorStr := query.Hypervisor if len(hypervisorStr) > 0 { hostType, ok := api.HYPERVISOR_HOSTTYPE[hypervisorStr] diff --git a/pkg/mcclient/options/compute/host.go b/pkg/mcclient/options/compute/host.go index 1c90d70771..930ecbe601 100644 --- a/pkg/mcclient/options/compute/host.go +++ b/pkg/mcclient/options/compute/host.go @@ -21,20 +21,21 @@ import ( ) type HostListOptions struct { - Schedtag string `help:"List hosts in schedtag"` - Zone string `help:"List hosts in zone"` - Region string `help:"List hosts in region"` - Wire string `help:"List hosts in wire"` - Image string `help:"List hosts cached images" json:"cachedimage"` - Storage string `help:"List hosts attached to storages"` - Baremetal string `help:"List hosts that is managed by baremetal system" choices:"true|false"` - Empty bool `help:"show empty host" json:"-"` - Occupied bool `help:"show occupid host" json:"-"` - Enabled bool `help:"Show enabled host only" json:"-"` - Disabled bool `help:"Show disabled host only" json:"-"` - HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv|aliyun|azure|qcloud|aws|huawei|ucloud|google|ctyun"` - AnyMac string `help:"Mac matches one of the host's interface"` - AnyIp []string `help:"IP matches one of the host's interface"` + Schedtag string `help:"List hosts in schedtag"` + Zone string `help:"List hosts in zone"` + Region string `help:"List hosts in region"` + Wire string `help:"List hosts in wire"` + Image string `help:"List hosts cached images" json:"cachedimage"` + Storage string `help:"List hosts attached to storages"` + Baremetal string `help:"List hosts that is managed by baremetal system" choices:"true|false"` + Empty bool `help:"show empty host" json:"-"` + Occupied bool `help:"show occupid host" json:"-"` + Enabled bool `help:"Show enabled host only" json:"-"` + Disabled bool `help:"Show disabled host only" json:"-"` + HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv|aliyun|azure|qcloud|aws|huawei|ucloud|google|ctyun"` + AnyMac string `help:"Mac matches one of the host's interface"` + AnyIp []string `help:"IP matches one of the host's interface"` + HostStorageType []string `help:"List host in host_storage_type"` IsBaremetal *bool `help:"filter host list by is_baremetal=true|false"`