mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +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{})
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240220074040-c367f1e9972c
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240221114447-a32f31a35fd3
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
|
||||
|
||||
@@ -1201,8 +1201,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240220074040-c367f1e9972c h1:JrwRyafRs6P6IcYq1dV5HQ3KbtWQtDP3XMnHMTZjnNc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240220074040-c367f1e9972c/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240221114447-a32f31a35fd3 h1:nTjuhs0Fif0Mhi3kUYwgNhqzuUdb3NVri4LWkwe1O08=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240221114447-a32f31a35fd3/go.mod h1:dsUESXIbXJ+/ywbNClhldOrbPOiBi2udrgOnB/ffoWk=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
@@ -36,9 +33,6 @@ type LoadbalancerAclListInput struct {
|
||||
|
||||
ManagedResourceListInput
|
||||
RegionalFilterListInput
|
||||
|
||||
//
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclDetails struct {
|
||||
@@ -48,7 +42,11 @@ type LoadbalancerAclDetails struct {
|
||||
|
||||
SLoadbalancerAcl
|
||||
|
||||
LbListenerCount int `json:"lb_listener_count"`
|
||||
LoadbalancerAclUsage
|
||||
}
|
||||
|
||||
type LoadbalancerAclUsage struct {
|
||||
ListenerCount int `json:"lb_listener_count"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclResourceInfo struct {
|
||||
@@ -79,15 +77,6 @@ type SAclEntry struct {
|
||||
|
||||
type SAclEntries []SAclEntry
|
||||
|
||||
func (self SAclEntries) GetFingerprint() string {
|
||||
cidrs := []string{}
|
||||
for _, acl := range self {
|
||||
cidrs = append(cidrs, acl.Cidr)
|
||||
}
|
||||
sort.Strings(cidrs)
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(strings.Join(cidrs, ""))))
|
||||
}
|
||||
|
||||
func (self SAclEntries) String() string {
|
||||
return jsonutils.Marshal(self).String()
|
||||
}
|
||||
@@ -125,9 +114,10 @@ func (aclEntry *SAclEntry) Validate() error {
|
||||
type LoadbalancerAclCreateInput struct {
|
||||
apis.SharableVirtualResourceCreateInput
|
||||
|
||||
CloudregionResourceInput
|
||||
CloudproviderResourceInput
|
||||
|
||||
AclEntries SAclEntries `json:"acl_entries"`
|
||||
// swagger: ignore
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateInput) Validate() error {
|
||||
@@ -146,7 +136,6 @@ func (self *LoadbalancerAclCreateInput) Validate() error {
|
||||
}
|
||||
found[acl.Cidr] = true
|
||||
}
|
||||
self.Fingerprint = self.AclEntries.GetFingerprint()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -154,8 +143,6 @@ type LoadbalancerAclUpdateInput struct {
|
||||
apis.SharableVirtualResourceBaseUpdateInput
|
||||
|
||||
AclEntries SAclEntries `json:"acl_entries"`
|
||||
// swagger: ignore
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclUpdateInput) Validate() error {
|
||||
@@ -172,7 +159,6 @@ func (self *LoadbalancerAclUpdateInput) Validate() error {
|
||||
}
|
||||
found[acl.Cidr] = true
|
||||
}
|
||||
self.Fingerprint = self.AclEntries.GetFingerprint()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,10 +23,14 @@ import (
|
||||
type LoadbalancerCertificateDetails struct {
|
||||
apis.SharableVirtualResourceDetails
|
||||
SLoadbalancerCertificate
|
||||
ManagedResourceInfo
|
||||
CloudregionResourceInfo
|
||||
|
||||
LbListenerCount int `json:"lb_listener_count"`
|
||||
// 证书内容是否完整
|
||||
IsComplete bool `json:"is_complete"`
|
||||
LoadbalancerCertificateUsage
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateUsage struct {
|
||||
ListenerCount int `json:"lb_listener_count"`
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateResourceInfo struct {
|
||||
@@ -69,6 +73,9 @@ type LoadbalancerCertificateListInput struct {
|
||||
type LoadbalancerCertificateCreateInput struct {
|
||||
apis.SharableVirtualResourceCreateInput
|
||||
|
||||
CloudregionResourceInput
|
||||
CloudproviderResourceInput
|
||||
|
||||
Certificate string `json:"certificate"`
|
||||
PrivateKey string `json:"private_key"`
|
||||
// swagger: ignore
|
||||
|
||||
@@ -48,13 +48,13 @@ func syncRegionLoadbalancerCertificates(
|
||||
}
|
||||
result := func() compare.SyncResult {
|
||||
defer syncResults.AddSqlCost(LoadbalancerCertificateManager)()
|
||||
return provider.SyncLoadbalancerCertificates(ctx, userCred, localRegion, certificates, syncRange.Xor)
|
||||
return localRegion.SyncLoadbalancerCertificates(ctx, userCred, provider, certificates, syncRange.Xor)
|
||||
}()
|
||||
|
||||
syncResults.Add(CachedLoadbalancerCertificateManager, result)
|
||||
syncResults.Add(LoadbalancerCertificateManager, result)
|
||||
|
||||
msg := result.Result()
|
||||
log.Infof("SyncLoadbalancerCachedCertificates for region %s result: %s", localRegion.Name, msg)
|
||||
log.Infof("SyncLoadbalancerCertificates for region %s result: %s", localRegion.Name, msg)
|
||||
if result.IsError() {
|
||||
return
|
||||
}
|
||||
@@ -80,13 +80,13 @@ func syncRegionLoadbalancerAcls(
|
||||
}
|
||||
result := func() compare.SyncResult {
|
||||
defer syncResults.AddSqlCost(LoadbalancerAclManager)()
|
||||
return CachedLoadbalancerAclManager.SyncLoadbalancerAcls(ctx, userCred, provider, localRegion, acls, syncRange)
|
||||
return localRegion.SyncLoadbalancerAcls(ctx, userCred, provider, acls, syncRange.Xor)
|
||||
}()
|
||||
|
||||
syncResults.Add(CachedLoadbalancerAclManager, result)
|
||||
syncResults.Add(LoadbalancerAclManager, result)
|
||||
|
||||
msg := result.Result()
|
||||
log.Infof("SyncLoadbalancerCachedAcls for region %s result: %s", localRegion.Name, msg)
|
||||
log.Infof("SyncLoadbalancerAcls for region %s result: %s", localRegion.Name, msg)
|
||||
if result.IsError() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ func InitDB() error {
|
||||
LoadbalancerListenerRuleManager,
|
||||
LoadbalancerBackendGroupManager,
|
||||
LoadbalancerBackendManager,
|
||||
CachedLoadbalancerCertificateManager,
|
||||
LoadbalancerClusterManager,
|
||||
SchedtagManager,
|
||||
DynamicschedtagManager,
|
||||
|
||||
@@ -18,15 +18,19 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
@@ -63,41 +67,60 @@ type SLoadbalancerAcl struct {
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
AclEntries *api.SAclEntries `list:"user" update:"user" create:"required"`
|
||||
Fingerprint string `name:"fingerprint" width:"64" charset:"ascii" nullable:"false" index:"true" list:"user" update:"user" create:"required"`
|
||||
// 是否变化
|
||||
IsDirty bool `nullable:"false" default:"false"`
|
||||
AclEntries *api.SAclEntries `list:"user" update:"user" create:"required"`
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerAclManager) FetchByFingerPrint(projectId string, fingerprint string) (*SLoadbalancerAcl, error) {
|
||||
ret := &SLoadbalancerAcl{}
|
||||
q := man.Query().Equals("tenant_id", projectId).Equals("fingerprint", fingerprint).Asc("created_at").Limit(1)
|
||||
err := q.First(ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerAclManager) CountByFingerPrint(projectId string, fingerprint string) int {
|
||||
q := man.Query()
|
||||
return q.Equals("tenant_id", projectId).Equals("fingerprint", fingerprint).Asc("created_at").Count()
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerAclManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.LoadbalancerAclCreateInput) (*api.LoadbalancerAclCreateInput, error) {
|
||||
func (man *SLoadbalancerAclManager) ValidateCreateData(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
ownerId mcclient.IIdentityProvider,
|
||||
query jsonutils.JSONObject,
|
||||
input *api.LoadbalancerAclCreateInput,
|
||||
) (*api.LoadbalancerAclCreateInput, error) {
|
||||
err := input.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
input.Status = api.LB_STATUS_ENABLED
|
||||
input.Status = apis.STATUS_CREATING
|
||||
input.SharableVirtualResourceCreateInput, err = man.SSharableVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.SharableVirtualResourceCreateInput)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(input.CloudregionId) == 0 {
|
||||
input.CloudregionId = api.DEFAULT_REGION_ID
|
||||
}
|
||||
regionObj, err := validators.ValidateModel(ctx, userCred, CloudregionManager, &input.CloudregionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region := regionObj.(*SCloudregion)
|
||||
if len(input.CloudproviderId) > 0 {
|
||||
providerObj, err := validators.ValidateModel(ctx, userCred, CloudproviderManager, &input.CloudproviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
input.ManagerId = input.CloudproviderId
|
||||
provider := providerObj.(*SCloudprovider)
|
||||
if provider.Provider != region.Provider {
|
||||
return nil, httperrors.NewConflictError("conflict region %s and cloudprovider %s", region.Name, provider.Name)
|
||||
}
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerAcl) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
self.SSharableVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
self.StartCreateTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) StartCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclCreateTask", lbacl, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.LoadbalancerAclUpdateInput) (*api.LoadbalancerAclUpdateInput, error) {
|
||||
err := input.Validate()
|
||||
if err != nil {
|
||||
@@ -109,47 +132,70 @@ func (lbacl *SLoadbalancerAcl) ValidateUpdateData(ctx context.Context, userCred
|
||||
return nil, errors.Wrap(err, "SSharableVirtualResourceBase.ValidateUpdateData")
|
||||
}
|
||||
|
||||
if len(input.Fingerprint) > 0 && input.Fingerprint != lbacl.Fingerprint {
|
||||
db.Update(lbacl, func() error {
|
||||
lbacl.IsDirty = true
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lbacl.SSharableVirtualResourceBase.PostUpdate(ctx, userCred, query, data)
|
||||
if lbacl.IsDirty {
|
||||
acls, err := lbacl.GetCachedAcls()
|
||||
if err != nil {
|
||||
log.Errorf("SLoadbalancerAcl PostUpdate %s", err)
|
||||
}
|
||||
|
||||
for i := range acls {
|
||||
acl := acls[i]
|
||||
acl.SetModelManager(CachedLoadbalancerAclManager, &acl)
|
||||
err = acl.StartLoadBalancerAclSyncTask(ctx, userCred, "")
|
||||
if err != nil {
|
||||
log.Errorf("SLoadbalancerAcl PostUpdate %s", err)
|
||||
}
|
||||
}
|
||||
db.Update(lbacl, func() error {
|
||||
lbacl.IsDirty = false
|
||||
return nil
|
||||
})
|
||||
}
|
||||
lbacl.StartLoadBalancerAclUpdateTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) StartLoadBalancerAclSyncTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclSyncTask", lbacl, userCred, nil, parentTaskId, "", nil)
|
||||
func (lbacl *SLoadbalancerAcl) StartLoadBalancerAclUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclUpdateTask", lbacl, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "LoadbalancerAclSyncTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (nm *SLoadbalancerAclManager) query(manager db.IModelManager, field string, aclIds []string, filter func(*sqlchemy.SQuery) *sqlchemy.SQuery) *sqlchemy.SSubQuery {
|
||||
q := manager.Query()
|
||||
|
||||
if filter != nil {
|
||||
q = filter(q)
|
||||
}
|
||||
|
||||
sq := q.SubQuery()
|
||||
|
||||
return sq.Query(
|
||||
sq.Field("acl_id"),
|
||||
sqlchemy.COUNT(field),
|
||||
).In("acl_id", aclIds).GroupBy(sq.Field("acl_id")).SubQuery()
|
||||
}
|
||||
|
||||
type SAclUsageCount struct {
|
||||
Id string
|
||||
api.LoadbalancerAclUsage
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerAclManager) TotalResourceCount(aclIds []string) (map[string]api.LoadbalancerAclUsage, error) {
|
||||
// listener
|
||||
listenerSQ := manager.query(LoadbalancerListenerManager, "listener_cnt", aclIds, nil)
|
||||
|
||||
acls := manager.Query().SubQuery()
|
||||
aclQ := acls.Query(
|
||||
sqlchemy.SUM("lb_listener_count", listenerSQ.Field("listener_cnt")),
|
||||
)
|
||||
|
||||
aclQ.AppendField(aclQ.Field("id"))
|
||||
|
||||
aclQ = aclQ.LeftJoin(listenerSQ, sqlchemy.Equals(aclQ.Field("id"), listenerSQ.Field("acl_id")))
|
||||
aclQ = aclQ.Filter(sqlchemy.In(aclQ.Field("id"), aclIds)).GroupBy(aclQ.Field("id"))
|
||||
|
||||
aclCount := []SAclUsageCount{}
|
||||
err := aclQ.All(&aclCount)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "aclQ.All")
|
||||
}
|
||||
|
||||
result := map[string]api.LoadbalancerAclUsage{}
|
||||
for i := range aclCount {
|
||||
result[aclCount[i].Id] = aclCount[i].LoadbalancerAclUsage
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerAclManager) FetchCustomizeColumns(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
@@ -163,6 +209,7 @@ func (manager *SLoadbalancerAclManager) FetchCustomizeColumns(
|
||||
virtRows := manager.SSharableVirtualResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
managerRows := manager.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
regionRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
aclIds := make([]string, len(objs))
|
||||
|
||||
for i := range rows {
|
||||
rows[i] = api.LoadbalancerAclDetails{
|
||||
@@ -170,18 +217,17 @@ func (manager *SLoadbalancerAclManager) FetchCustomizeColumns(
|
||||
ManagedResourceInfo: managerRows[i],
|
||||
CloudregionResourceInfo: regionRows[i],
|
||||
}
|
||||
acl := objs[i].(*SLoadbalancerAcl)
|
||||
aclIds[i] = acl.Id
|
||||
}
|
||||
|
||||
for i := range objs {
|
||||
q := LoadbalancerListenerManager.Query().Equals("acl_id", objs[i].(*SLoadbalancerAcl).GetId())
|
||||
ownerId, queryScope, err, _ := db.FetchCheckQueryOwnerScope(ctx, userCred, query, LoadbalancerListenerManager, policy.PolicyActionList, true)
|
||||
if err != nil {
|
||||
log.Errorf("FetchCheckQueryOwnerScope error: %v", err)
|
||||
return rows
|
||||
}
|
||||
|
||||
q = LoadbalancerListenerManager.FilterByOwner(ctx, q, LoadbalancerListenerManager, userCred, ownerId, queryScope)
|
||||
rows[i].LbListenerCount, _ = q.CountWithError()
|
||||
usage, err := manager.TotalResourceCount(aclIds)
|
||||
if err != nil {
|
||||
log.Errorf("TotalResourceCount error: %v", err)
|
||||
return rows
|
||||
}
|
||||
for i := range rows {
|
||||
rows[i].LoadbalancerAclUsage, _ = usage[aclIds[i]]
|
||||
}
|
||||
|
||||
return rows
|
||||
@@ -228,9 +274,7 @@ func (lbacl *SLoadbalancerAcl) PerformPatch(ctx context.Context, userCred mcclie
|
||||
}
|
||||
}
|
||||
diff, err := db.Update(lbacl, func() error {
|
||||
// todo: sync diff to clouds
|
||||
lbacl.AclEntries = &entries
|
||||
lbacl.Fingerprint = lbacl.AclEntries.GetFingerprint()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -238,55 +282,43 @@ func (lbacl *SLoadbalancerAcl) PerformPatch(ctx context.Context, userCred mcclie
|
||||
}
|
||||
if len(diff) > 0 {
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_UPDATE, diff, userCred)
|
||||
lbacl.StartLoadBalancerAclUpdateTask(ctx, userCred, "")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) ValidateDeleteCondition(ctx context.Context, info *api.LoadbalancerAclDetails) error {
|
||||
if info != nil && info.LbListenerCount > 0 {
|
||||
return httperrors.NewResourceBusyError("acl %s is still referred to by %d listener", lbacl.Name, info.LbListenerCount)
|
||||
if info != nil && info.ListenerCount > 0 {
|
||||
return httperrors.NewResourceBusyError("acl %s is still referred to by %d listener", lbacl.Name, info.ListenerCount)
|
||||
}
|
||||
return lbacl.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, jsonutils.Marshal(info))
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return nil, lbacl.Delete(ctx, userCred)
|
||||
return nil, lbacl.RealDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
caches, err := lbacl.GetCachedAcls()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetCachedAcls")
|
||||
}
|
||||
|
||||
for i := range caches {
|
||||
err = caches[i].RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "RealDelete")
|
||||
}
|
||||
}
|
||||
|
||||
return lbacl.DoPendingDelete(ctx, userCred)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) StartLoadBalancerAclDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclDeleteTask", lbacl, userCred, params, parentTaskId, "", nil)
|
||||
func (lbacl *SLoadbalancerAcl) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return lbacl.SSharableVirtualResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerAcl) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
return self.StartDeleteTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) StartDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclDeleteTask", lbacl, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
lbacl.SetStatus(ctx, userCred, apis.STATUS_DELETING, "")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) GetCachedAcls() ([]SCachedLoadbalancerAcl, error) {
|
||||
ret := []SCachedLoadbalancerAcl{}
|
||||
q := CachedLoadbalancerAclManager.Query().Equals("acl_id", lbacl.Id)
|
||||
err := db.FetchModelObjects(CachedLoadbalancerAclManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// 负载均衡ACL规则列表
|
||||
func (manager *SLoadbalancerAclManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
@@ -312,10 +344,6 @@ func (manager *SLoadbalancerAclManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if len(input.Fingerprint) > 0 {
|
||||
q = q.In("fingerprint", input.Fingerprint)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -391,6 +419,153 @@ func (manager *SLoadbalancerAclManager) ListItemExportKeys(ctx context.Context,
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerAcl) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
||||
region, err := self.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegion")
|
||||
}
|
||||
provider, err := self.GetDriver(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDriver")
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerAcl) GetILoadbalancerAcl(ctx context.Context) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "empty external id")
|
||||
}
|
||||
iRegion, err := self.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iRegion.GetILoadBalancerAclById(self.ExternalId)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, lbacl, "LoadbalancerAclSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (self *SCloudregion) GetLoadbalancerAcls(managerId string) ([]SLoadbalancerAcl, error) {
|
||||
q := LoadbalancerAclManager.Query().Equals("cloudregion_id", self.Id)
|
||||
if len(managerId) > 0 {
|
||||
q = q.Equals("manager_id", managerId)
|
||||
}
|
||||
ret := []SLoadbalancerAcl{}
|
||||
err := db.FetchModelObjects(LoadbalancerAclManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SCloudregion) SyncLoadbalancerAcls(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, exts []cloudprovider.ICloudLoadbalancerAcl, xor bool) compare.SyncResult {
|
||||
lockman.LockRawObject(ctx, LoadbalancerAclManager.Keyword(), fmt.Sprintf("%s-%s", self.Id, provider.Id))
|
||||
defer lockman.ReleaseRawObject(ctx, LoadbalancerAclManager.Keyword(), fmt.Sprintf("%s-%s", self.Id, provider.Id))
|
||||
|
||||
result := compare.SyncResult{}
|
||||
|
||||
dbAcls, err := self.GetLoadbalancerAcls(provider.Id)
|
||||
if err != nil {
|
||||
result.Error(err)
|
||||
return result
|
||||
}
|
||||
|
||||
removed := make([]SLoadbalancerAcl, 0)
|
||||
commondb := make([]SLoadbalancerAcl, 0)
|
||||
commonext := make([]cloudprovider.ICloudLoadbalancerAcl, 0)
|
||||
added := make([]cloudprovider.ICloudLoadbalancerAcl, 0)
|
||||
|
||||
err = compare.CompareSets(dbAcls, exts, &removed, &commondb, &commonext, &added)
|
||||
if err != nil {
|
||||
result.Error(err)
|
||||
return result
|
||||
}
|
||||
|
||||
for i := 0; i < len(removed); i += 1 {
|
||||
err = removed[i].RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
result.DeleteError(err)
|
||||
continue
|
||||
}
|
||||
result.Delete()
|
||||
}
|
||||
|
||||
for i := 0; i < len(commondb); i += 1 {
|
||||
if !xor {
|
||||
err = commondb[i].SyncWithCloudAcl(ctx, userCred, commonext[i], provider)
|
||||
if err != nil {
|
||||
result.UpdateError(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
result.Update()
|
||||
}
|
||||
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
err := self.newFromCloudAcl(ctx, userCred, provider, added[i])
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
continue
|
||||
}
|
||||
result.Add()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) SyncWithCloudAcl(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudLoadbalancerAcl, provider *SCloudprovider) error {
|
||||
_, err := db.Update(lbacl, func() error {
|
||||
rules := api.SAclEntries{}
|
||||
entries := ext.GetAclEntries()
|
||||
for _, entry := range entries {
|
||||
rules = append(rules, api.SAclEntry{
|
||||
Cidr: entry.CIDR,
|
||||
Comment: entry.Comment,
|
||||
})
|
||||
}
|
||||
lbacl.AclEntries = &rules
|
||||
lbacl.Status = ext.GetStatus()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, lbacl, ext, false)
|
||||
SyncCloudProject(ctx, userCred, lbacl, provider.GetOwnerId(), ext, provider)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudregion) newFromCloudAcl(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, ext cloudprovider.ICloudLoadbalancerAcl) error {
|
||||
acl := &SLoadbalancerAcl{}
|
||||
acl.SetModelManager(LoadbalancerAclManager, acl)
|
||||
acl.ExternalId = ext.GetGlobalId()
|
||||
acl.CloudregionId = self.Id
|
||||
acl.ManagerId = provider.Id
|
||||
acl.Name = ext.GetName()
|
||||
acl.Status = ext.GetStatus()
|
||||
entries := api.SAclEntries{}
|
||||
for _, entry := range ext.GetAclEntries() {
|
||||
entries = append(entries, api.SAclEntry{
|
||||
Cidr: entry.CIDR,
|
||||
Comment: entry.Comment,
|
||||
})
|
||||
}
|
||||
acl.AclEntries = &entries
|
||||
|
||||
err := LoadbalancerAclManager.TableSpec().Insert(ctx, acl)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Insert")
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, acl, ext, false)
|
||||
SyncCloudProject(ctx, userCred, acl, provider.GetOwnerId(), ext, provider)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerAclManager) InitializeData() error {
|
||||
_, err := sqlchemy.GetDB().Exec(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -1,631 +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 models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SCachedLoadbalancerAclManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SStatusStandaloneResourceBaseManager
|
||||
SManagedResourceBaseManager
|
||||
SCloudregionResourceBaseManager
|
||||
SLoadbalancerAclResourceBaseManager
|
||||
}
|
||||
|
||||
var CachedLoadbalancerAclManager *SCachedLoadbalancerAclManager
|
||||
|
||||
func init() {
|
||||
CachedLoadbalancerAclManager = &SCachedLoadbalancerAclManager{
|
||||
SStatusStandaloneResourceBaseManager: db.NewStatusStandaloneResourceBaseManager(
|
||||
SCachedLoadbalancerAcl{},
|
||||
"cachedloadbalanceracls_tbl",
|
||||
"cachedloadbalanceracl",
|
||||
"cachedloadbalanceracls",
|
||||
),
|
||||
}
|
||||
|
||||
CachedLoadbalancerAclManager.SetVirtualObject(CachedLoadbalancerAclManager)
|
||||
}
|
||||
|
||||
type SCachedLoadbalancerAcl struct {
|
||||
db.SStatusStandaloneResourceBase
|
||||
db.SExternalizedResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
SLoadbalancerAclResourceBase
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) ResourceScope() rbacscope.TRbacScope {
|
||||
return rbacscope.ScopeProject
|
||||
}
|
||||
|
||||
func (self *SCachedLoadbalancerAcl) GetOwnerId() mcclient.IIdentityProvider {
|
||||
acl, err := self.GetAcl()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return acl.GetOwnerId()
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) FetchOwnerId(ctx context.Context, data jsonutils.JSONObject) (mcclient.IIdentityProvider, error) {
|
||||
aclId, _ := data.GetString("acl_id")
|
||||
if len(aclId) > 0 {
|
||||
cert, err := db.FetchById(LoadbalancerAclManager, aclId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.FetchById(LoadbalancerAclManager, %s)", aclId)
|
||||
}
|
||||
return cert.(*SLoadbalancerAcl).GetOwnerId(), nil
|
||||
}
|
||||
return db.FetchProjectInfo(ctx, data)
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) FilterByOwner(ctx context.Context, q *sqlchemy.SQuery, man db.FilterByOwnerProvider, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) *sqlchemy.SQuery {
|
||||
if ownerId != nil {
|
||||
sq := LoadbalancerAclManager.Query("id")
|
||||
switch scope {
|
||||
case rbacscope.ScopeProject:
|
||||
sq = sq.Equals("tenant_id", ownerId.GetProjectId())
|
||||
return q.In("acl_id", sq.SubQuery())
|
||||
case rbacscope.ScopeDomain:
|
||||
sq = sq.Equals("domain_id", ownerId.GetProjectDomainId())
|
||||
return q.In("acl_id", sq.SubQuery())
|
||||
}
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.CachedLoadbalancerAclUpdateInput) (*api.CachedLoadbalancerAclUpdateInput, error) {
|
||||
var err error
|
||||
input.StatusStandaloneResourceBaseUpdateInput, err = lbacl.SStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, input.StatusStandaloneResourceBaseUpdateInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBase.ValidateUpdateData")
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) StartLoadBalancerAclSyncTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclSyncTask", lbacl, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerAclManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) StartLoadBalancerAclCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclCreateTask", lbacl, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) GetRegion() (*SCloudregion, error) {
|
||||
region, err := CloudregionManager.FetchById(lbacl.CloudregionId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegion.FetchById(%s)", lbacl.CloudregionId)
|
||||
}
|
||||
return region.(*SCloudregion), nil
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
||||
provider, err := lbacl.GetDriver(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDriver")
|
||||
}
|
||||
region, err := lbacl.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegion")
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerAclManager) FetchCustomizeColumns(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
objs []interface{},
|
||||
fields stringutils2.SSortedStrings,
|
||||
isList bool,
|
||||
) []api.CachedLoadbalancerAclDetails {
|
||||
rows := make([]api.CachedLoadbalancerAclDetails, len(objs))
|
||||
|
||||
stdRows := man.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
manRows := man.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
regionRows := man.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
for i := range rows {
|
||||
rows[i] = api.CachedLoadbalancerAclDetails{
|
||||
StatusStandaloneResourceDetails: stdRows[i],
|
||||
ManagedResourceInfo: manRows[i],
|
||||
CloudregionResourceInfo: regionRows[i],
|
||||
}
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.JSONTrue, "purge")
|
||||
return nil, lbacl.StartLoadBalancerAclDeleteTask(ctx, userCred, params, "")
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbacl.SetStatus(ctx, userCred, api.LB_STATUS_DELETING, "")
|
||||
return lbacl.StartLoadBalancerAclDeleteTask(ctx, userCred, query.(*jsonutils.JSONDict), "")
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) StartLoadBalancerAclDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerAclDeleteTask", lbacl, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return lbacl.SStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SCachedLoadbalancerAcl) syncRemoveCloudLoadbalanceAcl(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
return self.RealDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (acl *SCachedLoadbalancerAcl) SyncWithCloudLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, extAcl cloudprovider.ICloudLoadbalancerAcl, provider *SCloudprovider) error {
|
||||
diff, err := db.UpdateWithLock(ctx, acl, func() error {
|
||||
// todo: 华为云acl没有name字段应此不需要同步名称
|
||||
if options.Options.EnableSyncName && !utils.IsInStringArray(acl.GetProviderName(), []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_HCSO, api.CLOUD_PROVIDER_HCS}) {
|
||||
acl.Name = extAcl.GetName()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cacheLoadbalancerAcl.sync.Update")
|
||||
}
|
||||
if account, _ := provider.GetCloudaccount(); account != nil {
|
||||
syncMetadata(ctx, userCred, acl, extAcl, account.ReadOnly)
|
||||
}
|
||||
db.OpsLog.LogSyncUpdate(acl, diff, userCred)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerAclManager) GetOrCreateCachedAcl(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, lblis *SLoadbalancerListener, acl *SLoadbalancerAcl) (*SCachedLoadbalancerAcl, error) {
|
||||
ownerProjId := provider.ProjectId
|
||||
|
||||
lockman.LockClass(ctx, man, ownerProjId)
|
||||
defer lockman.ReleaseClass(ctx, man, ownerProjId)
|
||||
|
||||
cache, err := func() (*SCachedLoadbalancerAcl, error) {
|
||||
listenerId := ""
|
||||
if utils.IsInStringArray(lblis.GetProviderName(), []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_HCSO, api.CLOUD_PROVIDER_HCS}) {
|
||||
listenerId = lblis.Id
|
||||
}
|
||||
if lblis.GetProviderName() == api.CLOUD_PROVIDER_OPENSTACK {
|
||||
listenerId = lblis.Id
|
||||
}
|
||||
|
||||
region, err := lblis.GetRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lbacl, err := man.getLoadbalancerAclByRegion(provider, region.Id, acl.Id, listenerId)
|
||||
if err == nil {
|
||||
if lbacl.Id != acl.Id {
|
||||
_, err := db.Update(lbacl, func() error {
|
||||
lbacl.Name = acl.Name
|
||||
lbacl.AclId = acl.Id
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return lbacl, nil
|
||||
}
|
||||
|
||||
if errors.Cause(err) != cloudprovider.ErrNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lbacl = &SCachedLoadbalancerAcl{}
|
||||
lbacl.SetModelManager(CachedLoadbalancerAclManager, lbacl)
|
||||
lbacl.ManagerId = provider.Id
|
||||
lbacl.CloudregionId = region.Id
|
||||
lbacl.Name = acl.Name
|
||||
lbacl.AclId = acl.Id
|
||||
|
||||
err = man.TableSpec().Insert(ctx, lbacl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lbacl, err
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(cache.ExternalId) > 0 {
|
||||
return cache, nil
|
||||
}
|
||||
err = cache.CreateIAcl(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateIAcl")
|
||||
}
|
||||
return cache, nil
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) SyncIAcl(ctx context.Context) error {
|
||||
iRegion, err := lbacl.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
acl := &cloudprovider.SLoadbalancerAccessControlList{
|
||||
Name: lbacl.Name,
|
||||
Entrys: []cloudprovider.SLoadbalancerAccessControlListEntry{},
|
||||
}
|
||||
|
||||
localAcl, err := lbacl.GetAcl()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetAcl")
|
||||
}
|
||||
|
||||
if localAcl.AclEntries != nil {
|
||||
for _, entry := range *localAcl.AclEntries {
|
||||
acl.Entrys = append(acl.Entrys, cloudprovider.SLoadbalancerAccessControlListEntry{CIDR: entry.Cidr, Comment: entry.Comment})
|
||||
}
|
||||
}
|
||||
|
||||
lockman.LockRawObject(ctx, "acl", lbacl.Id)
|
||||
defer lockman.ReleaseRawObject(ctx, "acl", lbacl.Id)
|
||||
|
||||
iLoadbalancerAcl, err := iRegion.GetILoadBalancerAclById(lbacl.ExternalId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return iLoadbalancerAcl.Sync(acl)
|
||||
}
|
||||
|
||||
func (lbacl *SCachedLoadbalancerAcl) CreateIAcl(ctx context.Context) error {
|
||||
iRegion, err := lbacl.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
acl := &cloudprovider.SLoadbalancerAccessControlList{
|
||||
Name: lbacl.Name,
|
||||
Entrys: []cloudprovider.SLoadbalancerAccessControlListEntry{},
|
||||
}
|
||||
|
||||
originAcl, err := lbacl.GetAcl()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetAcl")
|
||||
}
|
||||
if originAcl.AclEntries != nil {
|
||||
for _, entry := range *originAcl.AclEntries {
|
||||
acl.Entrys = append(acl.Entrys, cloudprovider.SLoadbalancerAccessControlListEntry{CIDR: entry.Cidr, Comment: entry.Comment})
|
||||
}
|
||||
}
|
||||
iLoadbalancerAcl, err := iRegion.CreateILoadBalancerAcl(acl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = db.Update(lbacl, func() error {
|
||||
lbacl.ExternalId = iLoadbalancerAcl.GetGlobalId()
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerAclManager) getLoadbalancerAclsByRegion(region *SCloudregion, provider *SCloudprovider) ([]SCachedLoadbalancerAcl, error) {
|
||||
acls := []SCachedLoadbalancerAcl{}
|
||||
q := man.Query().Equals("cloudregion_id", region.Id).Equals("manager_id", provider.Id)
|
||||
if err := db.FetchModelObjects(man, q, &acls); err != nil {
|
||||
log.Errorf("failed to get acls for region: %v provider: %v error: %v", region, provider, err)
|
||||
return nil, err
|
||||
}
|
||||
return acls, nil
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerAclManager) getLoadbalancerAclByRegion(provider *SCloudprovider, regionId string, aclId string, listenerId string) (*SCachedLoadbalancerAcl, error) {
|
||||
acls := []SCachedLoadbalancerAcl{}
|
||||
q := man.Query().Equals("cloudregion_id", regionId).Equals("manager_id", provider.Id)
|
||||
// used by huawei only
|
||||
if len(listenerId) > 0 {
|
||||
q.Equals("listener_id", listenerId)
|
||||
} else {
|
||||
q.Equals("acl_id", aclId)
|
||||
}
|
||||
|
||||
if err := db.FetchModelObjects(man, q, &acls); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(acls) >= 1 {
|
||||
return &acls[0], nil
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerAclManager) SyncLoadbalancerAcls(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
provider *SCloudprovider,
|
||||
region *SCloudregion,
|
||||
acls []cloudprovider.ICloudLoadbalancerAcl,
|
||||
syncRange *SSyncRange,
|
||||
) compare.SyncResult {
|
||||
lockman.LockRawObject(ctx, man.Keyword(), fmt.Sprintf("%s-%s", provider.Id, region.Id))
|
||||
defer lockman.ReleaseRawObject(ctx, man.Keyword(), fmt.Sprintf("%s-%s", provider.Id, region.Id))
|
||||
|
||||
syncResult := compare.SyncResult{}
|
||||
|
||||
dbAcls, err := man.getLoadbalancerAclsByRegion(region, provider)
|
||||
if err != nil {
|
||||
syncResult.Error(err)
|
||||
return syncResult
|
||||
}
|
||||
|
||||
removed := []SCachedLoadbalancerAcl{}
|
||||
commondb := []SCachedLoadbalancerAcl{}
|
||||
commonext := []cloudprovider.ICloudLoadbalancerAcl{}
|
||||
added := []cloudprovider.ICloudLoadbalancerAcl{}
|
||||
|
||||
err = compare.CompareSets(dbAcls, acls, &removed, &commondb, &commonext, &added)
|
||||
if err != nil {
|
||||
syncResult.Error(err)
|
||||
return syncResult
|
||||
}
|
||||
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].syncRemoveCloudLoadbalanceAcl(ctx, userCred)
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
syncResult.Delete()
|
||||
}
|
||||
}
|
||||
if !syncRange.Xor {
|
||||
for i := 0; i < len(commondb); i++ {
|
||||
err = commondb[i].SyncWithCloudLoadbalancerAcl(ctx, userCred, commonext[i], provider)
|
||||
if err != nil {
|
||||
syncResult.UpdateError(err)
|
||||
} else {
|
||||
syncResult.Update()
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(added); i++ {
|
||||
_, err := man.newFromCloudLoadbalancerAcl(ctx, userCred, provider, added[i], region, provider.GetOwnerId())
|
||||
if err != nil {
|
||||
syncResult.AddError(err)
|
||||
} else {
|
||||
syncResult.Add()
|
||||
}
|
||||
}
|
||||
return syncResult
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerAclManager) newFromCloudLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extAcl cloudprovider.ICloudLoadbalancerAcl, region *SCloudregion, projectId mcclient.IIdentityProvider) (*SCachedLoadbalancerAcl, error) {
|
||||
acl := SCachedLoadbalancerAcl{}
|
||||
acl.SetModelManager(man, &acl)
|
||||
|
||||
acl.ExternalId = extAcl.GetGlobalId()
|
||||
acl.ManagerId = provider.Id
|
||||
acl.CloudregionId = region.Id
|
||||
acl.Name = extAcl.GetName()
|
||||
|
||||
aclEntites := api.SAclEntries{}
|
||||
for _, entry := range extAcl.GetAclEntries() {
|
||||
aclEntites = append(aclEntites, api.SAclEntry{Cidr: entry.CIDR, Comment: entry.Comment})
|
||||
}
|
||||
|
||||
f := aclEntites.GetFingerprint()
|
||||
if LoadbalancerAclManager.CountByFingerPrint(provider.ProjectId, f) == 0 {
|
||||
localAcl := &SLoadbalancerAcl{}
|
||||
localAcl.SetModelManager(LoadbalancerAclManager, localAcl)
|
||||
localAcl.Name = acl.Name
|
||||
localAcl.Description = acl.Description
|
||||
localAcl.AclEntries = &aclEntites
|
||||
localAcl.Fingerprint = f
|
||||
localAcl.IsPublic = true
|
||||
localAcl.PublicScope = string(rbacscope.ScopeDomain)
|
||||
err := LoadbalancerAclManager.TableSpec().Insert(ctx, localAcl)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cachedLoadbalancerAclManager.new.InsertAcl")
|
||||
}
|
||||
|
||||
SyncCloudProject(ctx, userCred, localAcl, provider.GetOwnerId(), extAcl, provider)
|
||||
}
|
||||
|
||||
{
|
||||
localAcl, err := LoadbalancerAclManager.FetchByFingerPrint(provider.ProjectId, f)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "cachedLoadbalancerAclManager.new.FetchByFingerPrint")
|
||||
}
|
||||
|
||||
acl.AclId = localAcl.GetId()
|
||||
}
|
||||
|
||||
var err = func() error {
|
||||
lockman.LockRawObject(ctx, man.Keyword(), "name")
|
||||
defer lockman.ReleaseRawObject(ctx, man.Keyword(), "name")
|
||||
|
||||
newName, err := db.GenerateName(ctx, man, projectId, extAcl.GetName())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cachedLoadbalancerAclManager.new.GenerateName")
|
||||
}
|
||||
acl.Name = newName
|
||||
return man.TableSpec().Insert(ctx, &acl)
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Insert")
|
||||
}
|
||||
syncMetadata(ctx, userCred, &acl, extAcl, false)
|
||||
|
||||
db.OpsLog.LogEvent(&acl, db.ACT_CREATE, acl.GetShortDesc(ctx), userCred)
|
||||
return &acl, nil
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.CachedLoadbalancerAclListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = manager.SManagedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = manager.SCloudregionResourceBaseManager.ListItemFilter(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
q, err = manager.SLoadbalancerAclResourceBaseManager.ListItemFilter(ctx, q, userCred, query.LoadbalancerAclFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SLoadbalancerAclResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.CachedLoadbalancerAclListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = manager.SManagedResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = manager.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = manager.SLoadbalancerAclResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.LoadbalancerAclFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SLoadbalancerAclResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
q, err = manager.SManagedResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
q, err = manager.SCloudregionResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
q, err = manager.SLoadbalancerAclResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) ListItemExportKeys(ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
keys stringutils2.SSortedStrings,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
if keys.ContainsAny(manager.SManagedResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SManagedResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
if keys.ContainsAny(manager.SCloudregionResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SCloudregionResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
if keys.ContainsAny(manager.SLoadbalancerAclResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SLoadbalancerAclResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SLoadbalancerAclResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerAclManager) InitializeData() error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,578 +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 models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/rand"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
// +onecloud:swagger-gen-ignore
|
||||
type SCachedLoadbalancerCertificateManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SStatusStandaloneResourceBaseManager
|
||||
SManagedResourceBaseManager
|
||||
SCloudregionResourceBaseManager
|
||||
SLoadbalancerCertificateResourceBaseManager
|
||||
}
|
||||
|
||||
var CachedLoadbalancerCertificateManager *SCachedLoadbalancerCertificateManager
|
||||
|
||||
func init() {
|
||||
CachedLoadbalancerCertificateManager = &SCachedLoadbalancerCertificateManager{
|
||||
SStatusStandaloneResourceBaseManager: db.NewStatusStandaloneResourceBaseManager(
|
||||
SCachedLoadbalancerCertificate{},
|
||||
"cachedloadbalancercertificates_tbl",
|
||||
"cachedloadbalancercertificate",
|
||||
"cachedloadbalancercertificates",
|
||||
),
|
||||
}
|
||||
|
||||
CachedLoadbalancerCertificateManager.SetVirtualObject(CachedLoadbalancerCertificateManager)
|
||||
}
|
||||
|
||||
type SCachedLoadbalancerCertificate struct {
|
||||
db.SStatusStandaloneResourceBase
|
||||
db.SExternalizedResourceBase
|
||||
SManagedResourceBase // 云账号ID
|
||||
SCloudregionResourceBase // Region ID
|
||||
|
||||
SLoadbalancerCertificateResourceBase `width:"128" charset:"ascii" nullable:"false" create:"required" index:"true" list:"user"`
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerCertificateManager) ResourceScope() rbacscope.TRbacScope {
|
||||
return rbacscope.ScopeProject
|
||||
}
|
||||
|
||||
func (self *SCachedLoadbalancerCertificate) GetOwnerId() mcclient.IIdentityProvider {
|
||||
cert, err := self.GetCertificate()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return cert.GetOwnerId()
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerCertificateManager) FetchOwnerId(ctx context.Context, data jsonutils.JSONObject) (mcclient.IIdentityProvider, error) {
|
||||
certId, _ := data.GetString("certificate_id")
|
||||
if len(certId) > 0 {
|
||||
cert, err := db.FetchById(LoadbalancerCertificateManager, certId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.FetchById(LoadbalancerCertificateManager, %s)", certId)
|
||||
}
|
||||
return cert.(*SLoadbalancerCertificate).GetOwnerId(), nil
|
||||
}
|
||||
return db.FetchProjectInfo(ctx, data)
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerCertificateManager) FilterByOwner(ctx context.Context, q *sqlchemy.SQuery, man db.FilterByOwnerProvider, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, scope rbacscope.TRbacScope) *sqlchemy.SQuery {
|
||||
if ownerId != nil {
|
||||
sq := LoadbalancerCertificateManager.Query("id")
|
||||
switch scope {
|
||||
case rbacscope.ScopeProject:
|
||||
sq = sq.Equals("tenant_id", ownerId.GetProjectId())
|
||||
return q.In("certificate_id", sq.SubQuery())
|
||||
case rbacscope.ScopeDomain:
|
||||
sq = sq.Equals("domain_id", ownerId.GetProjectDomainId())
|
||||
return q.In("certificate_id", sq.SubQuery())
|
||||
}
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func (self *SCachedLoadbalancerCertificate) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCachedLoadbalancerCertificate) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return self.SStatusStandaloneResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SCachedLoadbalancerCertificate) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
self.SetStatus(ctx, userCred, api.LB_STATUS_DELETING, "")
|
||||
return self.StartLoadBalancerCertificateDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
func (lbcert *SCachedLoadbalancerCertificate) StartLoadBalancerCertificateDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
err := func() error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerCertificateDeleteTask", lbcert, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}()
|
||||
if err != nil {
|
||||
lbcert.SetStatus(ctx, userCred, api.LB_STATUS_DELETE_FAILED, err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerCertificateManager) FetchCustomizeColumns(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject,
|
||||
objs []interface{},
|
||||
fields stringutils2.SSortedStrings,
|
||||
isList bool,
|
||||
) []api.CachedLoadbalancerCertificateDetails {
|
||||
rows := make([]api.CachedLoadbalancerCertificateDetails, len(objs))
|
||||
|
||||
stdRows := man.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
manRows := man.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
regionRows := man.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
certRows := man.SLoadbalancerCertificateResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
for i := range rows {
|
||||
rows[i] = api.CachedLoadbalancerCertificateDetails{
|
||||
StatusStandaloneResourceDetails: stdRows[i],
|
||||
ManagedResourceInfo: manRows[i],
|
||||
CloudregionResourceInfo: regionRows[i],
|
||||
LoadbalancerCertificateResourceInfo: certRows[i],
|
||||
}
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
func (lbcert *SCachedLoadbalancerCertificate) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
||||
provider, err := lbcert.GetDriver(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDriver")
|
||||
}
|
||||
region, err := lbcert.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegion")
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (lbcert *SCachedLoadbalancerCertificate) GetRegion() (*SCloudregion, error) {
|
||||
return lbcert.SCloudregionResourceBase.GetRegion()
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerCertificateManager) GetOrCreateCachedCertificate(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, lblis *SLoadbalancerListener, cert *SLoadbalancerCertificate) (*SCachedLoadbalancerCertificate, error) {
|
||||
ownerProjId := provider.ProjectId
|
||||
|
||||
lockman.LockClass(ctx, man, ownerProjId)
|
||||
defer lockman.ReleaseClass(ctx, man, ownerProjId)
|
||||
|
||||
cache, err := func() (*SCachedLoadbalancerCertificate, error) {
|
||||
region, err := lblis.GetRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lbcert, err := man.getLoadbalancerCertificateByRegion(provider, region.Id, cert.Id)
|
||||
if err == nil {
|
||||
return lbcert, nil
|
||||
}
|
||||
|
||||
if errors.Cause(err) != cloudprovider.ErrNotFound {
|
||||
return nil, errors.Wrap(err, "getLoadbalancerCertificateByRegion")
|
||||
}
|
||||
|
||||
lbcert = &SCachedLoadbalancerCertificate{}
|
||||
lbcert.SetModelManager(CachedLoadbalancerCertificateManager, lbcert)
|
||||
lbcert.ManagerId = provider.Id
|
||||
lbcert.CloudregionId = region.Id
|
||||
lbcert.Name = cert.Name
|
||||
lbcert.Description = cert.Description
|
||||
lbcert.CertificateId = cert.Id
|
||||
|
||||
err = man.TableSpec().Insert(ctx, lbcert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Insert")
|
||||
}
|
||||
|
||||
return lbcert, nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(cache.ExternalId) > 0 {
|
||||
return cache, nil
|
||||
}
|
||||
err = cache.CreateICertificate(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateICertificate")
|
||||
}
|
||||
return cache, nil
|
||||
}
|
||||
|
||||
func (lbcert *SCachedLoadbalancerCertificate) CreateICertificate(ctx context.Context) error {
|
||||
iRegion, err := lbcert.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "lbcert.GetIRegion")
|
||||
}
|
||||
|
||||
localCert, err := lbcert.GetCertificate()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetCertificate")
|
||||
}
|
||||
|
||||
certificate := &cloudprovider.SLoadbalancerCertificate{
|
||||
Name: fmt.Sprintf("%s-%s", lbcert.Name, rand.String(4)),
|
||||
PrivateKey: localCert.PrivateKey,
|
||||
Certificate: localCert.Certificate,
|
||||
}
|
||||
iLoadbalancerCert, err := iRegion.CreateILoadBalancerCertificate(certificate)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "iRegion.CreateILoadBalancerCertificate")
|
||||
}
|
||||
_, err = db.Update(lbcert, func() error {
|
||||
lbcert.ExternalId = iLoadbalancerCert.GetGlobalId()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "db.SetExternalId")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbcert *SCachedLoadbalancerCertificate) StartLoadbalancerCertificateCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerCertificateCreateTask", lbcert, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) newFromCloudLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudLoadbalancerCertificate, region *SCloudregion) error {
|
||||
lbcert := &SCachedLoadbalancerCertificate{}
|
||||
lbcert.SetModelManager(CachedLoadbalancerCertificateManager, lbcert)
|
||||
|
||||
lbcert.ExternalId = ext.GetGlobalId()
|
||||
lbcert.ManagerId = self.Id
|
||||
if region.GetDriver().IsCertificateBelongToRegion() {
|
||||
lbcert.CloudregionId = region.Id
|
||||
}
|
||||
|
||||
tenantIds := []string{self.GetOwnerId().GetProjectDomainId()}
|
||||
c := &SLoadbalancerCertificate{}
|
||||
c.SetModelManager(LoadbalancerCertificateManager, c)
|
||||
for _, tenantId := range tenantIds {
|
||||
q1 := LoadbalancerCertificateManager.Query()
|
||||
q1 = q1.Equals("fingerprint", ext.GetFingerprint())
|
||||
q1 = q1.Equals("tenant_id", tenantId)
|
||||
cnt, err := q1.CountWithError()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "CountWithError")
|
||||
}
|
||||
if cnt > 0 {
|
||||
err = q1.First(c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "q1.First")
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(c.Id) == 0 {
|
||||
// other information's
|
||||
c.Name = ext.GetName()
|
||||
c.Certificate = ext.GetPublickKey()
|
||||
c.PrivateKey = ext.GetPrivateKey()
|
||||
c.Fingerprint = ext.GetFingerprint()
|
||||
c.ProjectId = tenantIds[0]
|
||||
c.CommonName = ext.GetCommonName()
|
||||
c.SubjectAlternativeNames = ext.GetSubjectAlternativeNames()
|
||||
c.NotAfter = ext.GetExpireTime()
|
||||
c.PublicScope = string(rbacscope.ScopeDomain)
|
||||
c.IsPublic = true
|
||||
|
||||
err := LoadbalancerCertificateManager.TableSpec().Insert(ctx, c)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Insert lbcert")
|
||||
}
|
||||
|
||||
SyncCloudProject(ctx, userCred, c, self.GetOwnerId(), ext, self)
|
||||
}
|
||||
lbcert.CertificateId = c.Id
|
||||
lbcert.Name = ext.GetName()
|
||||
|
||||
err := CachedLoadbalancerCertificateManager.TableSpec().Insert(ctx, lbcert)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Insert cache lbert")
|
||||
}
|
||||
|
||||
syncMetadata(ctx, userCred, lbcert, ext, false)
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_CREATE, lbcert.GetShortDesc(ctx), userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: lbcert,
|
||||
Action: notifyclient.ActionSyncCreate,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbcert *SCachedLoadbalancerCertificate) SyncWithCloudLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudLoadbalancerCertificate) error {
|
||||
diff, err := db.Update(lbcert, func() error {
|
||||
lbcert.Name = ext.GetName()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "db.Update")
|
||||
}
|
||||
|
||||
syncMetadata(ctx, userCred, lbcert, ext, false)
|
||||
db.OpsLog.LogSyncUpdate(lbcert, diff, userCred)
|
||||
if len(diff) > 0 {
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: lbcert,
|
||||
Action: notifyclient.ActionSyncUpdate,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbcert *SCachedLoadbalancerCertificate) syncRemoveCloudLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
lockman.LockObject(ctx, lbcert)
|
||||
defer lockman.ReleaseObject(ctx, lbcert)
|
||||
|
||||
err := lbcert.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "lbcert.RealDelete")
|
||||
}
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: lbcert,
|
||||
Action: notifyclient.ActionSyncDelete,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerCertificateManager) getLoadbalancerCertificateByRegion(provider *SCloudprovider, regionId string, localCertificateId string) (*SCachedLoadbalancerCertificate, error) {
|
||||
certificates := []SCachedLoadbalancerCertificate{}
|
||||
q := man.Query().Equals("manager_id", provider.Id).Equals("certificate_id", localCertificateId)
|
||||
regionDriver, err := provider.GetRegionDriver()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetRegionDriver")
|
||||
}
|
||||
|
||||
if regionDriver.IsCertificateBelongToRegion() {
|
||||
q = q.Equals("cloudregion_id", regionId)
|
||||
}
|
||||
|
||||
if err := db.FetchModelObjects(man, q, &certificates); err != nil {
|
||||
log.Errorf("failed to get lb certificate for region: %v provider: %v error: %v", regionId, provider, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(certificates) >= 1 {
|
||||
return &certificates[0], nil
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) getLoadbalancerCertificatesByRegion(region *SCloudregion) ([]SCachedLoadbalancerCertificate, error) {
|
||||
q := CachedLoadbalancerCertificateManager.Query().Equals("manager_id", self.Id)
|
||||
if region.GetDriver().IsCertificateBelongToRegion() {
|
||||
q = q.Equals("cloudregion_id", region.Id)
|
||||
}
|
||||
|
||||
ret := []SCachedLoadbalancerCertificate{}
|
||||
err := db.FetchModelObjects(CachedLoadbalancerCertificateManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.FetchModelObjects")
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) SyncLoadbalancerCertificates(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
region *SCloudregion,
|
||||
certificates []cloudprovider.ICloudLoadbalancerCertificate,
|
||||
xor bool,
|
||||
) compare.SyncResult {
|
||||
lockman.LockRawObject(ctx, CachedLoadbalancerCertificateManager.Keyword(), fmt.Sprintf("%s-%s", self.Id, region.Id))
|
||||
defer lockman.ReleaseRawObject(ctx, CachedLoadbalancerCertificateManager.Keyword(), fmt.Sprintf("%s-%s", self.Id, region.Id))
|
||||
|
||||
syncResult := compare.SyncResult{}
|
||||
|
||||
dbCertificates, err := self.getLoadbalancerCertificatesByRegion(region)
|
||||
if err != nil {
|
||||
syncResult.Error(errors.Wrapf(err, "getLoadbalancerCertificatesByRegion"))
|
||||
return syncResult
|
||||
}
|
||||
|
||||
removed := []SCachedLoadbalancerCertificate{}
|
||||
commondb := []SCachedLoadbalancerCertificate{}
|
||||
commonext := []cloudprovider.ICloudLoadbalancerCertificate{}
|
||||
added := []cloudprovider.ICloudLoadbalancerCertificate{}
|
||||
|
||||
err = compare.CompareSets(dbCertificates, certificates, &removed, &commondb, &commonext, &added)
|
||||
if err != nil {
|
||||
syncResult.Error(errors.Wrapf(err, "compare.CompareSets"))
|
||||
return syncResult
|
||||
}
|
||||
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].syncRemoveCloudLoadbalancerCertificate(ctx, userCred)
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
continue
|
||||
}
|
||||
syncResult.Delete()
|
||||
}
|
||||
if !xor {
|
||||
for i := 0; i < len(commondb); i++ {
|
||||
err = commondb[i].SyncWithCloudLoadbalancerCertificate(ctx, userCred, commonext[i])
|
||||
if err != nil {
|
||||
syncResult.UpdateError(err)
|
||||
continue
|
||||
}
|
||||
syncResult.Update()
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(added); i++ {
|
||||
err := self.newFromCloudLoadbalancerCertificate(ctx, userCred, added[i], region)
|
||||
if err != nil {
|
||||
syncResult.AddError(err)
|
||||
continue
|
||||
}
|
||||
syncResult.Add()
|
||||
}
|
||||
return syncResult
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerCertificateManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.CachedLoadbalancerCertificateListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = man.SStatusStandaloneResourceBaseManager.ListItemFilter(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = man.SManagedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.ListItemFilter(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = man.SLoadbalancerCertificateResourceBaseManager.ListItemFilter(ctx, q, userCred, query.LoadbalancerCertificateFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SLoadbalancerCertificateResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerCertificateManager) OrderByExtraFields(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
query api.CachedLoadbalancerCertificateListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = man.SStatusStandaloneResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.StatusStandaloneResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = man.SManagedResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = man.SLoadbalancerCertificateResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.LoadbalancerCertificateFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SLoadbalancerCertificateResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerCertificateManager) QueryDistinctExtraField(q *sqlchemy.SQuery, field string) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = man.SStatusStandaloneResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
q, err = man.SManagedResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
q, err = man.SLoadbalancerCertificateResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
func (manager *SCachedLoadbalancerCertificateManager) ListItemExportKeys(ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
keys stringutils2.SSortedStrings,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SStatusStandaloneResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SStatusStandaloneResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
if keys.ContainsAny(manager.SManagedResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SManagedResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
if keys.ContainsAny(manager.SCloudregionResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SCloudregionResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
if keys.ContainsAny(manager.SLoadbalancerCertificateResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SLoadbalancerCertificateResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SLoadbalancerCertificateResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (man *SCachedLoadbalancerCertificateManager) InitializeData() error {
|
||||
return nil
|
||||
}
|
||||
@@ -21,20 +21,24 @@ import (
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
@@ -44,6 +48,9 @@ type SLoadbalancerCertificateManager struct {
|
||||
SLoadbalancerLogSkipper
|
||||
db.SSharableVirtualResourceBaseManager
|
||||
db.SExternalizedResourceBaseManager
|
||||
|
||||
SManagedResourceBaseManager
|
||||
SCloudregionResourceBaseManager
|
||||
}
|
||||
|
||||
var LoadbalancerCertificateManager *SLoadbalancerCertificateManager
|
||||
@@ -60,25 +67,14 @@ func init() {
|
||||
LoadbalancerCertificateManager.SetVirtualObject(LoadbalancerCertificateManager)
|
||||
}
|
||||
|
||||
// TODO
|
||||
//
|
||||
// - notify users of cert expiration
|
||||
// - ca info: self-signed, public ca
|
||||
type SLoadbalancerCertificate struct {
|
||||
db.SSharableVirtualResourceBase
|
||||
db.SExternalizedResourceBase
|
||||
|
||||
db.SCertificateResourceBase
|
||||
}
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) GetCachedCerts() ([]SCachedLoadbalancerCertificate, error) {
|
||||
ret := []SCachedLoadbalancerCertificate{}
|
||||
q := CachedLoadbalancerCertificateManager.Query().Equals("certificate_id", lbcert.Id)
|
||||
err := db.FetchModelObjects(CachedLoadbalancerCertificateManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
db.SCertificateResourceBase
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.LoadbalancerCertificateUpdateInput) (*api.LoadbalancerCertificateUpdateInput, error) {
|
||||
@@ -90,8 +86,52 @@ func (lbcert *SLoadbalancerCertificate) ValidateUpdateData(ctx context.Context,
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) IsComplete() bool {
|
||||
return lbcert.PrivateKey != "" && lbcert.Certificate != ""
|
||||
func (nm *SLoadbalancerCertificateManager) query(manager db.IModelManager, field string, certIds []string, filter func(*sqlchemy.SQuery) *sqlchemy.SQuery) *sqlchemy.SSubQuery {
|
||||
q := manager.Query()
|
||||
|
||||
if filter != nil {
|
||||
q = filter(q)
|
||||
}
|
||||
|
||||
sq := q.SubQuery()
|
||||
|
||||
return sq.Query(
|
||||
sq.Field("certificate_id"),
|
||||
sqlchemy.COUNT(field),
|
||||
).In("certificate_id", certIds).GroupBy(sq.Field("certificate_id")).SubQuery()
|
||||
}
|
||||
|
||||
type SCertUsageCount struct {
|
||||
Id string
|
||||
api.LoadbalancerCertificateUsage
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerCertificateManager) TotalResourceCount(certIds []string) (map[string]api.LoadbalancerCertificateUsage, error) {
|
||||
// listener
|
||||
listenerSQ := manager.query(LoadbalancerListenerManager, "listener_cnt", certIds, nil)
|
||||
|
||||
certs := manager.Query().SubQuery()
|
||||
certQ := certs.Query(
|
||||
sqlchemy.SUM("lb_listener_count", listenerSQ.Field("listener_cnt")),
|
||||
)
|
||||
|
||||
certQ.AppendField(certQ.Field("id"))
|
||||
|
||||
certQ = certQ.LeftJoin(listenerSQ, sqlchemy.Equals(certQ.Field("id"), listenerSQ.Field("certificate_id")))
|
||||
certQ = certQ.Filter(sqlchemy.In(certQ.Field("id"), certIds)).GroupBy(certQ.Field("id"))
|
||||
|
||||
certCount := []SCertUsageCount{}
|
||||
err := certQ.All(&certCount)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "certQ.All")
|
||||
}
|
||||
|
||||
result := map[string]api.LoadbalancerCertificateUsage{}
|
||||
for i := range certCount {
|
||||
result[certCount[i].Id] = certCount[i].LoadbalancerCertificateUsage
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerCertificateManager) FetchCustomizeColumns(
|
||||
@@ -105,51 +145,59 @@ func (manager *SLoadbalancerCertificateManager) FetchCustomizeColumns(
|
||||
rows := make([]api.LoadbalancerCertificateDetails, len(objs))
|
||||
|
||||
virtRows := manager.SSharableVirtualResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
managerRows := manager.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
regionRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
certIds := make([]string, len(objs))
|
||||
for i := range rows {
|
||||
rows[i] = api.LoadbalancerCertificateDetails{
|
||||
SharableVirtualResourceDetails: virtRows[i],
|
||||
IsComplete: objs[i].(*SLoadbalancerCertificate).IsComplete(),
|
||||
ManagedResourceInfo: managerRows[i],
|
||||
CloudregionResourceInfo: regionRows[i],
|
||||
}
|
||||
}
|
||||
|
||||
for i := range objs {
|
||||
q := LoadbalancerListenerManager.Query().Equals("certificate_id", objs[i].(*SLoadbalancerCertificate).GetId())
|
||||
ownerId, queryScope, err, _ := db.FetchCheckQueryOwnerScope(ctx, userCred, query, LoadbalancerListenerManager, policy.PolicyActionList, true)
|
||||
if err != nil {
|
||||
log.Errorf("FetchCheckQueryOwnerScope error: %v", err)
|
||||
return rows
|
||||
}
|
||||
usage, err := manager.TotalResourceCount(certIds)
|
||||
if err != nil {
|
||||
log.Errorf("TotalResourceCount error: %v", err)
|
||||
return rows
|
||||
}
|
||||
|
||||
q = LoadbalancerListenerManager.FilterByOwner(ctx, q, LoadbalancerListenerManager, userCred, ownerId, queryScope)
|
||||
rows[i].LbListenerCount, _ = q.CountWithError()
|
||||
for i := range rows {
|
||||
rows[i].LoadbalancerCertificateUsage, _ = usage[certIds[i]]
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Context, info *api.LoadbalancerCertificateDetails) error {
|
||||
if info != nil && info.LbListenerCount > 0 {
|
||||
return httperrors.NewNotEmptyError("cert %s with %d listeners", lbcert.Name, info.LbListenerCount)
|
||||
if info != nil && info.ListenerCount > 0 {
|
||||
return httperrors.NewNotEmptyError("cert %s with %d listeners", lbcert.Name, info.ListenerCount)
|
||||
}
|
||||
return lbcert.SSharableVirtualResourceBase.ValidateDeleteCondition(ctx, jsonutils.Marshal(info))
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
caches, err := lbcert.GetCachedCerts()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetCachedCerts")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := range caches {
|
||||
err := caches[i].Delete(ctx, userCred)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Delete cache %s", caches[i].Id)
|
||||
}
|
||||
}
|
||||
func (lbcert *SLoadbalancerCertificate) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return lbcert.SSharableVirtualResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
return self.StartDeleteTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) StartDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerCertificateDeleteTask", lbcert, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
lbcert.SetStatus(ctx, userCred, apis.STATUS_DELETING, "")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerCertificateManager) ListItemFilter(
|
||||
ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
@@ -165,36 +213,29 @@ func (man *SLoadbalancerCertificateManager) ListItemFilter(
|
||||
return nil, errors.Wrap(err, "SExternalizedResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
q, err = man.SManagedResourceBaseManager.ListItemFilter(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.ListItemFilter(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
|
||||
if query.Usable != nil && *query.Usable {
|
||||
region := query.CloudregionId
|
||||
manager := query.CloudproviderId
|
||||
|
||||
// 证书可用包含两类:1.本地证书内容不为空 2.公有云中已经存在,但是证书内容不完整的证书
|
||||
if len(region) > 0 || len(manager) > 0 {
|
||||
q2 := CachedLoadbalancerCertificateManager.Query("certificate_id")
|
||||
if len(region) > 0 {
|
||||
q2 = q2.Equals("cloudregion_id", region)
|
||||
}
|
||||
|
||||
if len(manager) > 0 {
|
||||
q2 = q2.Equals("manager_id", manager)
|
||||
}
|
||||
|
||||
count, err := q2.CountWithError()
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
conditionA := sqlchemy.AND(sqlchemy.IsNotEmpty(q.Field("certificate")), sqlchemy.IsNotEmpty(q.Field("private_key")))
|
||||
conditionB := sqlchemy.In(q.Field("id"), q2.SubQuery())
|
||||
q = q.Filter(sqlchemy.OR(conditionA, conditionB))
|
||||
} else {
|
||||
q = q.IsNotEmpty("certificate").IsNotEmpty("private_key")
|
||||
}
|
||||
} else {
|
||||
q = q.IsNotEmpty("certificate").IsNotEmpty("private_key")
|
||||
}
|
||||
q = q.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.AND(
|
||||
sqlchemy.Equals(q.Field("cloudregion_id"), api.DEFAULT_REGION_ID),
|
||||
sqlchemy.IsNotEmpty(q.Field("certificate")),
|
||||
sqlchemy.IsNotEmpty(q.Field("private_key")),
|
||||
),
|
||||
sqlchemy.AND(
|
||||
sqlchemy.NotEquals(q.Field("cloudregion_id"), api.DEFAULT_REGION_ID),
|
||||
sqlchemy.IsNotEmpty(q.Field("external_id")),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
if len(query.CommonName) > 0 {
|
||||
@@ -220,6 +261,15 @@ func (man *SLoadbalancerCertificateManager) OrderByExtraFields(
|
||||
return nil, errors.Wrap(err, "SSharableVirtualResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
|
||||
q, err = man.SManagedResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.ManagedResourceListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query.RegionalFilterListInput)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.OrderByExtraFields")
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -231,11 +281,81 @@ func (man *SLoadbalancerCertificateManager) QueryDistinctExtraField(q *sqlchemy.
|
||||
return q, nil
|
||||
}
|
||||
|
||||
q, err = man.SManagedResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
q, err = man.SCloudregionResourceBaseManager.QueryDistinctExtraField(q, field)
|
||||
if err == nil {
|
||||
return q, nil
|
||||
}
|
||||
|
||||
return q, httperrors.ErrNotFound
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerCertificateManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input *api.LoadbalancerCertificateCreateInput) (*api.LoadbalancerCertificateCreateInput, error) {
|
||||
func (manager *SLoadbalancerCertificateManager) ListItemExportKeys(ctx context.Context,
|
||||
q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
keys stringutils2.SSortedStrings,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
|
||||
q, err = manager.SSharableVirtualResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SSharableVirtualResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
|
||||
if keys.ContainsAny(manager.SManagedResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SManagedResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SManagedResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
|
||||
if keys.ContainsAny(manager.SCloudregionResourceBaseManager.GetExportKeys()...) {
|
||||
q, err = manager.SCloudregionResourceBaseManager.ListItemExportKeys(ctx, q, userCred, keys)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SCloudregionResourceBaseManager.ListItemExportKeys")
|
||||
}
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
||||
region, err := self.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegion")
|
||||
}
|
||||
provider, err := self.GetDriver(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDriver")
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) GetILoadbalancerCertificate(ctx context.Context) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
if len(self.ExternalId) == 0 {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "empty external id")
|
||||
}
|
||||
iRegion, err := self.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iRegion.GetILoadBalancerCertificateById(self.ExternalId)
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, lbcert, "LoadbalancerCertificateSyncstatusTask", "")
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerCertificateManager) ValidateCreateData(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
ownerId mcclient.IIdentityProvider,
|
||||
query jsonutils.JSONObject,
|
||||
input *api.LoadbalancerCertificateCreateInput,
|
||||
) (*api.LoadbalancerCertificateCreateInput, error) {
|
||||
if len(input.Certificate) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("certificate")
|
||||
}
|
||||
@@ -268,10 +388,164 @@ func (man *SLoadbalancerCertificateManager) ValidateCreateData(ctx context.Conte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
input.Status = api.LB_STATUS_ENABLED
|
||||
input.Status = apis.STATUS_CREATING
|
||||
|
||||
if len(input.CloudregionId) == 0 {
|
||||
input.CloudregionId = api.DEFAULT_REGION_ID
|
||||
}
|
||||
regionObj, err := validators.ValidateModel(ctx, userCred, CloudregionManager, &input.CloudregionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region := regionObj.(*SCloudregion)
|
||||
if len(input.CloudproviderId) > 0 {
|
||||
providerObj, err := validators.ValidateModel(ctx, userCred, CloudproviderManager, &input.CloudproviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
input.ManagerId = input.CloudproviderId
|
||||
provider := providerObj.(*SCloudprovider)
|
||||
if provider.Provider != region.Provider {
|
||||
return nil, httperrors.NewConflictError("conflict region %s and cloudprovider %s", region.Name, provider.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
self.SSharableVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
self.StartCreateTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) StartCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerCertificateCreateTask", lbcert, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "NewTask")
|
||||
}
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SCloudregion) GetLoadbalancerCertificates(managerId string) ([]SLoadbalancerCertificate, error) {
|
||||
q := LoadbalancerCertificateManager.Query().Equals("cloudregion_id", self.Id)
|
||||
if len(managerId) > 0 {
|
||||
q = q.Equals("manager_id", managerId)
|
||||
}
|
||||
ret := []SLoadbalancerCertificate{}
|
||||
err := db.FetchModelObjects(LoadbalancerCertificateManager, q, &ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SCloudregion) SyncLoadbalancerCertificates(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, exts []cloudprovider.ICloudLoadbalancerCertificate, xor bool) compare.SyncResult {
|
||||
lockman.LockRawObject(ctx, LoadbalancerCertificateManager.Keyword(), fmt.Sprintf("%s-%s", self.Id, provider.Id))
|
||||
defer lockman.ReleaseRawObject(ctx, LoadbalancerCertificateManager.Keyword(), fmt.Sprintf("%s-%s", self.Id, provider.Id))
|
||||
|
||||
result := compare.SyncResult{}
|
||||
|
||||
dbCerts, err := self.GetLoadbalancerCertificates(provider.Id)
|
||||
if err != nil {
|
||||
result.Error(err)
|
||||
return result
|
||||
}
|
||||
|
||||
removed := make([]SLoadbalancerCertificate, 0)
|
||||
commondb := make([]SLoadbalancerCertificate, 0)
|
||||
commonext := make([]cloudprovider.ICloudLoadbalancerCertificate, 0)
|
||||
added := make([]cloudprovider.ICloudLoadbalancerCertificate, 0)
|
||||
|
||||
err = compare.CompareSets(dbCerts, exts, &removed, &commondb, &commonext, &added)
|
||||
if err != nil {
|
||||
result.Error(err)
|
||||
return result
|
||||
}
|
||||
|
||||
for i := 0; i < len(removed); i += 1 {
|
||||
err = removed[i].RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
result.DeleteError(err)
|
||||
continue
|
||||
}
|
||||
result.Delete()
|
||||
}
|
||||
|
||||
for i := 0; i < len(commondb); i += 1 {
|
||||
if !xor {
|
||||
err = commondb[i].SyncWithCloudCert(ctx, userCred, commonext[i], provider)
|
||||
if err != nil {
|
||||
result.UpdateError(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
result.Update()
|
||||
}
|
||||
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
err := self.newFromCloudCert(ctx, userCred, provider, added[i])
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
continue
|
||||
}
|
||||
result.Add()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) SyncWithCloudCert(ctx context.Context, userCred mcclient.TokenCredential, ext cloudprovider.ICloudLoadbalancerCertificate, provider *SCloudprovider) error {
|
||||
_, err := db.Update(lbcert, func() error {
|
||||
lbcert.Name = ext.GetName()
|
||||
lbcert.CommonName = ext.GetCommonName()
|
||||
lbcert.SubjectAlternativeNames = ext.GetSubjectAlternativeNames()
|
||||
lbcert.Fingerprint = ext.GetFingerprint()
|
||||
lbcert.NotAfter = ext.GetExpireTime()
|
||||
lbcert.Status = ext.GetStatus()
|
||||
if key := ext.GetPublickKey(); len(key) > 0 {
|
||||
lbcert.Certificate = key
|
||||
}
|
||||
if key := ext.GetPrivateKey(); len(key) > 0 {
|
||||
lbcert.PrivateKey = key
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, lbcert, ext, false)
|
||||
SyncCloudProject(ctx, userCred, lbcert, provider.GetOwnerId(), ext, provider)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudregion) newFromCloudCert(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, ext cloudprovider.ICloudLoadbalancerCertificate) error {
|
||||
ret := &SLoadbalancerCertificate{}
|
||||
ret.SetModelManager(LoadbalancerCertificateManager, ret)
|
||||
ret.ExternalId = ext.GetGlobalId()
|
||||
ret.CloudregionId = self.Id
|
||||
ret.ManagerId = provider.Id
|
||||
ret.Name = ext.GetName()
|
||||
ret.Status = ext.GetStatus()
|
||||
ret.CommonName = ext.GetCommonName()
|
||||
ret.SubjectAlternativeNames = ext.GetSubjectAlternativeNames()
|
||||
ret.Fingerprint = ext.GetFingerprint()
|
||||
ret.NotAfter = ext.GetExpireTime()
|
||||
ret.Certificate = ext.GetPublickKey()
|
||||
ret.PrivateKey = ext.GetPrivateKey()
|
||||
|
||||
err := LoadbalancerCertificateManager.TableSpec().Insert(ctx, ret)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Insert")
|
||||
}
|
||||
|
||||
syncVirtualResourceMetadata(ctx, userCred, ret, ext, false)
|
||||
SyncCloudProject(ctx, userCred, ret, provider.GetOwnerId(), ext, provider)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerCertificateManager) InitializeData() error {
|
||||
_, err := sqlchemy.GetDB().Exec(
|
||||
fmt.Sprintf(
|
||||
|
||||
@@ -832,12 +832,12 @@ func (lblis *SLoadbalancerListener) constructFieldsFromCloudListener(userCred mc
|
||||
}
|
||||
|
||||
lblis.AclType = extListener.GetAclType()
|
||||
if aclID := extListener.GetAclId(); len(aclID) > 0 {
|
||||
if _acl, err := db.FetchByExternalIdAndManagerId(CachedLoadbalancerAclManager, aclID, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if aclId := extListener.GetAclId(); len(aclId) > 0 {
|
||||
if _acl, err := db.FetchByExternalIdAndManagerId(LoadbalancerAclManager, aclId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("manager_id", lb.ManagerId)
|
||||
}); err == nil {
|
||||
acl := _acl.(*SCachedLoadbalancerAcl)
|
||||
lblis.AclId = acl.AclId
|
||||
acl := _acl.(*SLoadbalancerAcl)
|
||||
lblis.AclId = acl.Id
|
||||
}
|
||||
} else {
|
||||
lblis.AclId = ""
|
||||
@@ -884,11 +884,11 @@ func (lblis *SLoadbalancerListener) constructFieldsFromCloudListener(userCred mc
|
||||
lblis.TLSCipherPolicy = extListener.GetTLSCipherPolicy()
|
||||
lblis.EnableHttp2 = extListener.HTTP2Enabled()
|
||||
if certificateId := extListener.GetCertificateId(); len(certificateId) > 0 {
|
||||
if _cert, err := db.FetchByExternalIdAndManagerId(CachedLoadbalancerCertificateManager, certificateId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if _cert, err := db.FetchByExternalIdAndManagerId(LoadbalancerCertificateManager, certificateId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("manager_id", lb.ManagerId)
|
||||
}); err == nil {
|
||||
cert := _cert.(*SCachedLoadbalancerCertificate)
|
||||
lblis.CertificateId = cert.CertificateId
|
||||
cert := _cert.(*SLoadbalancerCertificate)
|
||||
lblis.CertificateId = cert.Id
|
||||
}
|
||||
}
|
||||
fallthrough
|
||||
|
||||
@@ -419,8 +419,6 @@ func (self *SCloudregion) purgeKubeClusters(ctx context.Context, managerId strin
|
||||
}
|
||||
|
||||
func (self *SCloudregion) purgeLoadbalancers(ctx context.Context, managerId string) error {
|
||||
cacheAcls := CachedLoadbalancerAclManager.Query("id").Equals("manager_id", managerId).Equals("cloudregion_id", self.Id)
|
||||
cacheCerts := CachedLoadbalancerCertificateManager.Query("id").Equals("manager_id", managerId).Equals("cloudregion_id", self.Id)
|
||||
lbs := LoadbalancerManager.Query("id").Equals("manager_id", managerId).Equals("cloudregion_id", self.Id)
|
||||
lbnetworks := LoadbalancernetworkManager.Query("row_id").In("loadbalancer_id", lbs.SubQuery())
|
||||
lblis := LoadbalancerListenerManager.Query("id").In("loadbalancer_id", lbs.SubQuery())
|
||||
@@ -434,8 +432,6 @@ func (self *SCloudregion) purgeLoadbalancers(ctx context.Context, managerId stri
|
||||
{manager: LoadbalancerBackendGroupManager, key: "id", q: lbbgs},
|
||||
{manager: LoadbalancerListenerManager, key: "id", q: lblis},
|
||||
{manager: LoadbalancernetworkManager, key: "row_id", q: lbnetworks},
|
||||
{manager: CachedLoadbalancerCertificateManager, key: "id", q: cacheCerts},
|
||||
{manager: CachedLoadbalancerAclManager, key: "id", q: cacheAcls},
|
||||
{manager: LoadbalancerManager, key: "id", q: lbs},
|
||||
}
|
||||
for i := range pairs {
|
||||
|
||||
@@ -130,13 +130,15 @@ type ILoadbalancerDriver interface {
|
||||
RequestSyncstatusLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *SLoadbalancer, task taskman.ITask) error
|
||||
RequestRemoteUpdateLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *SLoadbalancer, replaceTags bool, task taskman.ITask) error
|
||||
|
||||
RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *SCachedLoadbalancerAcl, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *SCachedLoadbalancerAcl, task taskman.ITask) error
|
||||
RequestSyncLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *SCachedLoadbalancerAcl, task taskman.ITask) error
|
||||
RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *SLoadbalancerAcl, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *SLoadbalancerAcl, task taskman.ITask) error
|
||||
RequestUpdateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *SLoadbalancerAcl, task taskman.ITask) error
|
||||
RequestLoadbalancerAclSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbacl *SLoadbalancerAcl, task taskman.ITask) error
|
||||
|
||||
IsCertificateBelongToRegion() bool
|
||||
RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *SCachedLoadbalancerCertificate, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *SCachedLoadbalancerCertificate, task taskman.ITask) error
|
||||
RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *SLoadbalancerCertificate, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *SLoadbalancerCertificate, task taskman.ITask) error
|
||||
RequestLoadbalancerCertificateSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbcert *SLoadbalancerCertificate, task taskman.ITask) error
|
||||
|
||||
ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, lb *SLoadbalancer, input *api.LoadbalancerBackendGroupCreateInput) (*api.LoadbalancerBackendGroupCreateInput, error)
|
||||
RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *SLoadbalancerBackendGroup, task taskman.ITask) error
|
||||
|
||||
@@ -231,12 +231,7 @@ func (self *SAwsRegionDriver) RequestCreateLoadbalancerListener(ctx context.Cont
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetCertificate")
|
||||
}
|
||||
|
||||
lbcert, err := models.CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate(ctx, userCred, provider, lblis, cert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate")
|
||||
}
|
||||
opts.CertificateId = lbcert.ExternalId
|
||||
opts.CertificateId = cert.ExternalId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,15 +65,19 @@ func (self *SBaseRegionDriver) RequestDeleteLoadbalancer(ctx context.Context, us
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancer")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestCreateLoadbalancerAcl")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestSyncLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestSyncLoadbalancerAcl")
|
||||
func (self *SBaseRegionDriver) RequestUpdateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return errors.Wrapf(cloudprovider.ErrNotImplemented, "RequestUpdateLoadbalancerAcl")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
func (self *SBaseRegionDriver) RequestLoadbalancerAclSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return errors.Wrapf(cloudprovider.ErrNotImplemented, "RequestLoadbalancerAclSyncstatus")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancerAcl")
|
||||
}
|
||||
|
||||
@@ -81,14 +85,18 @@ func (self *SBaseRegionDriver) IsCertificateBelongToRegion() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SCachedLoadbalancerCertificate, task taskman.ITask) error {
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestCreateLoadbalancerCertificate")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SCachedLoadbalancerCertificate, task taskman.ITask) error {
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancerCertificate")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestLoadbalancerCertificateSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestLoadbalancerCertificateSyncstatus")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, task taskman.ITask) error {
|
||||
return errors.Wrapf(cloudprovider.ErrNotImplemented, "RequestCreateLoadbalancerBackendGroup")
|
||||
}
|
||||
|
||||
@@ -110,12 +110,7 @@ func (self *SHuaWeiRegionDriver) RequestCreateLoadbalancerListener(ctx context.C
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetCertificate")
|
||||
}
|
||||
|
||||
lbcert, err := models.CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate(ctx, userCred, provider, lblis, cert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate")
|
||||
}
|
||||
opts.CertificateId = lbcert.ExternalId
|
||||
opts.CertificateId = cert.ExternalId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -413,25 +413,34 @@ func (self *SKVMRegionDriver) RequestDeleteLoadbalancer(ctx context.Context, use
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestSyncLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
func (self *SKVMRegionDriver) RequestUpdateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
func (self *SKVMRegionDriver) RequestLoadbalancerAclSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
lbacl.SetStatus(ctx, userCred, apis.STATUS_AVAILABLE, "")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SCachedLoadbalancerCertificate, task taskman.ITask) error {
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SCachedLoadbalancerCertificate, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestLoadbalancerCertificateSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
lbcert.SetStatus(ctx, userCred, apis.STATUS_AVAILABLE, "")
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, task taskman.ITask) error {
|
||||
|
||||
@@ -321,74 +321,133 @@ func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancer(ctx co
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, lbacl.CreateIAcl(ctx)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestSyncLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, lbacl.SyncIAcl(ctx)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) deleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) (jsonutils.JSONObject, error) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
}
|
||||
iRegion, err := lbacl.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(lbacl.ExternalId) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
iLoadbalancerAcl, err := iRegion.GetILoadBalancerAclById(lbacl.ExternalId)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
iRegion, err := lbacl.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetIRegion")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, iLoadbalancerAcl.Delete()
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SCachedLoadbalancerAcl, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return self.deleteLoadbalancerAcl(ctx, userCred, lbacl, task)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SCachedLoadbalancerCertificate, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, lbcert.CreateICertificate(ctx)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SCachedLoadbalancerCertificate, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
opts := &cloudprovider.SLoadbalancerAccessControlList{
|
||||
Name: lbacl.Name,
|
||||
Entrys: []cloudprovider.SLoadbalancerAccessControlListEntry{},
|
||||
}
|
||||
if lbacl.AclEntries != nil {
|
||||
for _, entry := range *lbacl.AclEntries {
|
||||
opts.Entrys = append(opts.Entrys, cloudprovider.SLoadbalancerAccessControlListEntry{
|
||||
Comment: entry.Comment,
|
||||
CIDR: entry.Cidr,
|
||||
})
|
||||
}
|
||||
}
|
||||
iAcl, err := iRegion.CreateILoadBalancerAcl(opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateILoadBalancerAcl")
|
||||
}
|
||||
_, err = db.Update(lbacl, func() error {
|
||||
lbacl.ExternalId = iAcl.GetGlobalId()
|
||||
return nil
|
||||
})
|
||||
return nil, err
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestUpdateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iAcl, err := lbacl.GetILoadbalancerAcl(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetILoadbalancerAcl")
|
||||
}
|
||||
opts := &cloudprovider.SLoadbalancerAccessControlList{
|
||||
Name: lbacl.Name,
|
||||
Entrys: []cloudprovider.SLoadbalancerAccessControlListEntry{},
|
||||
}
|
||||
if lbacl.AclEntries != nil {
|
||||
for _, entry := range *lbacl.AclEntries {
|
||||
opts.Entrys = append(opts.Entrys, cloudprovider.SLoadbalancerAccessControlListEntry{
|
||||
Comment: entry.Comment,
|
||||
CIDR: entry.Cidr,
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil, iAcl.Sync(opts)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestLoadbalancerAclSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iAcl, err := lbacl.GetILoadbalancerAcl(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetILoadbalancerAcl")
|
||||
}
|
||||
return nil, lbacl.SyncWithCloudAcl(ctx, userCred, iAcl, lbacl.GetCloudprovider())
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iAcl, err := lbacl.GetILoadbalancerAcl(ctx)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrapf(err, "GetILoadbalancerAcl")
|
||||
}
|
||||
return nil, iAcl.Delete()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iRegion, err := lbcert.GetIRegion(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerCert, err := iRegion.GetILoadBalancerCertificateById(lbcert.ExternalId)
|
||||
|
||||
opts := &cloudprovider.SLoadbalancerCertificate{
|
||||
Name: lbcert.Name,
|
||||
PrivateKey: lbcert.PrivateKey,
|
||||
Certificate: lbcert.Certificate,
|
||||
}
|
||||
|
||||
iCert, err := iRegion.CreateILoadBalancerCertificate(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = db.Update(lbcert, func() error {
|
||||
lbcert.ExternalId = iCert.GetGlobalId()
|
||||
return nil
|
||||
})
|
||||
return nil, err
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iCert, err := lbcert.GetILoadbalancerCertificate(ctx)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, iLoadbalancerCert.Delete()
|
||||
return nil, iCert.Delete()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestLoadbalancerCertificateSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iCert, err := lbcert.GetILoadbalancerCertificate(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, lbcert.SyncWithCloudCert(ctx, userCred, iCert, lbcert.GetCloudprovider())
|
||||
})
|
||||
return nil
|
||||
}
|
||||
@@ -604,12 +663,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerListene
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetCertificate")
|
||||
}
|
||||
|
||||
lbcert, err := models.CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate(ctx, userCred, provider, lblis, cert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate")
|
||||
}
|
||||
params.CertificateId = lbcert.ExternalId
|
||||
params.CertificateId = cert.ExternalId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,12 +673,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerListene
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetAcl")
|
||||
}
|
||||
|
||||
lbacl, err := models.CachedLoadbalancerAclManager.GetOrCreateCachedAcl(ctx, userCred, provider, lblis, acl)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CachedLoadbalancerAclManager.GetOrCreateCachedAcl")
|
||||
}
|
||||
params.AccessControlListId = lbacl.ExternalId
|
||||
params.AccessControlListId = acl.ExternalId
|
||||
params.AccessControlListType = lblis.AclType
|
||||
params.AccessControlListStatus = lblis.AclStatus
|
||||
}
|
||||
@@ -721,12 +770,8 @@ func (self *SManagedVirtualizationRegionDriver) RequestSyncLoadbalancerListener(
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetCertificate")
|
||||
}
|
||||
lbcert, err := models.CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate(ctx, userCred, provider, lblis, cert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetOrCreateCachedCertificate")
|
||||
}
|
||||
err = iLis.ChangeCertificate(ctx, &cloudprovider.ListenerCertificateOptions{
|
||||
CertificateId: lbcert.ExternalId,
|
||||
CertificateId: cert.ExternalId,
|
||||
})
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotSupported && errors.Cause(err) != cloudprovider.ErrNotImplemented {
|
||||
return nil, errors.Wrapf(err, "ChangeCertificate")
|
||||
@@ -742,12 +787,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestSyncLoadbalancerListener(
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetAcl")
|
||||
}
|
||||
|
||||
lbacl, err := models.CachedLoadbalancerAclManager.GetOrCreateCachedAcl(ctx, userCred, provider, lblis, acl)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "regionDriver.RequestSyncLoadbalancerListener.GetAcl")
|
||||
}
|
||||
opts.AclId = lbacl.ExternalId
|
||||
opts.AclId = acl.ExternalId
|
||||
}
|
||||
err := iLis.SetAcl(ctx, opts)
|
||||
if err != nil && errors.Cause(err) != cloudprovider.ErrNotSupported {
|
||||
|
||||
@@ -85,12 +85,7 @@ func (self *SQcloudRegionDriver) RequestCreateLoadbalancerListener(ctx context.C
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetCertificate")
|
||||
}
|
||||
|
||||
lbcert, err := models.CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate(ctx, userCred, provider, lblis, cert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CachedLoadbalancerCertificateManager.GetOrCreateCachedCertificate")
|
||||
}
|
||||
opts.CertificateId = lbcert.ExternalId
|
||||
opts.CertificateId = cert.ExternalId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,8 +151,6 @@ func InitHandlers(app *appsrv.Application) {
|
||||
models.LoadbalancerAclManager,
|
||||
models.LoadbalancerAgentManager,
|
||||
models.LoadbalancerClusterManager,
|
||||
models.CachedLoadbalancerAclManager,
|
||||
models.CachedLoadbalancerCertificateManager,
|
||||
models.RouteTableManager,
|
||||
models.RouteTableAssociationManager,
|
||||
models.RouteTableRouteSetManager,
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
@@ -36,7 +37,7 @@ func init() {
|
||||
taskman.RegisterTask(LoadbalancerAclCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) taskFail(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, err error) {
|
||||
func (self *LoadbalancerAclCreateTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, err error) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), api.LB_CREATE_FAILED, err.Error())
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_CREATE, err, self.UserCred, false)
|
||||
@@ -45,7 +46,7 @@ func (self *LoadbalancerAclCreateTask) taskFail(ctx context.Context, lbacl *mode
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbacl := obj.(*models.SCachedLoadbalancerAcl)
|
||||
lbacl := obj.(*models.SLoadbalancerAcl)
|
||||
region, err := lbacl.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbacl, errors.Wrapf(err, "GetRegion"))
|
||||
@@ -58,13 +59,13 @@ func (self *LoadbalancerAclCreateTask) OnInit(ctx context.Context, obj db.IStand
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) OnLoadbalancerAclCreateComplete(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), api.LB_STATUS_ENABLED, "")
|
||||
func (self *LoadbalancerAclCreateTask) OnLoadbalancerAclCreateComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), apis.STATUS_AVAILABLE, "")
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_ALLOCATE, lbacl.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) OnLoadbalancerAclCreateCompleteFailed(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
func (self *LoadbalancerAclCreateTask) OnLoadbalancerAclCreateCompleteFailed(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbacl, errors.Errorf(reason.String()))
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func init() {
|
||||
taskman.RegisterTask(LoadbalancerAclDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) taskFail(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, err error) {
|
||||
func (self *LoadbalancerAclDeleteTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, err error) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, err.Error())
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_DELOCATE_FAIL, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_DELOCATE, err, self.UserCred, false)
|
||||
@@ -45,7 +45,7 @@ func (self *LoadbalancerAclDeleteTask) taskFail(ctx context.Context, lbacl *mode
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbacl := obj.(*models.SCachedLoadbalancerAcl)
|
||||
lbacl := obj.(*models.SLoadbalancerAcl)
|
||||
region, err := lbacl.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbacl, errors.Wrapf(err, "GetRegion"))
|
||||
@@ -58,13 +58,13 @@ func (self *LoadbalancerAclDeleteTask) OnInit(ctx context.Context, obj db.IStand
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) OnLoadbalancerAclDeleteComplete(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
func (self *LoadbalancerAclDeleteTask) OnLoadbalancerAclDeleteComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_DELETE, lbacl.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_DELOCATE, nil, self.UserCred, true)
|
||||
lbacl.RealDelete(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) OnLoadbalancerAclDeleteCompleteFailed(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
func (self *LoadbalancerAclDeleteTask) OnLoadbalancerAclDeleteCompleteFailed(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbacl, errors.Errorf(reason.String()))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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 tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerAclSyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerAclSyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncstatusTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, err error) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), apis.STATUS_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbacl := obj.(*models.SLoadbalancerAcl)
|
||||
region, err := lbacl.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbacl, errors.Wrapf(err, "GetRegion"))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerAclSyncstatusComplete", nil)
|
||||
err = region.GetDriver().RequestLoadbalancerAclSyncstatus(ctx, self.GetUserCred(), lbacl, self)
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbacl, errors.Wrapf(err, "RequestLoadbalancerAclSyncstatus"))
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncstatusTask) OnLoadbalancerAclSyncstatusComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncstatusTask) OnLoadbalancerAclSyncstatusCompleteFailed(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbacl, errors.Errorf(reason.String()))
|
||||
}
|
||||
+12
-11
@@ -20,6 +20,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
@@ -28,15 +29,15 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type LoadbalancerAclSyncTask struct {
|
||||
type LoadbalancerAclUpdateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerAclSyncTask{})
|
||||
taskman.RegisterTask(LoadbalancerAclUpdateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncTask) taskFail(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, err error) {
|
||||
func (self *LoadbalancerAclUpdateTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, err error) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), api.LB_SYNC_CONF_FAILED, err.Error())
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_SYNC_CONF, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_SYNC_CONF, err, self.UserCred, false)
|
||||
@@ -44,27 +45,27 @@ func (self *LoadbalancerAclSyncTask) taskFail(ctx context.Context, lbacl *models
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbacl := obj.(*models.SCachedLoadbalancerAcl)
|
||||
func (self *LoadbalancerAclUpdateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbacl := obj.(*models.SLoadbalancerAcl)
|
||||
region, err := lbacl.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbacl, errors.Wrapf(err, "GetRegion"))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerAclSyncComplete", nil)
|
||||
err = region.GetDriver().RequestSyncLoadbalancerAcl(ctx, self.GetUserCred(), lbacl, self)
|
||||
self.SetStage("OnLoadbalancerAclUpdateComplete", nil)
|
||||
err = region.GetDriver().RequestUpdateLoadbalancerAcl(ctx, self.GetUserCred(), lbacl, self)
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbacl, errors.Wrapf(err, "RequestSyncLoadbalancerAcl"))
|
||||
self.taskFail(ctx, lbacl, errors.Wrapf(err, "RequestUpdateLoadbalancerAcl"))
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncTask) OnLoadbalancerAclSyncComplete(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), api.LB_STATUS_ENABLED, "")
|
||||
func (self *LoadbalancerAclUpdateTask) OnLoadbalancerAclUpdateComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.SetStatus(ctx, self.GetUserCred(), apis.STATUS_AVAILABLE, "")
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_SYNC_CONF, lbacl.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_SYNC_CONF, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncTask) OnLoadbalancerAclSyncCompleteFailed(ctx context.Context, lbacl *models.SCachedLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
func (self *LoadbalancerAclUpdateTask) OnLoadbalancerAclUpdateCompleteFailed(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbacl, errors.Errorf(reason.String()))
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
@@ -36,7 +37,7 @@ func init() {
|
||||
taskman.RegisterTask(LoadbalancerCertificateCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) taskFail(ctx context.Context, lbcert *models.SCachedLoadbalancerCertificate, err error) {
|
||||
func (self *LoadbalancerCertificateCreateTask) taskFail(ctx context.Context, lbcert *models.SLoadbalancerCertificate, err error) {
|
||||
lbcert.SetStatus(ctx, self.GetUserCred(), api.LB_CREATE_FAILED, err.Error())
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_ALLOCATE_FAIL, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_CREATE, err, self.UserCred, false)
|
||||
@@ -45,7 +46,7 @@ func (self *LoadbalancerCertificateCreateTask) taskFail(ctx context.Context, lbc
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbcert := obj.(*models.SCachedLoadbalancerCertificate)
|
||||
lbcert := obj.(*models.SLoadbalancerCertificate)
|
||||
region, err := lbcert.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbcert, errors.Wrapf(err, "GetRegion"))
|
||||
@@ -58,13 +59,13 @@ func (self *LoadbalancerCertificateCreateTask) OnInit(ctx context.Context, obj d
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) OnLoadbalancerCertificateCreateComplete(ctx context.Context, lbcert *models.SCachedLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
lbcert.SetStatus(ctx, self.GetUserCred(), api.LB_STATUS_ENABLED, "")
|
||||
func (self *LoadbalancerCertificateCreateTask) OnLoadbalancerCertificateCreateComplete(ctx context.Context, lbcert *models.SLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
lbcert.SetStatus(ctx, self.GetUserCred(), apis.STATUS_AVAILABLE, "")
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_ALLOCATE, lbcert.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) OnLoadbalancerCertificateCreateCompleteFailed(ctx context.Context, lbcert *models.SCachedLoadbalancerCertificate, reason jsonutils.JSONObject) {
|
||||
func (self *LoadbalancerCertificateCreateTask) OnLoadbalancerCertificateCreateCompleteFailed(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbcert, errors.Errorf(reason.String()))
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func init() {
|
||||
taskman.RegisterTask(LoadbalancerCertificateDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) taskFail(ctx context.Context, lbcert *models.SCachedLoadbalancerCertificate, err error) {
|
||||
func (self *LoadbalancerCertificateDeleteTask) taskFail(ctx context.Context, lbcert *models.SLoadbalancerCertificate, err error) {
|
||||
lbcert.SetStatus(ctx, self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, err.Error())
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_DELOCATE_FAIL, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_DELOCATE, err, self.UserCred, false)
|
||||
@@ -45,7 +45,7 @@ func (self *LoadbalancerCertificateDeleteTask) taskFail(ctx context.Context, lbc
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbcert := obj.(*models.SCachedLoadbalancerCertificate)
|
||||
lbcert := obj.(*models.SLoadbalancerCertificate)
|
||||
region, err := lbcert.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbcert, errors.Wrapf(err, "GetRegion"))
|
||||
@@ -58,13 +58,13 @@ func (self *LoadbalancerCertificateDeleteTask) OnInit(ctx context.Context, obj d
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnLoadbalancerCertificateDeleteComplete(ctx context.Context, lbcert *models.SCachedLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnLoadbalancerCertificateDeleteComplete(ctx context.Context, lbcert *models.SLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_DELETE, lbcert.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_DELOCATE, nil, self.UserCred, true)
|
||||
lbcert.RealDelete(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnLoadbalancerCertificateDeleteCompleteFailed(ctx context.Context, lbcert *models.SCachedLoadbalancerCertificate, reason jsonutils.JSONObject) {
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnLoadbalancerCertificateDeleteCompleteFailed(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbcert, errors.Errorf(reason.String()))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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 tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerCertificateSyncstatusTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerCertificateSyncstatusTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateSyncstatusTask) taskFail(ctx context.Context, lbcert *models.SLoadbalancerCertificate, err error) {
|
||||
lbcert.SetStatus(ctx, self.GetUserCred(), apis.STATUS_UNKNOWN, err.Error())
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbcert := obj.(*models.SLoadbalancerCertificate)
|
||||
region, err := lbcert.GetRegion()
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbcert, errors.Wrapf(err, "GetRegion"))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerCertificateSyncstatusComplete", nil)
|
||||
err = region.GetDriver().RequestLoadbalancerCertificateSyncstatus(ctx, self.GetUserCred(), lbcert, self)
|
||||
if err != nil {
|
||||
self.taskFail(ctx, lbcert, errors.Wrapf(err, "RequestLoadbalancerCertificateSyncstatus"))
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateSyncstatusTask) OnLoadbalancerCertificateSyncstatusComplete(ctx context.Context, lbcert *models.SLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateSyncstatusTask) OnLoadbalancerCertificateSyncstatusCompleteFailed(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbcert, errors.Errorf(reason.String()))
|
||||
}
|
||||
@@ -35,6 +35,9 @@ func init() {
|
||||
[]string{
|
||||
"id",
|
||||
"name",
|
||||
"status",
|
||||
"cloudregion",
|
||||
"manager",
|
||||
"project",
|
||||
"is_public",
|
||||
"acl_entries",
|
||||
|
||||
@@ -1,45 +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/modulebase"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
)
|
||||
|
||||
type LoadbalancerCachedAclManager struct {
|
||||
modulebase.ResourceManager
|
||||
}
|
||||
|
||||
var (
|
||||
LoadbalancerCachedAcls LoadbalancerCachedAclManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
LoadbalancerCachedAcls = LoadbalancerCachedAclManager{
|
||||
modules.NewComputeManager(
|
||||
"cachedloadbalanceracl",
|
||||
"cachedloadbalanceracls",
|
||||
[]string{
|
||||
"id",
|
||||
"acl_id",
|
||||
"name",
|
||||
"acl_entries",
|
||||
},
|
||||
[]string{"tenant"},
|
||||
),
|
||||
}
|
||||
modules.RegisterCompute(&LoadbalancerCachedAcls)
|
||||
}
|
||||
@@ -1,50 +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/modulebase"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
)
|
||||
|
||||
type LoadbalancerCachedCertificateManager struct {
|
||||
modulebase.ResourceManager
|
||||
}
|
||||
|
||||
var (
|
||||
LoadbalancerCachedCertificates LoadbalancerCachedCertificateManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
LoadbalancerCachedCertificates = LoadbalancerCachedCertificateManager{
|
||||
modules.NewComputeManager(
|
||||
"cachedloadbalancercertificate",
|
||||
"cachedloadbalancercertificates",
|
||||
[]string{
|
||||
"id",
|
||||
"certificate_id",
|
||||
"name",
|
||||
"algorithm",
|
||||
"fingerprint",
|
||||
"not_before",
|
||||
"not_after",
|
||||
"common_name",
|
||||
"subject_alternative_names",
|
||||
},
|
||||
[]string{"tenant"},
|
||||
),
|
||||
}
|
||||
modules.RegisterCompute(&LoadbalancerCachedCertificates)
|
||||
}
|
||||
@@ -78,11 +78,6 @@ type LoadbalancerAclCreateOptions struct {
|
||||
AclEntry []string `help:"acl entry with cidr and comment separated by #, e.g. 10.9.0.0/16#no comment" json:"-"`
|
||||
Manager string `json:"manager_id"`
|
||||
Region string `json:"cloudregion"`
|
||||
Listener string `help:"Huawei listener id"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclGetOptions struct {
|
||||
ID string `json:"-"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclListOptions struct {
|
||||
@@ -90,19 +85,19 @@ type LoadbalancerAclListOptions struct {
|
||||
Cloudregion string
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerAclListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(opts)
|
||||
}
|
||||
|
||||
type LoadbalancerAclUpdateOptions struct {
|
||||
ID string `json:"-"`
|
||||
LoadbalancerAclIdOptions
|
||||
Name string
|
||||
|
||||
AclEntry []string `help:"acl entry with cidr and comment separated by #, e.g. 10.9.0.0/16#no comment" json:"-"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclDeleteOptions struct {
|
||||
ID string `json:"-"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclActionPatchOptions struct {
|
||||
ID string `json:"-"`
|
||||
LoadbalancerAclIdOptions
|
||||
Add []string `help:"acl entry with cidr and comment separated by #, e.g. 10.9.0.0/16#no comment" json:"-"`
|
||||
Del []string `help:"acl entry with cidr and comment separated by #, e.g. 10.9.0.0/16#no comment" json:"-"`
|
||||
}
|
||||
@@ -110,14 +105,26 @@ type LoadbalancerAclActionPatchOptions struct {
|
||||
type LoadbalancerAclPublicOptions struct {
|
||||
options.SharableResourcePublicBaseOptions
|
||||
|
||||
LoadbalancerAclIdOptions
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerAclPublicOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(opts.SharableResourcePublicBaseOptions), nil
|
||||
}
|
||||
|
||||
type LoadbalancerAclIdOptions struct {
|
||||
ID string `json:"-"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclPrivateOptions struct {
|
||||
ID string `json:"-"`
|
||||
func (opts *LoadbalancerAclIdOptions) GetId() string {
|
||||
return opts.ID
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerAclCreateOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
func (opts *LoadbalancerAclIdOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerAclCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -135,7 +142,7 @@ func (opts *LoadbalancerAclCreateOptions) Params() (*jsonutils.JSONDict, error)
|
||||
return params, nil
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerAclUpdateOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
func (opts *LoadbalancerAclUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -151,7 +158,7 @@ func (opts *LoadbalancerAclUpdateOptions) Params() (*jsonutils.JSONDict, error)
|
||||
return params, nil
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerAclActionPatchOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
func (opts *LoadbalancerAclActionPatchOptions) Params() (jsonutils.JSONObject, error) {
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -54,11 +54,14 @@ type LoadbalancerCertificateCreateOptions struct {
|
||||
|
||||
NAME string
|
||||
|
||||
Manager string `json:"manager_id"`
|
||||
Region string `json:"cloudregion"`
|
||||
|
||||
Cert string `required:"true" json:"-" help:"path to certificate file"`
|
||||
Pkey string `required:"true" json:"-" help:"path to private key file"`
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerCertificateCreateOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
func (opts *LoadbalancerCertificateCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -79,10 +82,18 @@ func (opts *LoadbalancerCertificateCreateOptions) Params() (*jsonutils.JSONDict,
|
||||
return params, nil
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateGetOptions struct {
|
||||
type LoadbalancerCertificateIdOptions struct {
|
||||
ID string `json:"-"`
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerCertificateIdOptions) GetId() string {
|
||||
return opts.ID
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerCertificateIdOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateDeleteOptions struct {
|
||||
ID string `json:"-"`
|
||||
}
|
||||
@@ -102,14 +113,14 @@ func (opts *LoadbalancerCertificateListOptions) Params() (jsonutils.JSONObject,
|
||||
}
|
||||
|
||||
type LoadbalancerCertificateUpdateOptions struct {
|
||||
ID string `json:"-"`
|
||||
LoadbalancerCertificateIdOptions
|
||||
Name string
|
||||
|
||||
Cert string `json:"-" help:"path to certificate file"`
|
||||
Pkey string `json:"-" help:"path to private key file"`
|
||||
}
|
||||
|
||||
func (opts *LoadbalancerCertificateUpdateOptions) Params() (*jsonutils.JSONDict, error) {
|
||||
func (opts *LoadbalancerCertificateUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
paramsCertKey, err := loadbalancerCertificateLoadFiles(opts.Cert, opts.Pkey, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -119,9 +130,12 @@ func (opts *LoadbalancerCertificateUpdateOptions) Params() (*jsonutils.JSONDict,
|
||||
}
|
||||
|
||||
type LoadbalancerCertificatePublicOptions struct {
|
||||
LoadbalancerCertificateIdOptions
|
||||
options.SharableResourcePublicBaseOptions
|
||||
}
|
||||
|
||||
ID string `json:"-"`
|
||||
func (opts *LoadbalancerCertificatePublicOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(opts.SharableResourcePublicBaseOptions), nil
|
||||
}
|
||||
|
||||
type LoadbalancerCertificatePrivateOptions struct {
|
||||
|
||||
Vendored
+1
-1
@@ -1465,7 +1465,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240220074040-c367f1e9972c
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240221114447-a32f31a35fd3
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
-4
@@ -22,8 +22,4 @@ type SLoadbalancerAccessControlListEntry struct {
|
||||
type SLoadbalancerAccessControlList struct {
|
||||
Name string
|
||||
Entrys []SLoadbalancerAccessControlListEntry
|
||||
|
||||
// used by huawei
|
||||
ListenerId string
|
||||
AccessControlEnable bool
|
||||
}
|
||||
|
||||
-2
@@ -839,7 +839,6 @@ type ICloudLoadbalancerBackend interface {
|
||||
type ICloudLoadbalancerCertificate interface {
|
||||
IVirtualResource
|
||||
|
||||
Sync(name, privateKey, publickKey string) error
|
||||
Delete() error
|
||||
|
||||
GetCommonName() string
|
||||
@@ -853,7 +852,6 @@ type ICloudLoadbalancerCertificate interface {
|
||||
type ICloudLoadbalancerAcl interface {
|
||||
IVirtualResource
|
||||
|
||||
GetAclListenerID() string // huawei only
|
||||
GetAclEntries() []SLoadbalancerAccessControlListEntry
|
||||
Sync(acl *SLoadbalancerAccessControlList) error
|
||||
Delete() error
|
||||
|
||||
+2
-5
@@ -18,6 +18,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -42,10 +43,6 @@ type SLoadbalancerAcl struct {
|
||||
AclEntrys AclEntrys
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetAclListenerID() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetName() string {
|
||||
return acl.AclName
|
||||
}
|
||||
@@ -59,7 +56,7 @@ func (acl *SLoadbalancerAcl) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetStatus() string {
|
||||
return ""
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) Refresh() error {
|
||||
|
||||
Generated
Vendored
+2
-12
@@ -19,6 +19,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
|
||||
@@ -68,11 +69,7 @@ func (certificate *SLoadbalancerServerCertificate) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) GetStatus() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) IsEmulated() bool {
|
||||
return false
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) GetCommonName() string {
|
||||
@@ -104,13 +101,6 @@ func (region *SRegion) UpdateServerCertificateName(certId, name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) Sync(name string, privateKey string, publicKey string) error {
|
||||
if certificate.ServerCertificateName != name {
|
||||
return certificate.region.UpdateServerCertificateName(certificate.ServerCertificateId, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) Delete() error {
|
||||
return certificate.region.DeleteServerCertificate(certificate.ServerCertificateId)
|
||||
}
|
||||
|
||||
+2
-9
@@ -18,6 +18,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -44,10 +45,6 @@ type SLoadbalancerAcl struct {
|
||||
DepartmentInfo
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetAclListenerID() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetName() string {
|
||||
return acl.AclName
|
||||
}
|
||||
@@ -61,11 +58,7 @@ func (acl *SLoadbalancerAcl) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetStatus() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) IsEmulated() bool {
|
||||
return false
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) Refresh() error {
|
||||
|
||||
Generated
Vendored
+2
-12
@@ -19,6 +19,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
|
||||
@@ -68,11 +69,7 @@ func (certificate *SLoadbalancerServerCertificate) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) GetStatus() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) IsEmulated() bool {
|
||||
return false
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) GetCommonName() string {
|
||||
@@ -104,13 +101,6 @@ func (region *SRegion) UpdateServerCertificateName(certId, name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) Sync(name string, privateKey string, publicKey string) error {
|
||||
if certificate.ServerCertificateName != name {
|
||||
return certificate.region.UpdateServerCertificateName(certificate.ServerCertificateId, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) Delete() error {
|
||||
return certificate.region.DeleteServerCertificate(certificate.ServerCertificateId)
|
||||
}
|
||||
|
||||
+2
-10
@@ -26,7 +26,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -59,7 +59,7 @@ func (self *SElbCertificate) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SElbCertificate) GetStatus() string {
|
||||
return api.LB_STATUS_ENABLED
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SElbCertificate) Refresh() error {
|
||||
@@ -76,18 +76,10 @@ func (self *SElbCertificate) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElbCertificate) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SElbCertificate) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SElbCertificate) Sync(name, privateKey, publickKey string) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SElbCertificate) Delete() error {
|
||||
return self.region.deleteElbCertificate(self.GetName())
|
||||
}
|
||||
|
||||
+2
-10
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -54,7 +54,7 @@ func (self *SLoadbalancerCert) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCert) GetStatus() string {
|
||||
return api.LB_STATUS_ENABLED
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCert) Refresh() error {
|
||||
@@ -71,10 +71,6 @@ func (self *SLoadbalancerCert) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCert) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCert) GetSysTags() map[string]string {
|
||||
return nil
|
||||
}
|
||||
@@ -91,10 +87,6 @@ func (self *SLoadbalancerCert) GetProjectId() string {
|
||||
return getResourceGroup(self.GetId())
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCert) Sync(name, privateKey, publickKey string) error {
|
||||
return errors.Wrap(cloudprovider.ErrNotImplemented, "Sync")
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCert) Delete() error {
|
||||
return errors.Wrap(cloudprovider.ErrNotImplemented, "Delete")
|
||||
}
|
||||
|
||||
+2
-9
@@ -25,6 +25,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
)
|
||||
@@ -49,17 +50,13 @@ type SelfManaged struct {
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) GetStatus() string {
|
||||
return api.LB_STATUS_ENABLED
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) GetCreatedAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
@@ -80,10 +77,6 @@ func (self *SLoadbalancerCertificate) GetProjectId() string {
|
||||
return self.region.GetProjectId()
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) Sync(name, privateKey, publickKey string) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SLoadbalancerCertificate) Delete() error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
+4
@@ -46,3 +46,7 @@ func (r *SResourceBase) GetName() string {
|
||||
func (r *SResourceBase) GetDescription() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *SResourceBase) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
+3
-15
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud/huawei"
|
||||
@@ -37,10 +37,6 @@ type SElbACL struct {
|
||||
Whitelist string `json:"whitelist"`
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetAclListenerID() string {
|
||||
return self.ListenerID
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetId() string {
|
||||
return self.ID
|
||||
}
|
||||
@@ -54,11 +50,7 @@ func (self *SElbACL) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetStatus() string {
|
||||
if self.EnableWhitelist {
|
||||
return api.LB_BOOL_ON
|
||||
}
|
||||
|
||||
return api.LB_BOOL_OFF
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SElbACL) Refresh() error {
|
||||
@@ -75,10 +67,6 @@ func (self *SElbACL) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElbACL) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
@@ -104,7 +92,7 @@ func (self *SElbACL) Sync(acl *cloudprovider.SLoadbalancerAccessControlList) err
|
||||
params := jsonutils.NewDict()
|
||||
whiteListObj := jsonutils.NewDict()
|
||||
whiteListObj.Set("whitelist", jsonutils.NewString(whiteList))
|
||||
whiteListObj.Set("enable_whitelist", jsonutils.NewBool(acl.AccessControlEnable))
|
||||
whiteListObj.Set("enable_whitelist", jsonutils.NewBool(true))
|
||||
params.Set("whitelist", whiteListObj)
|
||||
return DoUpdate(self.region.ecsClient.ElbWhitelist.Update, self.GetId(), params, nil)
|
||||
}
|
||||
|
||||
+2
-14
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud/huawei"
|
||||
)
|
||||
@@ -67,7 +67,7 @@ func (self *SElbCert) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SElbCert) GetStatus() string {
|
||||
return api.LB_STATUS_ENABLED
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SElbCert) Refresh() error {
|
||||
@@ -85,22 +85,10 @@ func (self *SElbCert) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SElbCert) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SElbCert) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SElbCert) Sync(name, privateKey, publickKey string) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("name", jsonutils.NewString(name))
|
||||
params.Set("private_key", jsonutils.NewString(privateKey))
|
||||
params.Set("certificate", jsonutils.NewString(publickKey))
|
||||
return DoUpdate(self.region.ecsClient.ElbCertificates.Update, self.GetId(), params, nil)
|
||||
}
|
||||
|
||||
func (self *SElbCert) Delete() error {
|
||||
return DoDelete(self.region.ecsClient.ElbCertificates.Delete, self.GetId(), nil, nil)
|
||||
}
|
||||
|
||||
+4
-9
@@ -771,25 +771,20 @@ func (self *SRegion) CreateLoadBalancer(loadbalancer *cloudprovider.SLoadbalance
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
ret, err := self.CreateLoadBalancerAcl(acl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ret, nil
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (SElbACL, error) {
|
||||
func (self *SRegion) CreateLoadBalancerAcl(listenerId string, acl *cloudprovider.SLoadbalancerAccessControlList) (SElbACL, error) {
|
||||
params := jsonutils.NewDict()
|
||||
aclObj := jsonutils.NewDict()
|
||||
aclObj.Set("listener_id", jsonutils.NewString(acl.ListenerId))
|
||||
aclObj.Set("listener_id", jsonutils.NewString(listenerId))
|
||||
if len(acl.Entrys) > 0 {
|
||||
whitelist := []string{}
|
||||
for i := range acl.Entrys {
|
||||
whitelist = append(whitelist, acl.Entrys[i].CIDR)
|
||||
}
|
||||
|
||||
aclObj.Set("enable_whitelist", jsonutils.NewBool(acl.AccessControlEnable))
|
||||
aclObj.Set("enable_whitelist", jsonutils.NewBool(true))
|
||||
aclObj.Set("whitelist", jsonutils.NewString(strings.Join(whitelist, ",")))
|
||||
} else {
|
||||
aclObj.Set("enable_whitelist", jsonutils.NewBool(false))
|
||||
|
||||
+10
-22
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -37,10 +37,6 @@ type SElbACL struct {
|
||||
Whitelist string `json:"whitelist"`
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetAclListenerID() string {
|
||||
return self.ListenerID
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetId() string {
|
||||
return self.ID
|
||||
}
|
||||
@@ -54,11 +50,7 @@ func (self *SElbACL) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetStatus() string {
|
||||
if self.EnableWhitelist {
|
||||
return api.LB_BOOL_ON
|
||||
}
|
||||
|
||||
return api.LB_BOOL_OFF
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SElbACL) Refresh() error {
|
||||
@@ -69,10 +61,6 @@ func (self *SElbACL) Refresh() error {
|
||||
return jsonutils.Update(self, acl)
|
||||
}
|
||||
|
||||
func (self *SElbACL) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SElbACL) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
@@ -95,7 +83,7 @@ func (self *SElbACL) Sync(acl *cloudprovider.SLoadbalancerAccessControlList) err
|
||||
whiteList = strings.Join(cidrs, ",")
|
||||
params := map[string]interface{}{
|
||||
"whitelist": whiteList,
|
||||
"enable_whitelist": acl.AccessControlEnable,
|
||||
"enable_whitelist": true,
|
||||
}
|
||||
_, err := self.region.put(SERVICE_ELB, "elb/whitelists/"+self.GetId(), map[string]interface{}{"whitelist": params})
|
||||
return err
|
||||
@@ -115,7 +103,7 @@ func (self *SRegion) GetLoadBalancerAcl(aclId string) (*SElbACL, error) {
|
||||
return ret, resp.Unmarshal(ret, "whitelist")
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/zh-cn_topic_0096561582.html
|
||||
// https://console.huaweicloud.com/apiexplorer/#/openapi/ELB/doc?version=v2&api=ListWhitelists
|
||||
func (self *SRegion) GetLoadBalancerAcls(listenerId string) ([]SElbACL, error) {
|
||||
query := url.Values{}
|
||||
if len(listenerId) > 0 {
|
||||
@@ -129,16 +117,16 @@ func (self *SRegion) GetLoadBalancerAcls(listenerId string) ([]SElbACL, error) {
|
||||
return ret, resp.Unmarshal(&ret, "whitelists")
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateLoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (*SElbACL, error) {
|
||||
func (self *SRegion) CreateLoadBalancerAcl(listenerId string, opts *cloudprovider.SLoadbalancerAccessControlList) (*SElbACL, error) {
|
||||
params := map[string]interface{}{
|
||||
"listener_id": acl.ListenerId,
|
||||
"listener_id": listenerId,
|
||||
}
|
||||
if len(acl.Entrys) > 0 {
|
||||
if len(opts.Entrys) > 0 {
|
||||
whitelist := []string{}
|
||||
for i := range acl.Entrys {
|
||||
whitelist = append(whitelist, acl.Entrys[i].CIDR)
|
||||
for i := range opts.Entrys {
|
||||
whitelist = append(whitelist, opts.Entrys[i].CIDR)
|
||||
}
|
||||
params["enable_whitelist"] = acl.AccessControlEnable
|
||||
params["enable_whitelist"] = "true"
|
||||
params["whitelist"] = strings.Join(whitelist, ",")
|
||||
} else {
|
||||
params["enable_whitelist"] = false
|
||||
|
||||
+3
-17
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -68,7 +68,7 @@ func (self *SElbCert) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SElbCert) GetStatus() string {
|
||||
return api.LB_STATUS_ENABLED
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (self *SElbCert) Refresh() error {
|
||||
@@ -79,24 +79,10 @@ func (self *SElbCert) Refresh() error {
|
||||
return jsonutils.Update(self, cert)
|
||||
}
|
||||
|
||||
func (self *SElbCert) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SElbCert) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SElbCert) Sync(name, privateKey, publickKey string) error {
|
||||
params := map[string]interface{}{
|
||||
"name": name,
|
||||
"private_key": privateKey,
|
||||
"certificate": publickKey,
|
||||
}
|
||||
_, err := self.region.put(SERVICE_ELB, "elb/certificates/"+self.GetId(), params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SElbCert) Delete() error {
|
||||
_, err := self.region.delete(SERVICE_ELB, "elb/certificates/"+self.GetId())
|
||||
return err
|
||||
@@ -126,7 +112,7 @@ func (self *SRegion) GetLoadBalancerCertificate(id string) (*SElbCert, error) {
|
||||
return nil, err
|
||||
}
|
||||
ret := &SElbCert{region: self}
|
||||
return ret, resp.Unmarshal(ret)
|
||||
return ret, resp.Unmarshal(ret, "certificate")
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-elb/elb_qy_zs_0001.html
|
||||
|
||||
+1
-6
@@ -523,12 +523,7 @@ func (self *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalanc
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
ret, err := self.CreateLoadBalancerAcl(acl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SRegion) GetIBuckets() ([]cloudprovider.ICloudBucket, error) {
|
||||
|
||||
+4
-31
@@ -18,10 +18,10 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -41,10 +41,6 @@ type SLoadbalancerAcl struct {
|
||||
listener *SLoadbalancerListener
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetAclListenerID() string {
|
||||
return acl.listener.ID
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetName() string {
|
||||
return acl.listener.Name + "AllowedCidrs"
|
||||
}
|
||||
@@ -58,11 +54,7 @@ func (acl *SLoadbalancerAcl) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetStatus() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) IsEmulated() bool {
|
||||
return false
|
||||
return apis.STATUS_AVAILABLE
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) Refresh() error {
|
||||
@@ -138,26 +130,7 @@ func (region *SRegion) GetLoadBalancerAcls() ([]SLoadbalancerAcl, error) {
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateLoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (*SLoadbalancerAcl, error) {
|
||||
if !acl.AccessControlEnable {
|
||||
return nil, errors.Wrap(fmt.Errorf("only support allowed cidrs"), "CreateLoadBalancerAcl")
|
||||
}
|
||||
if len(acl.ListenerId) < 1 {
|
||||
return nil, errors.Wrap(fmt.Errorf("loadbalanceracl must band to a loadbalancerlistener"), "CreateLoadBalancerAcl")
|
||||
}
|
||||
cidrs := []string{}
|
||||
for i := 0; i < len(acl.Entrys); i++ {
|
||||
cidrs = append(cidrs, acl.Entrys[i].CIDR)
|
||||
}
|
||||
sacl, err := region.GetLoadbalancerAclDetail(acl.ListenerId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "region.GetLoadbalancerAclDetail(%s)", acl.ListenerId)
|
||||
}
|
||||
// ensure listener status
|
||||
err = waitLbResStatus(sacl.listener, 10*time.Second, 8*time.Minute)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, `waitLbResStatus(sacl.listener, 10*time.Second, 8*time.Minute)`)
|
||||
}
|
||||
return sacl, region.UpdateLoadbalancerListenerAllowedCidrs(acl.ListenerId, cidrs)
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) Sync(_acl *cloudprovider.SLoadbalancerAccessControlList) error {
|
||||
|
||||
+17
-13
@@ -24,6 +24,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/apis"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
@@ -121,11 +122,6 @@ func (self *SCertificate) GetKey() string {
|
||||
return self.CertificatePrivateKey
|
||||
}
|
||||
|
||||
// 证书不能修改
|
||||
func (self *SCertificate) Sync(name, privateKey, publickKey string) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SCertificate) Delete() error {
|
||||
return self.region.DeleteCertificate(self.GetId())
|
||||
}
|
||||
@@ -146,12 +142,21 @@ func (self *SCertificate) GetGlobalId() string {
|
||||
return self.CertificateID
|
||||
}
|
||||
|
||||
// todo: 貌似目前onecloud没有记录状态
|
||||
func (self *SCertificate) GetStatus() string {
|
||||
if _, ok := CERT_STATUS_MAP[self.Status]; !ok {
|
||||
return "unknown"
|
||||
status, ok := CERT_STATUS_MAP[self.Status]
|
||||
if !ok {
|
||||
return apis.STATUS_UNKNOWN
|
||||
}
|
||||
switch status {
|
||||
case "normal":
|
||||
return apis.STATUS_AVAILABLE
|
||||
case "deleted":
|
||||
return apis.STATUS_DELETING
|
||||
case "pending":
|
||||
return apis.STATUS_CREATING
|
||||
default:
|
||||
return status
|
||||
}
|
||||
return CERT_STATUS_MAP[self.Status]
|
||||
}
|
||||
|
||||
func (self *SCertificate) Refresh() error {
|
||||
@@ -163,10 +168,6 @@ func (self *SCertificate) Refresh() error {
|
||||
return jsonutils.Update(self, cert)
|
||||
}
|
||||
|
||||
func (self *SCertificate) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SCertificate) GetCommonName() string {
|
||||
return self.Domain
|
||||
}
|
||||
@@ -363,6 +364,9 @@ func (self *SRegion) DeleteCertificate(id string) error {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetILoadBalancerCertificates() ([]cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
if self.Region != QCLOUD_DEFAULT_REGION {
|
||||
return []cloudprovider.ICloudLoadbalancerCertificate{}, nil
|
||||
}
|
||||
certs, err := self.GetCertificates("", "", "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetCertificates")
|
||||
|
||||
+15
-8
@@ -145,12 +145,17 @@ func (disk *SDisk) GetMountpoint() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetISnapshot(snapshotId string) (cloudprovider.ICloudSnapshot, error) {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "GetISnapshot")
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "GetISnapshots")
|
||||
snapshots, err := disk.storage.zone.region.GetSnapshots(disk.VolumeId, "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := []cloudprovider.ICloudSnapshot{}
|
||||
for i := range snapshots {
|
||||
snapshots[i].region = disk.storage.zone.region
|
||||
ret = append(ret, &snapshots[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (disk *SDisk) Reset(ctx context.Context, snapshotId string) (string, error) {
|
||||
@@ -185,10 +190,12 @@ func (disk *SDisk) GetProjectId() string {
|
||||
return disk.ProjectName
|
||||
}
|
||||
|
||||
// Snapshot API is not supported, refer to
|
||||
// https://www.volcengine.com/docs/6460/195549
|
||||
func (disk *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (cloudprovider.ICloudSnapshot, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
snapshot, err := disk.storage.zone.region.CreateSnapshot(disk.VolumeId, name, desc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
// region
|
||||
|
||||
+25
-18
@@ -248,15 +248,12 @@ func (subnet *SNetwork) GetAllocTimeoutSeconds() int {
|
||||
return 120
|
||||
}
|
||||
|
||||
func (region *SRegion) GetSubnets(ids []string, zoneId string, vpcId string, pageNumber int, pageSize int) ([]SNetwork, int, error) {
|
||||
if pageSize > 100 || pageSize <= 0 {
|
||||
pageSize = 100
|
||||
}
|
||||
func (region *SRegion) GetSubnets(ids []string, zoneId string, vpcId string) ([]SNetwork, error) {
|
||||
params := make(map[string]string)
|
||||
params["PageSize"] = fmt.Sprintf("%d", pageSize)
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNumber)
|
||||
params["PageSize"] = "100"
|
||||
pageNum := 1
|
||||
for idx, id := range ids {
|
||||
params[fmt.Sprintf("SubnetIds.%d", idx)] = id
|
||||
params[fmt.Sprintf("SubnetIds.%d", idx+1)] = id
|
||||
}
|
||||
if len(zoneId) > 0 {
|
||||
params["ZoneId"] = zoneId
|
||||
@@ -265,18 +262,28 @@ func (region *SRegion) GetSubnets(ids []string, zoneId string, vpcId string, pag
|
||||
params["VpcId"] = vpcId
|
||||
}
|
||||
|
||||
body, err := region.vpcRequest("DescribeSubnets", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "GetSubnets fail")
|
||||
ret := []SNetwork{}
|
||||
for {
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNum)
|
||||
resp, err := region.vpcRequest("DescribeSubnets", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetSubnets fail")
|
||||
}
|
||||
part := struct {
|
||||
Subnets []SNetwork
|
||||
TotalCount int
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Unmarshal")
|
||||
}
|
||||
ret = append(ret, part.Subnets...)
|
||||
if len(ret) >= part.TotalCount || len(part.Subnets) == 0 {
|
||||
break
|
||||
}
|
||||
pageNum++
|
||||
}
|
||||
|
||||
subnets := make([]SNetwork, 0)
|
||||
err = body.Unmarshal(&subnets, "Subnets")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "Unmarshal subnets fail")
|
||||
}
|
||||
total, _ := body.Int("TotalCount")
|
||||
return subnets, int(total), nil
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetSubnetAttributes(SubnetId string) (*SNetwork, error) {
|
||||
|
||||
-17
@@ -340,23 +340,6 @@ func (region *SRegion) GetIEips() ([]cloudprovider.ICloudEIP, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) FetchSubnets(ids []string, zoneId string, vpcId string) ([]SNetwork, error) {
|
||||
pageNumber := 1
|
||||
nets := make([]SNetwork, 0)
|
||||
for {
|
||||
parts, total, err := region.GetSubnets(ids, zoneId, vpcId, pageNumber, 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nets = append(nets, parts...)
|
||||
if len(nets) >= total {
|
||||
break
|
||||
}
|
||||
pageNumber += 1
|
||||
}
|
||||
return nets, nil
|
||||
}
|
||||
|
||||
// IBucket
|
||||
func (region *SRegion) IBucketExist(name string) (bool, error) {
|
||||
toscli, err := region.GetTosClient()
|
||||
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
// 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 volcengine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/cloudmux/pkg/multicloud"
|
||||
)
|
||||
|
||||
type SSnapshot struct {
|
||||
multicloud.SResourceBase
|
||||
VolcEngineTags
|
||||
region *SRegion
|
||||
|
||||
SnapshotId string
|
||||
ZoneId string
|
||||
VolumeId string
|
||||
Status string
|
||||
SnapshotName string
|
||||
Description string
|
||||
CreationTime time.Time
|
||||
SnapshotType string
|
||||
VolumeType string
|
||||
VolumeKind string
|
||||
VolumeName string
|
||||
VolumeStatus string
|
||||
RetentionDays int
|
||||
ProjectName string
|
||||
Progress int
|
||||
SnapshotGroupId string
|
||||
ImageId string
|
||||
VolumeSize int32
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetId() string {
|
||||
return self.SnapshotId
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetName() string {
|
||||
return self.SnapshotName
|
||||
}
|
||||
|
||||
// available creating rollbacking deleting failed
|
||||
func (self *SSnapshot) GetStatus() string {
|
||||
switch self.Status {
|
||||
case "available":
|
||||
return api.SNAPSHOT_READY
|
||||
case "creating":
|
||||
return api.SNAPSHOT_CREATING
|
||||
case "failed":
|
||||
return api.SNAPSHOT_FAILED
|
||||
case "rollbacking":
|
||||
return api.SNAPSHOT_ROLLBACKING
|
||||
case "deleting":
|
||||
return api.SNAPSHOT_DELETING
|
||||
default:
|
||||
return self.Status
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetSizeMb() int32 {
|
||||
return self.VolumeSize * 1024
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetDiskId() string {
|
||||
return self.VolumeId
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetDiskType() string {
|
||||
if self.VolumeKind == "system" {
|
||||
return api.DISK_TYPE_SYS
|
||||
}
|
||||
return api.DISK_TYPE_DATA
|
||||
}
|
||||
|
||||
func (self *SSnapshot) Refresh() error {
|
||||
snapshot, err := self.region.GetSnapshot(self.SnapshotId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jsonutils.Update(self, snapshot)
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetGlobalId() string {
|
||||
return self.SnapshotId
|
||||
}
|
||||
|
||||
func (self *SRegion) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
|
||||
snapshots, err := self.GetSnapshots("", "", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := make([]cloudprovider.ICloudSnapshot, len(snapshots))
|
||||
for i := 0; i < len(snapshots); i += 1 {
|
||||
snapshots[i].region = self
|
||||
ret[i] = &snapshots[i]
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SSnapshot) Delete() error {
|
||||
return self.region.DeleteSnapshot(self.SnapshotId)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSnapshots(diskId string, snapshotName string, snapshotIds []string) ([]SSnapshot, error) {
|
||||
params := make(map[string]string)
|
||||
params["PageSize"] = "100"
|
||||
pageNum := 1
|
||||
|
||||
if len(diskId) > 0 {
|
||||
params["VolumeId"] = diskId
|
||||
}
|
||||
if len(snapshotName) > 0 {
|
||||
params["SnapshotName"] = snapshotName
|
||||
}
|
||||
for i, id := range snapshotIds {
|
||||
params[fmt.Sprintf("SnapshotIds.%d", i+1)] = id
|
||||
}
|
||||
|
||||
ret := []SSnapshot{}
|
||||
for {
|
||||
params["PageNumber"] = fmt.Sprintf("%d", pageNum)
|
||||
resp, err := self.storageRequest("DescribeSnapshots", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "DescribeSnapshots")
|
||||
}
|
||||
part := struct {
|
||||
Snapshots []SSnapshot
|
||||
TotalCount int64
|
||||
}{}
|
||||
err = resp.Unmarshal(&part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, part.Snapshots...)
|
||||
if len(part.Snapshots) == 0 || len(ret) >= int(part.TotalCount) {
|
||||
break
|
||||
}
|
||||
pageNum++
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSnapshot(id string) (*SSnapshot, error) {
|
||||
snapshots, err := self.GetSnapshots("", "", []string{id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range snapshots {
|
||||
snapshots[i].region = self
|
||||
if snapshots[i].SnapshotId == id {
|
||||
return &snapshots[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, id)
|
||||
}
|
||||
|
||||
func (self *SRegion) GetISnapshotById(id string) (cloudprovider.ICloudSnapshot, error) {
|
||||
snapshot, err := self.GetSnapshot(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteSnapshot(snapshotId string) error {
|
||||
params := make(map[string]string)
|
||||
params["SnapshotId"] = snapshotId
|
||||
params["ClientToken"] = utils.GenRequestId(20)
|
||||
_, err := self.storageRequest("DeleteSnapshot", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
return self.ProjectName
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateSnapshot(diskId, name, desc string) (*SSnapshot, error) {
|
||||
params := map[string]string{
|
||||
"SnapshotName": name,
|
||||
"ClientToken": utils.GenRequestId(20),
|
||||
"Description": desc,
|
||||
"VolumeId": diskId,
|
||||
}
|
||||
resp, err := self.storageRequest("CreateSnapshot", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, err := resp.GetString("SnapshotId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.GetSnapshot(id)
|
||||
}
|
||||
+1
-1
@@ -71,7 +71,7 @@ func (wire *SWire) GetBandwidth() int {
|
||||
}
|
||||
|
||||
func (wire *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
|
||||
networks, err := wire.vpc.region.FetchSubnets(nil, wire.zone.ZoneId, wire.vpc.VpcId)
|
||||
networks, err := wire.vpc.region.GetSubnets(nil, wire.zone.ZoneId, wire.vpc.VpcId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user