diff --git a/cmd/climc/shell/compute/networks.go b/cmd/climc/shell/compute/networks.go index f26eeeabb5..73957b7556 100644 --- a/cmd/climc/shell/compute/networks.go +++ b/cmd/climc/shell/compute/networks.go @@ -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"` } diff --git a/cmd/climc/shell/compute/storages.go b/cmd/climc/shell/compute/storages.go index 203ad24b23..6e54572813 100644 --- a/cmd/climc/shell/compute/storages.go +++ b/cmd/climc/shell/compute/storages.go @@ -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) diff --git a/pkg/apis/compute/network.go b/pkg/apis/compute/network.go index 9ef82e7887..3256d31780 100644 --- a/pkg/apis/compute/network.go +++ b/pkg/apis/compute/network.go @@ -65,6 +65,7 @@ type NetworkFilterListInput struct { type NetworkListInput struct { apis.SharableVirtualResourceListInput apis.ExternalizedResourceBaseListInput + SchedtagResourceInput WireFilterListInput HostResourceInput diff --git a/pkg/apis/compute/storage_const.go b/pkg/apis/compute/storage_const.go index dbd70dde35..dd89ff2861 100644 --- a/pkg/apis/compute/storage_const.go +++ b/pkg/apis/compute/storage_const.go @@ -174,6 +174,7 @@ type StorageShareFilterListInput struct { type StorageListInput struct { apis.EnabledStatusInfrasResourceBaseListInput apis.ExternalizedResourceBaseListInput + SchedtagResourceInput ManagedResourceListInput ZonalFilterListInput diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index cc237a198c..d3a645eca9 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -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) } diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 0ba80a0fe4..4f6c0ee0f9 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -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()