根据调度标签过滤网络和存储资源

This commit is contained in:
Qu Xuan
2020-05-18 12:03:10 +08:00
parent 6ea25e6fcc
commit 888a5463ab
6 changed files with 33 additions and 5 deletions
+1
View File
@@ -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"`
}
+6 -5
View File
@@ -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)
+1
View File
@@ -65,6 +65,7 @@ type NetworkFilterListInput struct {
type NetworkListInput struct {
apis.SharableVirtualResourceListInput
apis.ExternalizedResourceBaseListInput
SchedtagResourceInput
WireFilterListInput
HostResourceInput
+1
View File
@@ -174,6 +174,7 @@ type StorageShareFilterListInput struct {
type StorageListInput struct {
apis.EnabledStatusInfrasResourceBaseListInput
apis.ExternalizedResourceBaseListInput
SchedtagResourceInput
ManagedResourceListInput
ZonalFilterListInput
+12
View File
@@ -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)
}
+12
View File
@@ -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()