mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
mcclient: loadbalancers: allow updating names
- loadbalanceracls: allow updating only name
This commit is contained in:
@@ -39,6 +39,18 @@ func init() {
|
||||
printList(result, modules.LoadbalancerBackendGroups.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerBackendGroupUpdateOptions{}, "lbbackendgroup-update", "Update lbbackendgroup", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendGroupUpdateOptions) error {
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lbbackendgroup, err := modules.LoadbalancerBackendGroups.Update(s, opts.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbbackendgroup)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerBackendGroupDeleteOptions{}, "lbbackendgroup-delete", "Show lbbackendgroup", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendGroupDeleteOptions) error {
|
||||
lbbackendgroup, err := modules.LoadbalancerBackendGroups.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -101,9 +101,12 @@ type SLoadbalancerAcl struct {
|
||||
AclEntries *SLoadbalancerAclEntries `list:"user" update:"user" create:"required"`
|
||||
}
|
||||
|
||||
func loadbalancerAclsValidateAclEntries(data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
func loadbalancerAclsValidateAclEntries(data *jsonutils.JSONDict, update bool) (*jsonutils.JSONDict, error) {
|
||||
aclEntries := SLoadbalancerAclEntries{}
|
||||
aclEntriesV := validators.NewStructValidator("acl_entries", &aclEntries)
|
||||
if update {
|
||||
aclEntriesV.Optional(true)
|
||||
}
|
||||
err := aclEntriesV.Validate(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -112,7 +115,7 @@ func loadbalancerAclsValidateAclEntries(data *jsonutils.JSONDict) (*jsonutils.JS
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerAclManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
data, err := loadbalancerAclsValidateAclEntries(data)
|
||||
data, err := loadbalancerAclsValidateAclEntries(data, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -124,7 +127,7 @@ func (lbacl *SLoadbalancerAcl) AllowPerformStatus(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
data, err := loadbalancerAclsValidateAclEntries(data)
|
||||
data, err := loadbalancerAclsValidateAclEntries(data, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -69,7 +69,9 @@ type LoadbalancerAclListOptions struct {
|
||||
}
|
||||
|
||||
type LoadbalancerAclUpdateOptions struct {
|
||||
ID string `json:"-"`
|
||||
ID string `json:"-"`
|
||||
Name string
|
||||
|
||||
AclEntry []string `help:"acl entry with cidr and comment separated by #, e.g. 10.9.0.0/16#no comment" json:"-"`
|
||||
}
|
||||
|
||||
@@ -99,9 +101,13 @@ func (opts *LoadbalancerAclUpdateOptions) Params() (*jsonutils.JSONDict, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aclEntries := NewAclEntries(opts.AclEntry)
|
||||
aclEntriesJson := jsonutils.Marshal(aclEntries)
|
||||
params.Set("acl_entries", aclEntriesJson)
|
||||
// - when it's nil, we leave it alone without updating
|
||||
// - when it's non-nil, we update it as a whole
|
||||
if opts.AclEntry != nil {
|
||||
aclEntries := NewAclEntries(opts.AclEntry)
|
||||
aclEntriesJson := jsonutils.Marshal(aclEntries)
|
||||
params.Set("acl_entries", aclEntriesJson)
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,8 @@ type LoadbalancerAgentGetOptions struct {
|
||||
}
|
||||
|
||||
type LoadbalancerAgentUpdateOptions struct {
|
||||
ID string
|
||||
ID string
|
||||
Name string
|
||||
|
||||
HbTimeout *int
|
||||
|
||||
|
||||
@@ -4,12 +4,20 @@ type LoadbalancerBackendGroupCreateOptions struct {
|
||||
NAME string
|
||||
Loadbalancer string
|
||||
}
|
||||
|
||||
type LoadbalancerBackendGroupGetOptions struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
type LoadbalancerBackendGroupUpdateOptions struct {
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
type LoadbalancerBackendGroupDeleteOptions struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
type LoadbalancerBackendGroupListOptions struct {
|
||||
BaseListOptions
|
||||
Loadbalancer string
|
||||
|
||||
@@ -19,7 +19,8 @@ type LoadbalancerBackendListOptions struct {
|
||||
}
|
||||
|
||||
type LoadbalancerBackendUpdateOptions struct {
|
||||
ID string
|
||||
ID string
|
||||
Name string
|
||||
|
||||
Weight *int
|
||||
Port *int
|
||||
|
||||
@@ -70,7 +70,8 @@ type LoadbalancerCertificateListOptions struct {
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateUpdateOptions struct {
|
||||
ID string
|
||||
ID string
|
||||
Name string
|
||||
|
||||
Cert string `json:"-" help:"path to certificate file"`
|
||||
Pkey string `json:"-" help:"path to private key file"`
|
||||
|
||||
@@ -18,7 +18,9 @@ type LoadbalancerListenerRuleListOptions struct {
|
||||
}
|
||||
|
||||
type LoadbalancerListenerRuleUpdateOptions struct {
|
||||
ID string
|
||||
ID string
|
||||
Name string
|
||||
|
||||
BackendGroup string
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ type LoadbalancerListenerListOptions struct {
|
||||
}
|
||||
|
||||
type LoadbalancerListenerUpdateOptions struct {
|
||||
ID string
|
||||
ID string
|
||||
Name string
|
||||
|
||||
BackendGroup string
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ type LoadbalancerGetOptions struct {
|
||||
}
|
||||
|
||||
type LoadbalancerUpdateOptions struct {
|
||||
ID string
|
||||
ID string
|
||||
Name string
|
||||
|
||||
BackendGroup string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user