mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 12:32:55 +08:00
fix(region): refactor lb acl and cert (#19518)
This commit is contained in:
@@ -15,144 +15,21 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/util/printutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
baseoptions "yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/compute"
|
||||
)
|
||||
|
||||
func init() {
|
||||
lbAclConvert := func(jd *jsonutils.JSONDict) error {
|
||||
jaeso, err := jd.Get("acl_entries")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
aclEntries := options.AclEntries{}
|
||||
err = jaeso.Unmarshal(&aclEntries)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
aclTextLines := aclEntries.String()
|
||||
jd.Set("acl_entries", jsonutils.NewString(aclTextLines))
|
||||
return nil
|
||||
}
|
||||
|
||||
printLbAcl := func(jsonObj jsonutils.JSONObject) {
|
||||
jd, ok := jsonObj.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
printObject(jsonObj)
|
||||
return
|
||||
}
|
||||
err := lbAclConvert(jd)
|
||||
if err != nil {
|
||||
printObject(jsonObj)
|
||||
return
|
||||
}
|
||||
printObject(jd)
|
||||
}
|
||||
printLbAclList := func(list *printutils.ListResult, columns []string) {
|
||||
data := list.Data
|
||||
for _, jsonObj := range data {
|
||||
jd := jsonObj.(*jsonutils.JSONDict)
|
||||
err := lbAclConvert(jd)
|
||||
if err != nil {
|
||||
printList(list, columns)
|
||||
return
|
||||
}
|
||||
}
|
||||
printList(list, columns)
|
||||
}
|
||||
|
||||
R(&options.LoadbalancerAclCreateOptions{}, "lbacl-create", "Create lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lbacl, err := modules.LoadbalancerAcls.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclGetOptions{}, "lbacl-show", "Show lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclGetOptions) error {
|
||||
lbacl, err := modules.LoadbalancerAcls.Get(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclListOptions{}, "lbacl-list", "List lbacls", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclListOptions) error {
|
||||
params, err := baseoptions.ListStructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.LoadbalancerAcls.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAclList(result, modules.LoadbalancerAcls.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclUpdateOptions{}, "lbacl-update", "Update lbacls", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclUpdateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lbacl, err := modules.LoadbalancerAcls.Update(s, opts.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclDeleteOptions{}, "lbacl-purge", "Purge lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclDeleteOptions) error {
|
||||
lbacl, err := modules.LoadbalancerAcls.PerformAction(s, opts.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclDeleteOptions{}, "lbacl-delete", "Show lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclDeleteOptions) error {
|
||||
lbacl, err := modules.LoadbalancerAcls.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclActionPatchOptions{}, "lbacl-patch", "Patch lbacls", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclActionPatchOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lbacl, err := modules.LoadbalancerAcls.PerformAction(s, opts.ID, "patch", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclPublicOptions{}, "lbacl-public", "Public lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclPublicOptions) error {
|
||||
params := jsonutils.Marshal(opts)
|
||||
lbacl, err := modules.LoadbalancerAcls.PerformAction(s, opts.ID, "public", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclPrivateOptions{}, "lbacl-private", "Private lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclPrivateOptions) error {
|
||||
lbacl, err := modules.LoadbalancerAcls.PerformAction(s, opts.ID, "private", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
cmd := shell.NewResourceCmd(&modules.LoadbalancerAcls).WithKeyword("lbacl")
|
||||
cmd.List(&options.LoadbalancerAclListOptions{})
|
||||
cmd.Show(&options.LoadbalancerAclIdOptions{})
|
||||
cmd.Create(&options.LoadbalancerAclCreateOptions{})
|
||||
cmd.Delete(&options.LoadbalancerAclIdOptions{})
|
||||
cmd.Update(&options.LoadbalancerAclUpdateOptions{})
|
||||
cmd.Perform("purge", &options.LoadbalancerAclIdOptions{})
|
||||
cmd.Perform("syncstatus", &options.LoadbalancerAclIdOptions{})
|
||||
cmd.Perform("private", &options.LoadbalancerAclIdOptions{})
|
||||
cmd.Perform("public", &options.LoadbalancerAclPublicOptions{})
|
||||
cmd.Perform("patch", &options.LoadbalancerAclActionPatchOptions{})
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
// 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 compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/util/printutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/compute"
|
||||
)
|
||||
|
||||
func init() {
|
||||
lbAclConvert := func(jd *jsonutils.JSONDict) error {
|
||||
jaeso, err := jd.Get("acl_entries")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
aclEntries := options.AclEntries{}
|
||||
err = jaeso.Unmarshal(&aclEntries)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
aclTextLines := aclEntries.String()
|
||||
jd.Set("acl_entries", jsonutils.NewString(aclTextLines))
|
||||
return nil
|
||||
}
|
||||
|
||||
printLbAcl := func(jsonObj jsonutils.JSONObject) {
|
||||
jd, ok := jsonObj.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
printObject(jsonObj)
|
||||
return
|
||||
}
|
||||
err := lbAclConvert(jd)
|
||||
if err != nil {
|
||||
printObject(jsonObj)
|
||||
return
|
||||
}
|
||||
printObject(jd)
|
||||
}
|
||||
printLbAclList := func(list *printutils.ListResult, columns []string) {
|
||||
data := list.Data
|
||||
for _, jsonObj := range data {
|
||||
jd := jsonObj.(*jsonutils.JSONDict)
|
||||
err := lbAclConvert(jd)
|
||||
if err != nil {
|
||||
printList(list, columns)
|
||||
return
|
||||
}
|
||||
}
|
||||
printList(list, columns)
|
||||
}
|
||||
|
||||
R(&options.LoadbalancerAclGetOptions{}, "lbacl-cache-show", "Show cached lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclGetOptions) error {
|
||||
lbacl, err := modules.LoadbalancerCachedAcls.Get(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.CachedLoadbalancerAclListOptions{}, "lbacl-cache-list", "List cached lbacls", func(s *mcclient.ClientSession, opts *options.CachedLoadbalancerAclListOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.LoadbalancerCachedAcls.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAclList(result, modules.LoadbalancerCachedAcls.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.LoadbalancerCachedAclCreateOptions{}, "lbacl-cache-create", "Create cached lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerCachedAclCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lbacl, err := modules.LoadbalancerCachedAcls.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(lbacl)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.LoadbalancerAclDeleteOptions{}, "lbacl-cache-purge", "Purge cached lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclDeleteOptions) error {
|
||||
lbacl, err := modules.LoadbalancerCachedAcls.PerformAction(s, opts.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerAclDeleteOptions{}, "lbacl-cache-delete", "Delete cached lbacl", func(s *mcclient.ClientSession, opts *options.LoadbalancerAclDeleteOptions) error {
|
||||
lbacl, err := modules.LoadbalancerCachedAcls.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printLbAcl(lbacl)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
// 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 compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/compute"
|
||||
)
|
||||
|
||||
func init() {
|
||||
R(&options.LoadbalancerCertificateGetOptions{}, "lbcert-cache-show", "Show cached lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateGetOptions) error {
|
||||
lbcert, err := modules.LoadbalancerCachedCertificates.Get(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.LoadbalancerCachedCertificateListOptions{}, "lbcert-cache-list", "List cached lbcerts", func(s *mcclient.ClientSession, opts *options.LoadbalancerCachedCertificateListOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.LoadbalancerCachedCertificates.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.LoadbalancerCachedCertificates.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.LoadbalancerCachedCertificateCreateOptions{}, "lbcert-cache-create", "Create cached lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCachedCertificateCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lbcert, err := modules.LoadbalancerCachedCertificates.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&options.LoadbalancerCertificateDeleteOptions{}, "lbcert-cache-delete", "Delete cached lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateDeleteOptions) error {
|
||||
lbcert, err := modules.LoadbalancerCachedCertificates.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerCertificateDeleteOptions{}, "lbcert-cache-purge", "Purge cached lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateDeleteOptions) error {
|
||||
lbcert, err := modules.LoadbalancerCachedCertificates.PerformAction(s, opts.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -15,81 +15,19 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/compute"
|
||||
)
|
||||
|
||||
func init() {
|
||||
R(&options.LoadbalancerCertificateCreateOptions{}, "lbcert-create", "Create lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateCreateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lbcert, err := modules.LoadbalancerCertificates.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerCertificateGetOptions{}, "lbcert-show", "Show lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateGetOptions) error {
|
||||
lbcert, err := modules.LoadbalancerCertificates.Get(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerCertificateListOptions{}, "lbcert-list", "List lbcerts", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateListOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.LoadbalancerCertificates.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.LoadbalancerCertificates.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerCertificateUpdateOptions{}, "lbcert-update", "Update lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateUpdateOptions) error {
|
||||
params, err := opts.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lbcert, err := modules.LoadbalancerCertificates.Update(s, opts.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerCertificateDeleteOptions{}, "lbcert-delete", "Delete lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificateDeleteOptions) error {
|
||||
lbcert, err := modules.LoadbalancerCertificates.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerCertificatePublicOptions{}, "lbcert-public", "Public lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificatePublicOptions) error {
|
||||
params := jsonutils.Marshal(opts)
|
||||
lbcert, err := modules.LoadbalancerCertificates.PerformAction(s, opts.ID, "public", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerCertificatePrivateOptions{}, "lbcert-private", "Private lbcert", func(s *mcclient.ClientSession, opts *options.LoadbalancerCertificatePrivateOptions) error {
|
||||
lbcert, err := modules.LoadbalancerCertificates.PerformAction(s, opts.ID, "private", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbcert)
|
||||
return nil
|
||||
})
|
||||
cmd := shell.NewResourceCmd(&modules.LoadbalancerCertificates).WithKeyword("lbcert")
|
||||
cmd.Create(&options.LoadbalancerCertificateCreateOptions{})
|
||||
cmd.Show(&options.LoadbalancerCertificateIdOptions{})
|
||||
cmd.Delete(&options.LoadbalancerCertificateIdOptions{})
|
||||
cmd.List(&options.LoadbalancerCertificateListOptions{})
|
||||
cmd.Update(&options.LoadbalancerCertificateUpdateOptions{})
|
||||
cmd.Perform("public", &options.LoadbalancerCertificatePublicOptions{})
|
||||
cmd.Perform("private", &options.LoadbalancerCertificateIdOptions{})
|
||||
cmd.Perform("syncstatus", &options.LoadbalancerCertificateIdOptions{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user