mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
根据调度标签过滤网络和存储资源
This commit is contained in:
@@ -38,6 +38,7 @@ func init() {
|
||||
City string `help:"search networks belongs to a city"`
|
||||
Usable *bool `help:"search usable networks"`
|
||||
ServerType string `help:"search networks belongs to a ServerType" choices:"guest|baremetal|container|pxe|ipmi"`
|
||||
Schedtag string `help:"filter networks by schedtag"`
|
||||
|
||||
Status string `help:"filter by network status"`
|
||||
}
|
||||
|
||||
@@ -29,11 +29,12 @@ func init() {
|
||||
type StorageListOptions struct {
|
||||
options.BaseListOptions
|
||||
|
||||
Share *bool `help:"Share storage list"`
|
||||
Local *bool `help:"Local storage list"`
|
||||
Usable *bool `help:"Usable storage list"`
|
||||
Zone string `help:"List storages in zone" json:"-"`
|
||||
Region string `help:"List storages in region"`
|
||||
Share *bool `help:"Share storage list"`
|
||||
Local *bool `help:"Local storage list"`
|
||||
Usable *bool `help:"Usable storage list"`
|
||||
Zone string `help:"List storages in zone" json:"-"`
|
||||
Region string `help:"List storages in region"`
|
||||
Schedtag string `help:"filter storage by schedtag"`
|
||||
}
|
||||
R(&StorageListOptions{}, "storage-list", "List storages", func(s *mcclient.ClientSession, opts *StorageListOptions) error {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
|
||||
@@ -65,6 +65,7 @@ type NetworkFilterListInput struct {
|
||||
type NetworkListInput struct {
|
||||
apis.SharableVirtualResourceListInput
|
||||
apis.ExternalizedResourceBaseListInput
|
||||
SchedtagResourceInput
|
||||
WireFilterListInput
|
||||
|
||||
HostResourceInput
|
||||
|
||||
@@ -174,6 +174,7 @@ type StorageShareFilterListInput struct {
|
||||
type StorageListInput struct {
|
||||
apis.EnabledStatusInfrasResourceBaseListInput
|
||||
apis.ExternalizedResourceBaseListInput
|
||||
SchedtagResourceInput
|
||||
|
||||
ManagedResourceListInput
|
||||
ZonalFilterListInput
|
||||
|
||||
@@ -1800,6 +1800,18 @@ func (manager *SNetworkManager) ListItemFilter(
|
||||
q = q.Filter(ipCondtion)
|
||||
}
|
||||
|
||||
if len(input.Schedtag) > 0 {
|
||||
schedTag, err := SchedtagManager.FetchByIdOrName(nil, input.Schedtag)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(SchedtagManager.Keyword(), input.Schedtag)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
sq := NetworkschedtagManager.Query("network_id").Equals("schedtag_id", schedTag.GetId()).SubQuery()
|
||||
q = q.In("id", sq)
|
||||
}
|
||||
|
||||
if len(input.IfnameHint) > 0 {
|
||||
q = q.In("ifname_hint", input.IfnameHint)
|
||||
}
|
||||
|
||||
@@ -1292,6 +1292,18 @@ func (manager *SStorageManager) ListItemFilter(
|
||||
q = q.Filter(sqlchemy.In(q.Field("storage_type"), api.STORAGE_LOCAL_TYPES))
|
||||
}
|
||||
|
||||
if len(query.Schedtag) > 0 {
|
||||
schedTag, err := SchedtagManager.FetchByIdOrName(nil, query.Schedtag)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(SchedtagManager.Keyword(), query.Schedtag)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
sq := StorageschedtagManager.Query("storage_id").Equals("schedtag_id", schedTag.GetId()).SubQuery()
|
||||
q = q.In("id", sq)
|
||||
}
|
||||
|
||||
if query.Usable != nil && *query.Usable {
|
||||
hostStorageTable := HoststorageManager.Query().SubQuery()
|
||||
hostTable := HostManager.Query().SubQuery()
|
||||
|
||||
Reference in New Issue
Block a user