Skip to content

Commit

Permalink
fix(yunionconf): add predefine tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito committed May 28, 2024
1 parent c900efe commit 15cbef5
Show file tree
Hide file tree
Showing 38 changed files with 360 additions and 83 deletions.
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/baremetalnetworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ func init() {
R(&HostNetworkListOptions{}, "host-network-list", "List baremetal network pairs", func(s *mcclient.ClientSession, args *HostNetworkListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
if len(args.Network) > 0 {
params.Add(jsonutils.NewString(args.Network), "network_id")
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/baremetalstorages.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ func init() {
R(&BaremetalStorageListOptions{}, "baremetal-storage-list", "List baremetal storage pairs", func(s *mcclient.ClientSession, args *BaremetalStorageListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
var result *printutils.ListResult
var err error
Expand Down
3 changes: 2 additions & 1 deletion cmd/climc/shell/compute/cloudprovider_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func init() {
}

R(&CloudproviderQuotaListOptions{}, "cloud-provider-quota-list", "List cloudprovider quota", func(s *mcclient.ClientSession, args *CloudproviderQuotaListOptions) error {
params, err := args.Params()
param, err := args.Params()
if err != nil {
return err
}
params := param.(*jsonutils.JSONDict)

if len(args.QuotaType) > 0 {
params.Add(jsonutils.NewString(args.QuotaType), "quota_type")
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/cloudproviderregions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ func init() {
R(&CloudproviderRegionListOptions{}, "cloud-provider-region-list", "List cloudprovider region synchronization status", func(s *mcclient.ClientSession, args *CloudproviderRegionListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
var result *printutils.ListResult
var err error
Expand Down
4 changes: 2 additions & 2 deletions cmd/climc/shell/compute/dynamicschedtags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func init() {
R(&DynamicschedtagListOptions{}, "dynamic-schedtag-list", "List dynamic schedtag conditions", func(s *mcclient.ClientSession, args *DynamicschedtagListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err
}
params = param.(*jsonutils.JSONDict)
}
results, err := modules.Dynamicschedtags.List(s, params)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/hostcachedimages.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ func init() {
R(&HostCachedImageListOptions{}, "host-cachedimage-list", "List host cached image pairs", func(s *mcclient.ClientSession, args *HostCachedImageListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
var result *printutils.ListResult
var err error
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/hoststorages.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ func init() {
R(&HostStorageListOptions{}, "host-storage-list", "List host storage pairs", func(s *mcclient.ClientSession, args *HostStorageListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
var result *printutils.ListResult
var err error
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/isolated_device_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ func init() {
"List host Isolated device model pairs", func(s *mcclient.ClientSession, args *HostIsolatedDeviceModelListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
var result *printutils.ListResult
var err error
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/isolatedevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ func init() {
R(&DeviceListOptions{}, "isolated-device-list", "List isolated devices like GPU", func(s *mcclient.ClientSession, args *DeviceListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
if len(args.Host) > 0 {
params.Add(jsonutils.NewString(args.Host), "host")
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/loadbalancernetworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ func init() {
R(&LoadbalancerNetworkListOptions{}, "lbnetwork-list", "List loadbalancer network pairs", func(s *mcclient.ClientSession, args *LoadbalancerNetworkListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
if len(args.Ip) > 0 {
params.Add(jsonutils.NewString(args.Ip), "ip_addr")
Expand Down
15 changes: 1 addition & 14 deletions cmd/climc/shell/compute/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,7 @@ import (
)

func init() {
R(&options.MetadataListOptions{}, "metadata-list", "List metadatas", func(s *mcclient.ClientSession, opts *options.MetadataListOptions) error {
params, err := options.ListStructToParams(opts)
if err != nil {
return err
}
result, err := modules.ComputeMetadatas.List(s, params)
if err != nil {
return err
}
printList(result, []string{})
return nil
})

R(&options.TagListOptions{}, "tag-list", "List tags", func(s *mcclient.ClientSession, opts *options.TagListOptions) error {
R(&options.TagListOptions{}, "metadata-list", "List tags", func(s *mcclient.ClientSession, opts *options.TagListOptions) error {
var mod modulebase.IResourceManager
switch opts.Service {
case "compute":
Expand Down
3 changes: 2 additions & 1 deletion cmd/climc/shell/compute/policy_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ func init() {
Policydefinition string `help:"filter by policydefinition"`
}
R(&PolicyListOptions{}, "policy-assignment-list", "List policy assignments", func(s *mcclient.ClientSession, args *PolicyListOptions) error {
params, err := args.Params()
param, err := args.Params()
if err != nil {
return err
}
params := param.(*jsonutils.JSONDict)
if len(args.Policydefinition) > 0 {
params.Add(jsonutils.NewString(args.Policydefinition), "policydefinition")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/reservedips.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ func init() {
R(&ReservedIPListOptions{}, "reserved-ip-list", "Show all reserved IPs for any network", func(s *mcclient.ClientSession, args *ReservedIPListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
if len(args.Network) > 0 {
params.Add(jsonutils.NewString(args.Network), "network")
Expand Down
4 changes: 2 additions & 2 deletions cmd/climc/shell/compute/schedpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func init() {
R(&SchedpoliciesListOptions{}, "sched-policy-list", "List scheduler policies", func(s *mcclient.ClientSession, args *SchedpoliciesListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err
}
params = param.(*jsonutils.JSONDict)
}
results, err := modules.Schedpolicies.List(s, params)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/serverdisks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ func init() {
R(&ServerDiskListOptions{}, "server-disk-list", "List server disk pairs", func(s *mcclient.ClientSession, args *ServerDiskListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
if args.Index >= 0 {
params.Add(jsonutils.NewInt(args.Index), "index")
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/servernetworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ func init() {
R(&ServerNetworkListOptions{}, "server-network-list", "List server network pairs", func(s *mcclient.ClientSession, args *ServerNetworkListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
if len(args.Mac) > 0 {
params.Add(jsonutils.NewString(args.Mac), "mac_addr")
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/serversecgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ func init() {
R(&ServerSecgroupListOptions{}, "server-secgroup-list", "List server secgroup pairs", func(s *mcclient.ClientSession, args *ServerSecgroupListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
var result *printutils.ListResult
var err error
Expand Down
15 changes: 6 additions & 9 deletions cmd/climc/shell/compute/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ func init() {
R(&ListOptions{}, "spec", "List all kinds of model specs", func(s *mcclient.ClientSession, args *ListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
model := ""
if len(args.Model) != 0 {
Expand Down Expand Up @@ -108,12 +107,11 @@ func init() {
}
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
if len(args.HostType) > 0 {
params.Add(jsonutils.NewString(args.HostType), "host_type")
Expand Down Expand Up @@ -153,12 +151,11 @@ func init() {
}
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
resp, err := modules.Specs.SpecsQueryModelObjects(s, "isolated_devices", newSpecKeys(), params)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/storagecachedimages.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ func init() {
R(&StorageCachedImageListOptions{}, "storage-cached-image-list", "List storage cached image pairs", func(s *mcclient.ClientSession, args *StorageCachedImageListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
var result *printutils.ListResult
var err error
Expand Down
5 changes: 2 additions & 3 deletions cmd/climc/shell/compute/vcenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ func init() {
R(&VCenterListOptions{}, "vcenter-list", "List VMWare vcenters", func(s *mcclient.ClientSession, args *VCenterListOptions) error {
var params *jsonutils.JSONDict
{
var err error
params, err = args.BaseListOptions.Params()
param, err := args.BaseListOptions.Params()
if err != nil {
return err

}
params = param.(*jsonutils.JSONDict)
}
result, err := modules.VCenters.List(s, params)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/climc/shell/image/imageguest.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ func init() {
R(&GuestImageListOptions{}, "guest-image-list", "List guest images", func(s *mcclient.ClientSession,
args *GuestImageListOptions) error {

params, err := args.Params()
param, err := args.Params()
if err != nil {
return err
}
params := param.(*jsonutils.JSONDict)

if len(args.Name) > 0 {
params.Add(jsonutils.NewString(args.Name), "name")
Expand Down
31 changes: 31 additions & 0 deletions cmd/climc/shell/yunionconf/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package yunionconf

import (
"yunion.io/x/onecloud/cmd/climc/shell"
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionconf"
"yunion.io/x/onecloud/pkg/mcclient/options"
opts "yunion.io/x/onecloud/pkg/mcclient/options/yunionconf"
)

func init() {
cmd := shell.NewResourceCmd(&yunionconf.Tags)
cmd.List(&options.BaseListOptions{})
cmd.Delete(&options.BaseIdOptions{})
cmd.Show(&options.BaseIdOptions{})
cmd.Create(&opts.TagCreateOptions{})
cmd.Update(&opts.TagUpdateOptions{})
}
3 changes: 2 additions & 1 deletion pkg/apihelper/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ func GetDBModels(opts *GetDBModelsOptions) error {
filter := inter.ModelFilter()
listOptions.Filter = append(listOptions.Filter, filter...)
}
params, err := listOptions.Params()
param, err := listOptions.Params()
if err != nil {
return fmt.Errorf("%s: making list params: %s", manKeyPlural, err)
}
params := param.(*jsonutils.JSONDict)
if inter, ok := opts.GetModelSet().(IModelListParam); ok {
filter := inter.ModelParamFilter()
params.Update(filter)
Expand Down
Loading

0 comments on commit 15cbef5

Please # to comment.