mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 23:41:52 +08:00
添加region driver
This commit is contained in:
@@ -93,6 +93,14 @@ func init() {
|
||||
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 {
|
||||
|
||||
@@ -51,7 +51,7 @@ func init() {
|
||||
printObject(lbbackendgroup)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerBackendGroupDeleteOptions{}, "lbbackendgroup-delete", "Show lbbackendgroup", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendGroupDeleteOptions) error {
|
||||
R(&options.LoadbalancerBackendGroupDeleteOptions{}, "lbbackendgroup-delete", "Delete lbbackendgroup", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendGroupDeleteOptions) error {
|
||||
lbbackendgroup, err := modules.LoadbalancerBackendGroups.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -59,4 +59,12 @@ func init() {
|
||||
printObject(lbbackendgroup)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerBackendGroupDeleteOptions{}, "lbbackendgroup-purge", "Purge lbbackendgroup", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendGroupDeleteOptions) error {
|
||||
lbbackendgroup, err := modules.LoadbalancerBackendGroups.PerformAction(s, opts.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbbackendgroup)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func init() {
|
||||
printObject(lbbackend)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerBackendDeleteOptions{}, "lbbackend-delete", "Show lbbackend", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendDeleteOptions) error {
|
||||
R(&options.LoadbalancerBackendDeleteOptions{}, "lbbackend-delete", "Delete lbbackend", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendDeleteOptions) error {
|
||||
lbbackend, err := modules.LoadbalancerBackends.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -56,4 +56,12 @@ func init() {
|
||||
printObject(lbbackend)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerBackendDeleteOptions{}, "lbbackend-purge", "Purge lbbackend", func(s *mcclient.ClientSession, opts *options.LoadbalancerBackendDeleteOptions) error {
|
||||
lbbackend, err := modules.LoadbalancerBackends.PerformAction(s, opts.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lbbackend)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func init() {
|
||||
printObject(lblistenerrule)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerListenerRuleDeleteOptions{}, "lblistenerrule-delete", "Show lblistenerrule", func(s *mcclient.ClientSession, opts *options.LoadbalancerListenerRuleDeleteOptions) error {
|
||||
R(&options.LoadbalancerListenerRuleDeleteOptions{}, "lblistenerrule-delete", "Delete lblistenerrule", func(s *mcclient.ClientSession, opts *options.LoadbalancerListenerRuleDeleteOptions) error {
|
||||
lblistenerrule, err := modules.LoadbalancerListenerRules.Delete(s, opts.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -54,6 +54,14 @@ func init() {
|
||||
printObject(lblistenerrule)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerListenerRuleDeleteOptions{}, "lblistenerrule-purge", "Purge lblistenerrule", func(s *mcclient.ClientSession, opts *options.LoadbalancerListenerRuleDeleteOptions) error {
|
||||
lblistenerrule, err := modules.LoadbalancerListenerRules.PerformAction(s, opts.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lblistenerrule)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerListenerRuleActionStatusOptions{}, "lblistenerrule-status", "Change lblistenerrule status", func(s *mcclient.ClientSession, opts *options.LoadbalancerListenerRuleActionStatusOptions) error {
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
|
||||
@@ -56,6 +56,14 @@ func init() {
|
||||
printObject(lb)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerPurgeOptions{}, "lb-purge", "Purge lb", func(s *mcclient.ClientSession, opts *options.LoadbalancerPurgeOptions) error {
|
||||
lb, err := modules.Loadbalancers.PerformAction(s, opts.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(lb)
|
||||
return nil
|
||||
})
|
||||
R(&options.LoadbalancerActionStatusOptions{}, "lb-status", "Change lb status", func(s *mcclient.ClientSession, opts *options.LoadbalancerActionStatusOptions) error {
|
||||
params, err := options.StructToParams(opts)
|
||||
if err != nil {
|
||||
|
||||
@@ -84,6 +84,22 @@ func (region *SFakeOnPremiseRegion) GetILoadBalancers() ([]ICloudLoadbalancer, e
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SFakeOnPremiseRegion) GetILoadBalancerById(loadbalancerId string) (ICloudLoadbalancer, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SFakeOnPremiseRegion) GetILoadBalancerAclById(aclId string) (ICloudLoadbalancerAcl, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SFakeOnPremiseRegion) GetILoadBalancerCertificateById(certId string) (ICloudLoadbalancerCertificate, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SFakeOnPremiseRegion) CreateILoadBalancerCertificate(name string, privateKey, certificate string) (ICloudLoadbalancerCertificate, error) {
|
||||
return nil, ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SFakeOnPremiseRegion) GetILoadbalancerAcls() ([]ICloudLoadbalancerAcl, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
@@ -91,3 +107,11 @@ func (region *SFakeOnPremiseRegion) GetILoadbalancerAcls() ([]ICloudLoadbalancer
|
||||
func (region *SFakeOnPremiseRegion) GetILoadbalancerCertificates() ([]ICloudLoadbalancerCertificate, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SFakeOnPremiseRegion) CreateILoadBalancer(loadbalancer *SLoadbalancer) (ICloudLoadbalancer, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SFakeOnPremiseRegion) CreateILoadBalancerAcl(acl *SLoadbalancerAccessControlList) (ICloudLoadbalancerAcl, error) {
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package cloudprovider
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/util/billing"
|
||||
|
||||
type SLoadbalancer struct {
|
||||
Name string
|
||||
ZoneID string
|
||||
VpcID string
|
||||
NetworkID string
|
||||
Address string
|
||||
AddressType string
|
||||
LoadbalancerSpec string
|
||||
ChargeType string
|
||||
Bandwidth int
|
||||
billingCycle *billing.SBillingCycle
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package cloudprovider
|
||||
|
||||
type SLoadbalancerAccessControlListEntry struct {
|
||||
CIDR string
|
||||
Comment string
|
||||
}
|
||||
|
||||
type SLoadbalancerAccessControlList struct {
|
||||
Name string
|
||||
Entrys []SLoadbalancerAccessControlListEntry
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cloudprovider
|
||||
|
||||
type SLoadbalancerBackend struct {
|
||||
Index int
|
||||
Weight int
|
||||
Port int
|
||||
ID string
|
||||
Name string
|
||||
ExternalID string
|
||||
BackendType string
|
||||
BackendRole string
|
||||
Address string
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cloudprovider
|
||||
|
||||
type SLoadbalancerListener struct {
|
||||
Name string
|
||||
LoadbalancerID string
|
||||
ListenerType string
|
||||
ListenerPort int
|
||||
BackendGroupID string
|
||||
Scheduler string
|
||||
AccessControlListStatus string
|
||||
AccessControlListType string
|
||||
AccessControlListID string
|
||||
EnableHTTP2 bool
|
||||
CertificateID string
|
||||
}
|
||||
@@ -66,6 +66,14 @@ type ICloudRegion interface {
|
||||
GetILoadbalancerAcls() ([]ICloudLoadbalancerAcl, error)
|
||||
GetILoadbalancerCertificates() ([]ICloudLoadbalancerCertificate, error)
|
||||
|
||||
GetILoadBalancerById(loadbalancerId string) (ICloudLoadbalancer, error)
|
||||
GetILoadBalancerAclById(aclId string) (ICloudLoadbalancerAcl, error)
|
||||
GetILoadBalancerCertificateById(certId string) (ICloudLoadbalancerCertificate, error)
|
||||
|
||||
CreateILoadBalancer(loadbalancer *SLoadbalancer) (ICloudLoadbalancer, error)
|
||||
CreateILoadBalancerAcl(acl *SLoadbalancerAccessControlList) (ICloudLoadbalancerAcl, error)
|
||||
CreateILoadBalancerCertificate(name string, privateKey, certificate string) (ICloudLoadbalancerCertificate, error)
|
||||
|
||||
GetProvider() string
|
||||
}
|
||||
|
||||
@@ -400,9 +408,16 @@ type ICloudLoadbalancer interface {
|
||||
GetNetworkId() string
|
||||
GetVpcId() string
|
||||
GetZoneId() string
|
||||
GetLoadbalancerSpec() string
|
||||
GetChargeType() string
|
||||
|
||||
Delete() error
|
||||
|
||||
GetILoadbalancerListeners() ([]ICloudLoadbalancerListener, error)
|
||||
GetILoadbalancerBackendGroups() ([]ICloudLoadbalancerBackendGroup, error)
|
||||
|
||||
CreateILoadBalancerBackendGroup(name string, groupType string, backends []SLoadbalancerBackend) (ICloudLoadbalancerBackendGroup, error)
|
||||
GetILoadbalancerBackendGroupById(groupId string) (ICloudLoadbalancerBackendGroup, error)
|
||||
}
|
||||
|
||||
type ICloudLoadbalancerListener interface {
|
||||
@@ -459,6 +474,11 @@ type ICloudLoadbalancerBackendGroup interface {
|
||||
IsDefault() bool
|
||||
GetType() string
|
||||
GetILoadbalancerBackends() ([]ICloudLoadbalancerBackend, error)
|
||||
AddBackendServer(serverId string, weight int, port int) (ICloudLoadbalancerBackend, error)
|
||||
RemoveBackendServer(serverId string) error
|
||||
|
||||
Delete() error
|
||||
Sync(name string) error
|
||||
}
|
||||
|
||||
type ICloudLoadbalancerBackend interface {
|
||||
@@ -474,6 +494,9 @@ type ICloudLoadbalancerBackend interface {
|
||||
type ICloudLoadbalancerCertificate interface {
|
||||
ICloudResource
|
||||
|
||||
Sync(name, privateKey, publickKey string) error
|
||||
Delete() error
|
||||
|
||||
GetCommonName() string
|
||||
GetSubjectAlternativeNames() string
|
||||
GetFingerprint() string // return value format: <algo>:<fingerprint>,比如sha1:7454a14fdb8ae1ea8b2f72e458a24a76bd23ec19
|
||||
@@ -495,4 +518,5 @@ type ICloudLoadbalancerAcl interface {
|
||||
// }
|
||||
// ]
|
||||
GetAclEntries() *jsonutils.JSONArray
|
||||
Delete() error
|
||||
}
|
||||
|
||||
@@ -45,6 +45,17 @@ const (
|
||||
|
||||
var (
|
||||
CLOUD_PROVIDER_VALID_STATUS = []string{CLOUD_PROVIDER_CONNECTED, CLOUD_PROVIDER_START_SYNC, CLOUD_PROVIDER_SYNCING}
|
||||
|
||||
CLOUD_PROVIDERS = []string{
|
||||
CLOUD_PROVIDER_KVM,
|
||||
CLOUD_PROVIDER_VMWARE,
|
||||
CLOUD_PROVIDER_ALIYUN,
|
||||
CLOUD_PROVIDER_QCLOUD,
|
||||
CLOUD_PROVIDER_AZURE,
|
||||
CLOUD_PROVIDER_AWS,
|
||||
CLOUD_PROVIDER_HUAWEI,
|
||||
CLOUD_PROVIDER_OPENSTACK,
|
||||
}
|
||||
)
|
||||
|
||||
type SCloudproviderManager struct {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
@@ -127,6 +128,17 @@ func (self *SCloudregion) GetVpcCount() int {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SCloudregion) GetDriver() IRegionDriver {
|
||||
provider := self.Provider
|
||||
if len(provider) == 0 {
|
||||
provider = CLOUD_PROVIDER_KVM
|
||||
}
|
||||
if !utils.IsInStringArray(provider, CLOUD_PROVIDERS) {
|
||||
log.Fatalf("Unsupported region provider %s", provider)
|
||||
}
|
||||
return GetRegionDriver(provider)
|
||||
}
|
||||
|
||||
func (self *SCloudregion) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict {
|
||||
extra.Add(jsonutils.NewInt(int64(self.GetVpcCount())), "vpc_count")
|
||||
extra.Add(jsonutils.NewInt(int64(self.GetZoneCount())), "zone_count")
|
||||
|
||||
@@ -26,7 +26,17 @@ const (
|
||||
LB_STATUS_ENABLED = "enabled"
|
||||
LB_STATUS_DISABLED = "disabled"
|
||||
|
||||
LB_STATUS_INIT = "init"
|
||||
LB_STATUS_INIT = "init"
|
||||
|
||||
LB_STATUS_CREATING = "creating"
|
||||
LB_STATUS_CREATE_FAILED = "create_failed"
|
||||
|
||||
LB_STATUS_SYNCING = "syncing"
|
||||
LB_STATUS_SYNCING_FAILED = "syncing_failed"
|
||||
|
||||
LB_STATUS_DELETING = "deleting"
|
||||
LB_STATUS_DELETE_FAILED = "delete_failed"
|
||||
|
||||
LB_STATUS_UNKNOWN = "unknown"
|
||||
LB_STATUS_RUNNING = "running"
|
||||
LB_STATUS_STOPPED = "stopped"
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -103,7 +105,7 @@ type SLoadbalancerAcl struct {
|
||||
db.SSharableVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"required"`
|
||||
AclEntries *SLoadbalancerAclEntries `list:"user" update:"user" create:"required"`
|
||||
}
|
||||
|
||||
@@ -125,7 +127,23 @@ func (man *SLoadbalancerAclManager) ValidateCreateData(ctx context.Context, user
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data)
|
||||
if _, err := man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
regionID, err := data.GetString("cloudregion_id")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewMissingParameterError("cloudregion_id")
|
||||
}
|
||||
_region, err := CloudregionManager.FetchByIdOrName(userCred, regionID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find cloudregion %s", regionID)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
data.Set("cloudregion_id", jsonutils.NewString(_region.GetId()))
|
||||
region := _region.(*SCloudregion)
|
||||
return region.GetDriver().ValidateCreateLoadbalancerAclData(ctx, userCred, data)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) AllowPerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
@@ -140,6 +158,44 @@ func (lbacl *SLoadbalancerAcl) ValidateUpdateData(ctx context.Context, userCred
|
||||
return lbacl.SSharableVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lbacl.SSharableVirtualResourceBase.PostCreate(ctx, userCred, ownerProjId, query, data)
|
||||
|
||||
lbacl.SetStatus(userCred, LB_STATUS_CREATING, "")
|
||||
if err := lbacl.StartLoadBalancerAclCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalanceracl error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) 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 err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) GetRegion() *SCloudregion {
|
||||
region, err := CloudregionManager.FetchById(lbacl.CloudregionId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return region.(*SCloudregion)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
provider, err := lbacl.GetDriver()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("No cloudprovide for lb %s: %s", lbacl.Name, err)
|
||||
}
|
||||
region := lbacl.GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("failed to find region for lb %s", lbacl.Name)
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) AllowPerformPatch(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) bool {
|
||||
return lbacl.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, lbacl, "patch")
|
||||
}
|
||||
@@ -214,8 +270,28 @@ func (lbacl *SLoadbalancerAcl) ValidateDeleteCondition(ctx context.Context) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
lbacl.DoPendingDelete(ctx, userCred)
|
||||
func (lbacl *SLoadbalancerAcl) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, lbacl, "purge")
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
parasm := jsonutils.NewDict()
|
||||
parasm.Add(jsonutils.JSONTrue, "purge")
|
||||
return nil, lbacl.StartLoadBalancerAclDeleteTask(ctx, userCred, parasm, "")
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbacl.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
return lbacl.StartLoadBalancerAclDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
|
||||
@@ -2,7 +2,10 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -11,8 +14,10 @@ import (
|
||||
|
||||
"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/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
@@ -70,14 +75,117 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data)
|
||||
if _, err := man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lb := lbV.Model.(*SLoadbalancer)
|
||||
backends := []cloudprovider.SLoadbalancerBackend{}
|
||||
for idx := 0; data.Contains(fmt.Sprintf("backend.%d", idx)); idx++ {
|
||||
_backend, _ := data.GetString(fmt.Sprintf("backend.%d", idx))
|
||||
backend := cloudprovider.SLoadbalancerBackend{BackendType: LB_BACKEND_GUEST, Index: idx, BackendRole: "default"}
|
||||
for _, info := range strings.Split(_backend, ",") {
|
||||
value := strings.Split(info, ":")
|
||||
if len(value) != 2 {
|
||||
return nil, httperrors.NewInputParameterError("Unknown backend info %s", info)
|
||||
}
|
||||
switch strings.ToLower(value[0]) {
|
||||
case "id", "name":
|
||||
backend.ID = value[1]
|
||||
case "backend_type", "backendtype", "type":
|
||||
backend.BackendType = value[1]
|
||||
case "weight":
|
||||
v, err := strconv.Atoi(value[1])
|
||||
if err != nil || v < 0 || v > 256 {
|
||||
return nil, httperrors.NewInputParameterError("weight %s not support, only support range 0 ~ 100")
|
||||
}
|
||||
backend.Weight = v
|
||||
case "port":
|
||||
v, err := strconv.Atoi(value[1])
|
||||
if err != nil || v < 1 || v > 65535 {
|
||||
return nil, httperrors.NewInputParameterError("port %s not support, only support range 1 ~ 65535")
|
||||
}
|
||||
backend.Port = v
|
||||
}
|
||||
}
|
||||
if len(backend.ID) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("Missing backend id or name params")
|
||||
}
|
||||
if backend.Port < 1 || backend.Port > 65535 {
|
||||
return nil, httperrors.NewInputParameterError("port %s not support, only support range 1 ~ 65535")
|
||||
}
|
||||
switch backend.BackendType {
|
||||
case LB_BACKEND_GUEST:
|
||||
_guest, err := GuestManager.FetchByIdOrName(userCred, backend.ID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find guest %s", backend.ID)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
guest := _guest.(*SGuest)
|
||||
host := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, fmt.Errorf("error getting host of guest %s", guest.Name)
|
||||
}
|
||||
if host.ZoneId != lb.ZoneId {
|
||||
return nil, fmt.Errorf("zone of host %q (%s) != zone of loadbalancer %q (%s)",
|
||||
host.Name, host.ZoneId, lb.Name, lb.ZoneId)
|
||||
}
|
||||
backend.ID = guest.Id
|
||||
backend.Name = guest.Name
|
||||
backend.ExternalID = guest.ExternalId
|
||||
address, err := LoadbalancerBackendManager.getGuestAddress(guest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
backend.Address = address
|
||||
case LB_BACKEND_HOST:
|
||||
if !db.IsAdminAllowCreate(userCred, man) {
|
||||
return nil, httperrors.NewForbiddenError("only sysadmin can specify host as backend")
|
||||
}
|
||||
_host, err := HostManager.FetchByIdOrName(userCred, backend.ID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find host %s", backend.ID)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
host := _host.(*SHost)
|
||||
backend.ID = host.Id
|
||||
backend.Name = host.Name
|
||||
backend.ExternalID = host.ExternalId
|
||||
backend.Address = host.AccessIp
|
||||
default:
|
||||
return nil, httperrors.NewInputParameterError("unexpected backend type %s", backend.BackendType)
|
||||
}
|
||||
backends = append(backends, backend)
|
||||
}
|
||||
data.Set("backends", jsonutils.Marshal(backends))
|
||||
return lb.GetRegion().GetDriver().ValidateCreateLoadbalancerBackendGroupData(ctx, userCred, data, backends)
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) GetLoadbalancer() *SLoadbalancer {
|
||||
lb, _ := LoadbalancerManager.FetchById(lbbg.LoadbalancerId)
|
||||
lb, err := LoadbalancerManager.FetchById(lbbg.LoadbalancerId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return lb.(*SLoadbalancer)
|
||||
}
|
||||
|
||||
func (llbg *SLoadbalancerBackendGroup) GetRegion() *SCloudregion {
|
||||
if loadbalancer := llbg.GetLoadbalancer(); loadbalancer != nil {
|
||||
return loadbalancer.GetRegion()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
if loadbalancer := lbbg.GetLoadbalancer(); loadbalancer != nil {
|
||||
return loadbalancer.GetIRegion()
|
||||
}
|
||||
return nil, fmt.Errorf("failed to find loadbalancer for backendgroup %s", lbbg.Name)
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) AllowPerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return false
|
||||
}
|
||||
@@ -123,12 +231,35 @@ func (lbbg *SLoadbalancerBackendGroup) GetExtraDetails(ctx context.Context, user
|
||||
return extra, nil
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
lbbg.DoPendingDelete(ctx, userCred)
|
||||
lbbg.PreDeleteSubs(ctx, userCred)
|
||||
func (lbbg *SLoadbalancerBackendGroup) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lbbg.SVirtualResourceBase.PostCreate(ctx, userCred, ownerProjId, query, data)
|
||||
params := jsonutils.NewDict()
|
||||
backends, _ := data.Get("backends")
|
||||
if backends != nil {
|
||||
params.Add(backends, "backends")
|
||||
}
|
||||
lbbg.SetStatus(userCred, LB_STATUS_CREATING, "")
|
||||
if err := lbbg.StartLoadBalancerBackendGroupCreateTask(ctx, userCred, params, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer backendgroup error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) StartLoadBalancerBackendGroupCreateTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerLoadbalancerBackendGroupCreateTask", lbbg, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (lbbg *SLoadbalancerBackendGroup) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
// lbbg.DoPendingDelete(ctx, userCred)
|
||||
// lbbg.PreDeleteSubs(ctx, userCred)
|
||||
// }
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) PreDeleteSubs(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
lbbg.DoCancelPendingDelete(ctx, userCred)
|
||||
subMan := LoadbalancerBackendManager
|
||||
ownerProjId := lbbg.GetOwnerProjectId()
|
||||
|
||||
@@ -138,6 +269,30 @@ func (lbbg *SLoadbalancerBackendGroup) PreDeleteSubs(ctx context.Context, userCr
|
||||
subMan.PreDeleteSubs(ctx, userCred, q)
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, lbbg, "purge")
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
parasm := jsonutils.NewDict()
|
||||
parasm.Add(jsonutils.JSONTrue, "purge")
|
||||
return nil, lbbg.StartLoadBalancerBackendGroupDeleteTask(ctx, userCred, parasm, "")
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbbg.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
return lbbg.StartLoadBalancerBackendGroupDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) StartLoadBalancerBackendGroupDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerBackendGroupDeleteTask", lbbg, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -154,6 +156,36 @@ func (lbb *SLoadbalancerBackend) AllowPerformStatus(ctx context.Context, userCre
|
||||
return false
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) GetLoadbalancerBackendGroup() *SLoadbalancerBackendGroup {
|
||||
backendgroup, err := LoadbalancerBackendGroupManager.FetchById(lbb.BackendGroupId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return backendgroup.(*SLoadbalancerBackendGroup)
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) GetGuest() *SGuest {
|
||||
guest, err := GuestManager.FetchById(lbb.BackendId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return guest.(*SGuest)
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) GetRegion() *SCloudregion {
|
||||
if backendgroup := lbb.GetLoadbalancerBackendGroup(); backendgroup != nil {
|
||||
return backendgroup.GetRegion()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
if backendgroup := lbb.GetLoadbalancerBackendGroup(); backendgroup != nil {
|
||||
return backendgroup.GetIRegion()
|
||||
}
|
||||
return nil, fmt.Errorf("failed to find backendgroup for backend %s", lbb.Name)
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerBackendManager) getGuestAddress(guest *SGuest) (string, error) {
|
||||
gns := guest.GetNetworks()
|
||||
if len(gns) == 0 {
|
||||
@@ -181,14 +213,55 @@ func (lbb *SLoadbalancerBackend) ValidateUpdateData(ctx context.Context, userCre
|
||||
return lbb.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
lbb.DoPendingDelete(ctx, userCred)
|
||||
func (lbb *SLoadbalancerBackend) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lbb.SVirtualResourceBase.PostCreate(ctx, userCred, ownerProjId, query, data)
|
||||
lbb.SetStatus(userCred, LB_STATUS_CREATING, "")
|
||||
if err := lbb.StartLoadBalancerBackendCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer backend error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) StartLoadBalancerBackendCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerLoadbalancerBackendCreateTask", lbb, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (lbb *SLoadbalancerBackend) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
// lbb.DoPendingDelete(ctx, userCred)
|
||||
// }
|
||||
|
||||
func (lbb *SLoadbalancerBackend) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, lbb, "purge")
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
parasm := jsonutils.NewDict()
|
||||
parasm.Add(jsonutils.JSONTrue, "purge")
|
||||
return nil, lbb.StartLoadBalancerBackendDeleteTask(ctx, userCred, parasm, "")
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbb.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
return lbb.StartLoadBalancerBackendDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) StartLoadBalancerBackendDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerBackendDeleteTask", lbb, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerBackendManager) getLoadbalancerBackendsByLoadbalancerBackendgroup(loadbalancerBackendgroup *SLoadbalancerBackendGroup) ([]SLoadbalancerBackend, error) {
|
||||
loadbalancerBackends := []SLoadbalancerBackend{}
|
||||
q := man.Query().Equals("backend_group_id", loadbalancerBackendgroup.Id)
|
||||
@@ -271,6 +344,7 @@ func (lbb *SLoadbalancerBackend) constructFieldsFromCloudLoadbalancerBackend(ext
|
||||
return err
|
||||
}
|
||||
guest := instance.(*SGuest)
|
||||
lbb.BackendId = guest.Id
|
||||
address, err := LoadbalancerBackendManager.getGuestAddress(guest)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"crypto/x509"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -125,7 +127,23 @@ func (man *SLoadbalancerCertificateManager) ValidateCreateData(ctx context.Conte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data)
|
||||
if _, err := man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
regionID, err := data.GetString("cloudregion_id")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewMissingParameterError("cloudregion_id")
|
||||
}
|
||||
_region, err := CloudregionManager.FetchByIdOrName(userCred, regionID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find cloudregion %s", regionID)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
data.Set("cloudregion_id", jsonutils.NewString(_region.GetId()))
|
||||
region := _region.(*SCloudregion)
|
||||
return region.GetDriver().ValidateCreateLoadbalancerCertificateData(ctx, userCred, data)
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerCertificateManager) InitializeData() error {
|
||||
@@ -180,7 +198,28 @@ func (lbcert *SLoadbalancerCertificate) ValidateUpdateData(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return lbcert.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
if _, err := lbcert.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return lbcert.GetRegion().GetDriver().ValidateUpdateLoadbalancerCertificateData(ctx, userCred, data)
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lbcert.SVirtualResourceBase.PostCreate(ctx, userCred, ownerProjId, query, data)
|
||||
|
||||
lbcert.SetStatus(userCred, LB_STATUS_CREATING, "")
|
||||
if err := lbcert.StartLoadBalancerCertificateCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancercertificate error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) 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 err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Context) error {
|
||||
@@ -203,11 +242,51 @@ func (lbcert *SLoadbalancerCertificate) ValidateDeleteCondition(ctx context.Cont
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
lbcert.DoPendingDelete(ctx, userCred)
|
||||
func (lbcert *SLoadbalancerCertificate) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
func (lbcert *SLoadbalancerCertificate) GetRegion() *SCloudregion {
|
||||
region, err := CloudregionManager.FetchById(lbcert.CloudregionId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return region.(*SCloudregion)
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
provider, err := lbcert.GetDriver()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("No cloudprovide for lbcert %s: %s", lbcert.Name, err)
|
||||
}
|
||||
region := lbcert.GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("failed to find region for lbcert %s", lbcert.Name)
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, lbcert, "purge")
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
parasm := jsonutils.NewDict()
|
||||
parasm.Add(jsonutils.JSONTrue, "purge")
|
||||
return nil, lbcert.StartLoadBalancerCertificateDeleteTask(ctx, userCred, parasm, "")
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbcert.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
return lbcert.StartLoadBalancerCertificateDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) StartLoadBalancerCertificateDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerCertificateDeleteTask", lbcert, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"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/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -394,12 +395,49 @@ func (lblis *SLoadbalancerListener) GetExtraDetails(ctx context.Context, userCre
|
||||
return extra, nil
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
lblis.SetStatus(userCred, LB_STATUS_DISABLED, "preDelete")
|
||||
lblis.DoPendingDelete(ctx, userCred)
|
||||
lblis.PreDeleteSubs(ctx, userCred)
|
||||
func (lblis *SLoadbalancerListener) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lblis.SVirtualResourceBase.PostCreate(ctx, userCred, ownerProjId, query, data)
|
||||
|
||||
lblis.SetStatus(userCred, LB_STATUS_CREATING, "")
|
||||
if err := lblis.StartLoadBalancerListenerCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer listener error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) StartLoadBalancerListenerCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerListenerCreateTask", lblis, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, lblis, "purge")
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
parasm := jsonutils.NewDict()
|
||||
parasm.Add(jsonutils.JSONTrue, "purge")
|
||||
return nil, lblis.StartLoadBalancerListenerDeleteTask(ctx, userCred, parasm, "")
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) StartLoadBalancerListenerDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerListenerDeleteTask", lblis, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (lblis *SLoadbalancerListener) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
// lblis.SetStatus(userCred, LB_STATUS_DISABLED, "preDelete")
|
||||
// lblis.DoPendingDelete(ctx, userCred)
|
||||
// lblis.PreDeleteSubs(ctx, userCred)
|
||||
// }
|
||||
|
||||
func (lblis *SLoadbalancerListener) PreDeleteSubs(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
subMan := LoadbalancerListenerRuleManager
|
||||
ownerProjId := lblis.GetOwnerProjectId()
|
||||
@@ -408,12 +446,28 @@ func (lblis *SLoadbalancerListener) PreDeleteSubs(ctx context.Context, userCred
|
||||
defer lockman.ReleaseClass(ctx, subMan, ownerProjId)
|
||||
q := subMan.Query().Equals("listener_id", lblis.Id)
|
||||
subMan.PreDeleteSubs(ctx, userCred, q)
|
||||
lblis.DoPendingDelete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) GetLoadbalancer() *SLoadbalancer {
|
||||
loadbalancer, err := LoadbalancerManager.FetchById(lblis.LoadbalancerId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return loadbalancer.(*SLoadbalancer)
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) GetRegion() *SCloudregion {
|
||||
if loadbalancer := lblis.GetLoadbalancer(); loadbalancer != nil {
|
||||
return loadbalancer.GetRegion()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerListenerManager) getLoadbalancerListenersByLoadbalancer(lb *SLoadbalancer) ([]SLoadbalancerListener, error) {
|
||||
listeners := []SLoadbalancerListener{}
|
||||
q := man.Query().Equals("loadbalancer_id", lb.Id)
|
||||
|
||||
@@ -51,10 +51,10 @@ func (ln *SLoadbalancerNetwork) Network() *SNetwork {
|
||||
}
|
||||
|
||||
type SLoadbalancerNetworkRequestData struct {
|
||||
loadbalancer *SLoadbalancer
|
||||
networkId string
|
||||
Loadbalancer *SLoadbalancer
|
||||
NetworkId string
|
||||
reserved bool // allocate from reserved
|
||||
address string // the address user intends to use
|
||||
Address string // the address user intends to use
|
||||
strategy IPAddlocationDirection // allocate bottom up, top down, randomly
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ func (m *SLoadbalancernetworkManager) NewLoadbalancerNetwork(ctx context.Context
|
||||
if networkMan == nil {
|
||||
return nil, fmt.Errorf("failed getting network manager")
|
||||
}
|
||||
im, err := networkMan.FetchById(req.networkId)
|
||||
im, err := networkMan.FetchById(req.NetworkId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
network := im.(*SNetwork)
|
||||
ln := &SLoadbalancerNetwork{
|
||||
LoadbalancerId: req.loadbalancer.Id,
|
||||
LoadbalancerId: req.Loadbalancer.Id,
|
||||
NetworkId: network.Id,
|
||||
}
|
||||
ln.SetModelManager(m)
|
||||
@@ -84,7 +84,7 @@ func (m *SLoadbalancernetworkManager) NewLoadbalancerNetwork(ctx context.Context
|
||||
usedMap := network.GetUsedAddresses()
|
||||
recentReclaimed := map[string]bool{}
|
||||
ipAddr, err := network.GetFreeIP(ctx, userCred,
|
||||
usedMap, recentReclaimed, req.address, req.strategy, req.reserved)
|
||||
usedMap, recentReclaimed, req.Address, req.strategy, req.reserved)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -125,32 +125,32 @@ func (m *SLoadbalancernetworkManager) DeleteLoadbalancerNetwork(ctx context.Cont
|
||||
}
|
||||
|
||||
func (m *SLoadbalancernetworkManager) SyncLoadbalancerNetwork(ctx context.Context, userCred mcclient.TokenCredential, req *SLoadbalancerNetworkRequestData) error {
|
||||
_network, err := NetworkManager.FetchById(req.networkId)
|
||||
_network, err := NetworkManager.FetchById(req.NetworkId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
network := _network.(*SNetwork)
|
||||
ip, err := netutils.NewIPV4Addr(req.address)
|
||||
ip, err := netutils.NewIPV4Addr(req.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !network.isAddressInRange(ip) {
|
||||
return fmt.Errorf("address %s is not in the range of network %s(%s)", req.address, network.Id, network.Name)
|
||||
return fmt.Errorf("address %s is not in the range of network %s(%s)", req.Address, network.Id, network.Name)
|
||||
}
|
||||
q := m.Query().Equals("loadbalancer_id", req.loadbalancer.Id).Equals("network_id", req.networkId)
|
||||
q := m.Query().Equals("loadbalancer_id", req.Loadbalancer.Id).Equals("network_id", req.NetworkId)
|
||||
lns := []SLoadbalancerNetwork{}
|
||||
if err := db.FetchModelObjects(m, q, &lns); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(lns) == 0 {
|
||||
ln := &SLoadbalancerNetwork{LoadbalancerId: req.loadbalancer.Id, NetworkId: req.networkId, IpAddr: req.address}
|
||||
ln := &SLoadbalancerNetwork{LoadbalancerId: req.Loadbalancer.Id, NetworkId: req.NetworkId, IpAddr: req.Address}
|
||||
return m.TableSpec().Insert(ln)
|
||||
}
|
||||
for i := 0; i < len(lns); i++ {
|
||||
if i == 0 {
|
||||
if lns[i].IpAddr != req.address {
|
||||
if lns[i].IpAddr != req.Address {
|
||||
_, err := lns[i].GetModelManager().TableSpec().Update(&lns[i], func() error {
|
||||
lns[i].IpAddr = req.address
|
||||
lns[i].IpAddr = req.Address
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"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/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -35,6 +36,11 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
LB_CHARGE_TYPE_BY_TRAFFIC = "traffic"
|
||||
LB_CHARGE_TYPE_BY_BANDWIDTH = "bandwidth"
|
||||
)
|
||||
|
||||
// TODO build errors on pkg/httperrors/errors.go
|
||||
// NewGetManagerError
|
||||
// NewMissingArgumentError
|
||||
@@ -49,15 +55,18 @@ type SLoadbalancer struct {
|
||||
db.SVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
|
||||
Address string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
AddressType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
NetworkType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
Address string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"optional"`
|
||||
AddressType string `width:"16" charset:"ascii" nullable:"false" default:"intranet" list:"user" create:"optional"`
|
||||
NetworkType string `width:"16" charset:"ascii" nullable:"false" default:"vpc" list:"user" create:"optional"`
|
||||
NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required"`
|
||||
VpcId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
ZoneId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
|
||||
BackendGroupId string `width:"36" charset:"ascii" nullable:"false" list:"user" update:"user" update:"user"`
|
||||
ChargeType string `list:"user" default:"traffic" create:"optional"`
|
||||
LoadbalancerSpec string `list:"user" create:"optional"`
|
||||
|
||||
BackendGroupId string `width:"36" charset:"ascii" nullable:"true" list:"user" update:"user" update:"user"`
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
|
||||
@@ -117,6 +126,14 @@ func (man *SLoadbalancerManager) ValidateCreateData(ctx context.Context, userCre
|
||||
if wire == nil {
|
||||
return nil, fmt.Errorf("getting wire failed")
|
||||
}
|
||||
vpc := wire.getVpc()
|
||||
if vpc == nil {
|
||||
return nil, fmt.Errorf("getting vpc failed")
|
||||
}
|
||||
data.Set("vpc_id", jsonutils.NewString(vpc.Id))
|
||||
if len(vpc.ManagerId) > 0 {
|
||||
data.Set("manager_id", jsonutils.NewString(vpc.ManagerId))
|
||||
}
|
||||
zone := wire.GetZone()
|
||||
if zone == nil {
|
||||
return nil, fmt.Errorf("getting zone failed")
|
||||
@@ -130,8 +147,11 @@ func (man *SLoadbalancerManager) ValidateCreateData(ctx context.Context, userCre
|
||||
// TODO validate network is of classic type
|
||||
data.Set("network_type", jsonutils.NewString(LB_NETWORK_TYPE_CLASSIC))
|
||||
data.Set("address_type", jsonutils.NewString(LB_ADDR_TYPE_INTRANET))
|
||||
if _, err := man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return region.GetDriver().ValidateCreateLoadbalancerData(ctx, userCred, data)
|
||||
}
|
||||
return man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) AllowPerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
@@ -143,26 +163,91 @@ func (lb *SLoadbalancer) PostCreate(ctx context.Context, userCred mcclient.Token
|
||||
// NOTE lb.Id will only be available after BeforeInsert happens
|
||||
// NOTE this means lb.UpdateVersion will be 0, then 1 after creation
|
||||
// NOTE need ways to notify error
|
||||
LoadbalancerManager.TableSpec().Update(lb, func() error {
|
||||
if lb.AddressType == LB_ADDR_TYPE_INTRANET {
|
||||
// TODO support use reserved ip address
|
||||
// TODO prefer ip address from server_type loadbalancer?
|
||||
req := &SLoadbalancerNetworkRequestData{
|
||||
loadbalancer: lb,
|
||||
networkId: lb.NetworkId,
|
||||
address: lb.Address,
|
||||
}
|
||||
// NOTE the small window when agents can see the ephemeral address
|
||||
ln, err := LoadbalancernetworkManager.NewLoadbalancerNetwork(ctx, userCred, req)
|
||||
if err != nil {
|
||||
log.Errorf("allocating loadbalancer network failed: %v, req: %#v", err, req)
|
||||
lb.Address = ""
|
||||
} else {
|
||||
lb.Address = ln.IpAddr
|
||||
}
|
||||
}
|
||||
|
||||
lb.SetStatus(userCred, LB_STATUS_CREATING, "")
|
||||
if err := lb.StartLoadBalancerCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetCloudprovider() *SCloudprovider {
|
||||
cloudprovider, err := CloudproviderManager.FetchById(lb.ManagerId)
|
||||
if err != nil {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return cloudprovider.(*SCloudprovider)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetRegion() *SCloudregion {
|
||||
region, err := CloudregionManager.FetchById(lb.CloudregionId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return region.(*SCloudregion)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetZone() *SZone {
|
||||
zone, err := ZoneManager.FetchById(lb.ZoneId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return zone.(*SZone)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetVpc() *SVpc {
|
||||
vpc, err := VpcManager.FetchById(lb.VpcId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return vpc.(*SVpc)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetNetwork() *SNetwork {
|
||||
network, err := NetworkManager.FetchById(lb.NetworkId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return network.(*SNetwork)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
provider, err := lb.GetDriver()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("No cloudprovide for lb %s: %s", lb.Name, err)
|
||||
}
|
||||
region := lb.GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("failed to find region for lb %s", lb.Name)
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, lb, "purge")
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
parasm := jsonutils.NewDict()
|
||||
parasm.Add(jsonutils.JSONTrue, "purge")
|
||||
return nil, lb.StartLoadBalancerDeleteTask(ctx, userCred, parasm, "")
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) StartLoadBalancerDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, params *jsonutils.JSONDict, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerDeleteTask", lb, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) StartLoadBalancerCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerCreateTask", lb, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
@@ -200,23 +285,17 @@ func (lb *SLoadbalancer) GetExtraDetails(ctx context.Context, userCred mcclient.
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
if len(lb.Address) > 0 {
|
||||
// TODO reserve support
|
||||
lb.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
return lb.StartLoadBalancerDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) PendingDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(lb.NetworkId) > 0 {
|
||||
req := &SLoadbalancerNetworkDeleteData{
|
||||
loadbalancer: lb,
|
||||
}
|
||||
err := LoadbalancernetworkManager.DeleteLoadbalancerNetwork(ctx, userCred, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lb.Address = ""
|
||||
LoadbalancernetworkManager.DeleteLoadbalancerNetwork(ctx, userCred, req)
|
||||
}
|
||||
// TODO How about mark pending delete and return
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) PreDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
lb.SetStatus(userCred, LB_STATUS_DISABLED, "preDelete")
|
||||
lb.DoPendingDelete(ctx, userCred)
|
||||
lb.PreDeleteSubs(ctx, userCred)
|
||||
}
|
||||
@@ -326,6 +405,8 @@ func (man *SLoadbalancerManager) newFromCloudLoadbalancer(ctx context.Context, u
|
||||
lb.NetworkType = extLb.GetNetworkType()
|
||||
lb.Name = extLb.GetName()
|
||||
lb.Status = extLb.GetStatus()
|
||||
lb.LoadbalancerSpec = extLb.GetLoadbalancerSpec()
|
||||
lb.ChargeType = extLb.GetChargeType()
|
||||
lb.ExternalId = extLb.GetGlobalId()
|
||||
if networkId := extLb.GetNetworkId(); len(networkId) > 0 {
|
||||
if network, err := NetworkManager.FetchByExternalId(networkId); err == nil && network != nil {
|
||||
@@ -359,9 +440,9 @@ func (man *SLoadbalancerManager) newFromCloudLoadbalancer(ctx context.Context, u
|
||||
func (lb *SLoadbalancer) syncLoadbalancerNetwork(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if len(lb.NetworkId) > 0 {
|
||||
lbNetReq := &SLoadbalancerNetworkRequestData{
|
||||
loadbalancer: lb,
|
||||
networkId: lb.NetworkId,
|
||||
address: lb.Address,
|
||||
Loadbalancer: lb,
|
||||
NetworkId: lb.NetworkId,
|
||||
Address: lb.Address,
|
||||
}
|
||||
err := LoadbalancernetworkManager.SyncLoadbalancerNetwork(ctx, userCred, lbNetReq)
|
||||
if err != nil {
|
||||
@@ -375,11 +456,9 @@ func (lb *SLoadbalancer) SyncWithCloudLoadbalancer(ctx context.Context, userCred
|
||||
lb.Address = extLb.GetAddress()
|
||||
lb.Status = extLb.GetStatus()
|
||||
lb.Name = extLb.GetName()
|
||||
if networkId := extLb.GetNetworkId(); len(networkId) > 0 {
|
||||
if network, err := NetworkManager.FetchByExternalId(networkId); err == nil && network != nil {
|
||||
lb.NetworkId = network.GetId()
|
||||
}
|
||||
}
|
||||
lb.LoadbalancerSpec = extLb.GetLoadbalancerSpec()
|
||||
lb.ChargeType = extLb.GetChargeType()
|
||||
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lb.ProjectId = projectId
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type IRegionDriver interface {
|
||||
GetProvider() string
|
||||
|
||||
ValidateCreateLoadbalancerData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error)
|
||||
RequestCreateLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *SLoadbalancer, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *SLoadbalancer, task taskman.ITask) error
|
||||
|
||||
ValidateCreateLoadbalancerAclData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, 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
|
||||
|
||||
ValidateCreateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error)
|
||||
ValidateUpdateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, 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
|
||||
|
||||
ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, backends []cloudprovider.SLoadbalancerBackend) (*jsonutils.JSONDict, error)
|
||||
RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *SLoadbalancerBackendGroup, backends []cloudprovider.SLoadbalancerBackend, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *SLoadbalancerBackendGroup, task taskman.ITask) error
|
||||
|
||||
RequestCreateLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *SLoadbalancerBackend, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *SLoadbalancerBackend, task taskman.ITask) error
|
||||
|
||||
RequestCreateLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *SLoadbalancerListener, task taskman.ITask) error
|
||||
RequestDeleteLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *SLoadbalancerListener, task taskman.ITask) error
|
||||
}
|
||||
|
||||
var regionDrivers map[string]IRegionDriver
|
||||
|
||||
func init() {
|
||||
regionDrivers = make(map[string]IRegionDriver)
|
||||
}
|
||||
|
||||
func RegisterRegionDriver(driver IRegionDriver) {
|
||||
regionDrivers[driver.GetProvider()] = driver
|
||||
}
|
||||
|
||||
func GetRegionDriver(provider string) IRegionDriver {
|
||||
driver, ok := regionDrivers[provider]
|
||||
if ok {
|
||||
return driver
|
||||
}
|
||||
log.Fatalf("Unsupported provider %s", provider)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
type SAliyunRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SAliyunRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SAliyunRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_ALIYUN
|
||||
}
|
||||
|
||||
func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
loadbalancerSpec, _ := data.GetString("loadbalancer_spec")
|
||||
if len(loadbalancerSpec) != 0 && !utils.IsInStringArray(loadbalancerSpec, []string{"slb.s1.small", "slb.s2.small", "slb.s2.mediu", "slb.s3.small", "slb.s3.mediu", "slb.s3.large"}) {
|
||||
return nil, httperrors.NewInputParameterError("Unsupport loadbalancer_spec %s, support slb.s1.small、slb.s2.small、slb.s2.medium、slb.s3.small、slb.s3.medium、slb.s3.large", loadbalancerSpec)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunRegionDriver) ValidateUpdateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
if data.Contains("certificate") || data.Contains("private_key") {
|
||||
return nil, httperrors.NewUnsupportOperationError("Aliyun not allow to change certificate")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, backends []cloudprovider.SLoadbalancerBackend) (*jsonutils.JSONDict, error) {
|
||||
groupType, _ := data.GetString("type")
|
||||
switch groupType {
|
||||
case "", models.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
break
|
||||
case models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
if len(backends) != 2 {
|
||||
return nil, httperrors.NewInputParameterError("master slave backendgorup must contain two backend")
|
||||
}
|
||||
default:
|
||||
return nil, httperrors.NewInputParameterError("Unsupport backendgorup type %s", groupType)
|
||||
}
|
||||
for _, backend := range backends {
|
||||
if len(backend.ExternalID) == 0 {
|
||||
return nil, httperrors.NewInputParameterError("invalid guest %s", backend.Name)
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type SAwsRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SAwsRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SAwsRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_AWS
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type SAzureRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SAzureRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SAzureRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_AZURE
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SBaseRegionDriver struct {
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestCreateLoadbalancer")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancer")
|
||||
}
|
||||
|
||||
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) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancerAcl")
|
||||
}
|
||||
|
||||
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.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancerCertificate")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, backends []cloudprovider.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestCreateLoadbalancerBackendGroup")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancerBackendGroup")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *models.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestCreateLoadbalancerBackend")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *models.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancerBackend")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestCreateLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestCreateLoadbalancerListener")
|
||||
}
|
||||
|
||||
func (self *SBaseRegionDriver) RequestDeleteLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
return fmt.Errorf("Not Implement RequestDeleteLoadbalancerListener")
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type SEsxiRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SEsxiRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SEsxiRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_VMWARE
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type SHuaWeiRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SHuaWeiRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SHuaWeiRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_HUAWEI
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SKVMRegionDriver struct {
|
||||
SBaseRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SKVMRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_KVM
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) ValidateCreateLoadbalancerData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) ValidateCreateLoadbalancerAclData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) ValidateCreateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) ValidateUpdateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, backends []cloudprovider.SLoadbalancerBackend) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
_, err := models.LoadbalancerManager.TableSpec().Update(lb, func() error {
|
||||
if lb.AddressType == models.LB_ADDR_TYPE_INTRANET {
|
||||
// TODO support use reserved ip address
|
||||
// TODO prefer ip address from server_type loadbalancer?
|
||||
req := &models.SLoadbalancerNetworkRequestData{
|
||||
Loadbalancer: lb,
|
||||
NetworkId: lb.NetworkId,
|
||||
Address: lb.Address,
|
||||
}
|
||||
// NOTE the small window when agents can see the ephemeral address
|
||||
ln, err := models.LoadbalancernetworkManager.NewLoadbalancerNetwork(ctx, userCred, req)
|
||||
if err != nil {
|
||||
log.Errorf("allocating loadbalancer network failed: %v, req: %#v", err, req)
|
||||
lb.Address = ""
|
||||
} else {
|
||||
lb.Address = ln.IpAddr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return nil, err
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, 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 {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerCertificate(ctx context.Context, userCred mcclient.TokenCredential, lbcert *models.SLoadbalancerCertificate, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, backends []cloudprovider.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
for _, backend := range backends {
|
||||
loadbalancerBackend := models.SLoadbalancerBackend{
|
||||
BackendGroupId: lbbg.Id,
|
||||
BackendId: backend.ID,
|
||||
BackendType: backend.BackendType,
|
||||
BackendRole: backend.BackendRole,
|
||||
Weight: backend.Weight,
|
||||
Address: backend.Address,
|
||||
Port: backend.Port,
|
||||
}
|
||||
loadbalancerBackend.Status = models.LB_STATUS_ENABLED
|
||||
loadbalancerBackend.ProjectId = userCred.GetProjectId()
|
||||
loadbalancerBackend.Name = fmt.Sprintf("%s-%s-%s", lbbg.Name, backend.BackendType, backend.Name)
|
||||
if err := models.LoadbalancerBackendManager.TableSpec().Insert(&loadbalancerBackend); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *models.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *models.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestCreateLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) RequestDeleteLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SManagedVirtualizationRegionDriver struct {
|
||||
SVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateCreateLoadbalancerData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateManagerId(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
managerID := jsonutils.GetAnyString(data, []string{"manager_id", "manager"})
|
||||
if len(managerID) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("manager_id")
|
||||
}
|
||||
provider, err := models.CloudproviderManager.FetchByIdOrName(userCred, managerID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find cloudprovider %s", managerID)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
data.Set("manager_id", jsonutils.NewString(provider.GetId()))
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateCreateLoadbalancerAclData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return self.ValidateManagerId(ctx, userCred, data)
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateCreateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateUpdateLoadbalancerCertificateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, backends []cloudprovider.SLoadbalancerBackend) (*jsonutils.JSONDict, error) {
|
||||
for _, backend := range backends {
|
||||
if len(backend.ExternalID) == 0 {
|
||||
return nil, httperrors.NewInputParameterError("invalid guest %s", backend.Name)
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
params := &cloudprovider.SLoadbalancer{
|
||||
Name: lb.Name,
|
||||
Address: lb.Address,
|
||||
AddressType: lb.AddressType,
|
||||
ChargeType: lb.ChargeType,
|
||||
LoadbalancerSpec: lb.LoadbalancerSpec,
|
||||
}
|
||||
iRegion, err := lb.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(lb.ZoneId) > 0 {
|
||||
zone := lb.GetZone()
|
||||
if zone == nil {
|
||||
return nil, fmt.Errorf("failed to find zone for lb %s", lb.Name)
|
||||
}
|
||||
iZone, err := iRegion.GetIZoneById(zone.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.ZoneID = iZone.GetId()
|
||||
}
|
||||
if len(lb.VpcId) > 0 {
|
||||
vpc := lb.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, fmt.Errorf("failed to find vpc for lb %s", lb.Name)
|
||||
}
|
||||
iVpc, err := iRegion.GetIVpcById(vpc.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.VpcID = iVpc.GetId()
|
||||
}
|
||||
if len(lb.NetworkId) > 0 {
|
||||
network := lb.GetNetwork()
|
||||
if network == nil {
|
||||
return nil, fmt.Errorf("failed to find network for lb %s", lb.Name)
|
||||
}
|
||||
iNetwork, err := network.GetINetwork()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.NetworkID = iNetwork.GetId()
|
||||
}
|
||||
iLoadbalancer, err := iRegion.CreateILoadBalancer(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := lb.SetExternalId(iLoadbalancer.GetGlobalId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := lb.SyncWithCloudLoadbalancer(ctx, userCred, iLoadbalancer, "", false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if lb.AddressType == models.LB_ADDR_TYPE_INTRANET {
|
||||
req := &models.SLoadbalancerNetworkRequestData{
|
||||
Loadbalancer: lb,
|
||||
NetworkId: lb.NetworkId,
|
||||
Address: lb.Address,
|
||||
}
|
||||
if _, err := models.LoadbalancernetworkManager.NewLoadbalancerNetwork(ctx, userCred, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
lbbgs, err := iLoadbalancer.GetILoadbalancerBackendGroups()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(lbbgs) > 0 {
|
||||
provider := lb.GetCloudprovider()
|
||||
if provider == nil {
|
||||
return nil, fmt.Errorf("failed to find cloudprovider for lb %s", lb.Name)
|
||||
}
|
||||
models.LoadbalancerBackendGroupManager.SyncLoadbalancerBackendgroups(ctx, userCred, provider, lb, lbbgs, &models.SSyncRange{})
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
}
|
||||
iRegion, err := lb.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancer, err := iRegion.GetILoadBalancerById(lb.ExternalId)
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, iLoadbalancer.Delete()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerAcl(ctx context.Context, userCred mcclient.TokenCredential, lbacl *models.SLoadbalancerAcl, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iRegion, err := lbacl.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
acl := &cloudprovider.SLoadbalancerAccessControlList{Name: lbacl.Name, Entrys: []cloudprovider.SLoadbalancerAccessControlListEntry{}}
|
||||
if lbacl.AclEntries != nil {
|
||||
for _, entry := range *lbacl.AclEntries {
|
||||
acl.Entrys = append(acl.Entrys, cloudprovider.SLoadbalancerAccessControlListEntry{CIDR: entry.Cidr, Comment: entry.Comment})
|
||||
}
|
||||
}
|
||||
iLoadbalancerAcl, err := iRegion.CreateILoadBalancerAcl(acl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := lbacl.SetExternalId(iLoadbalancerAcl.GetGlobalId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, lbacl.SyncWithCloudLoadbalancerAcl(ctx, userCred, iLoadbalancerAcl, "", false)
|
||||
})
|
||||
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) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
}
|
||||
iRegion, err := lbacl.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerAcl, err := iRegion.GetILoadBalancerAclById(lbacl.ExternalId)
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, iLoadbalancerAcl.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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerCert, err := iRegion.CreateILoadBalancerCertificate(lbcert.Name, lbcert.PrivateKey, lbcert.Certificate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := lbcert.SetExternalId(iLoadbalancerCert.GetGlobalId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, lbcert.SyncWithCloudLoadbalancerCertificate(ctx, userCred, iLoadbalancerCert, "", false)
|
||||
})
|
||||
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) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
}
|
||||
iRegion, err := lbcert.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerCert, err := iRegion.GetILoadBalancerCertificateById(lbcert.ExternalId)
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, iLoadbalancerCert.Delete()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, backends []cloudprovider.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
iRegion, err := lbbg.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loadbalancer := lbbg.GetLoadbalancer()
|
||||
if loadbalancer == nil {
|
||||
return nil, fmt.Errorf("failed to find loadbalancer for backendgroup %s", lbbg.Name)
|
||||
}
|
||||
iLoadbalancer, err := iRegion.GetILoadBalancerById(loadbalancer.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerBackendGroup, err := iLoadbalancer.CreateILoadBalancerBackendGroup(lbbg.Name, lbbg.Type, backends)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := lbbg.SetExternalId(iLoadbalancerBackendGroup.GetGlobalId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iBackends, err := iLoadbalancerBackendGroup.GetILoadbalancerBackends()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(iBackends) > 0 {
|
||||
provider := loadbalancer.GetCloudprovider()
|
||||
if provider == nil {
|
||||
return nil, fmt.Errorf("failed to find cloudprovider for lb %s", loadbalancer.Name)
|
||||
}
|
||||
models.LoadbalancerBackendManager.SyncLoadbalancerBackends(ctx, userCred, provider, lbbg, iBackends, &models.SSyncRange{})
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerBackendGroup(ctx context.Context, userCred mcclient.TokenCredential, lbbg *models.SLoadbalancerBackendGroup, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
}
|
||||
iRegion, err := lbbg.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loadbalancer := lbbg.GetLoadbalancer()
|
||||
if loadbalancer == nil {
|
||||
return nil, fmt.Errorf("failed to find loadbalancer for backendgroup %s", lbbg.Name)
|
||||
}
|
||||
iLoadbalancer, err := iRegion.GetILoadBalancerById(loadbalancer.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerBackendGroup, err := iLoadbalancer.GetILoadbalancerBackendGroupById(lbbg.ExternalId)
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNotFound {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, iLoadbalancerBackendGroup.Delete()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *models.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
lbbg := lbb.GetLoadbalancerBackendGroup()
|
||||
if lbbg == nil {
|
||||
return nil, fmt.Errorf("failed to find lbbg for backend %s", lbb.Name)
|
||||
}
|
||||
lb := lbbg.GetLoadbalancer()
|
||||
if lb == nil {
|
||||
return nil, fmt.Errorf("failed to find lb for backendgroup %s", lbbg.Name)
|
||||
}
|
||||
iRegion, err := lb.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancer, err := iRegion.GetILoadBalancerById(lb.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerBackendGroup, err := iLoadbalancer.GetILoadbalancerBackendGroupById(lbbg.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
guest := lbb.GetGuest()
|
||||
if guest == nil {
|
||||
return nil, fmt.Errorf("failed to find guest for lbb %s", lbb.Name)
|
||||
}
|
||||
iLoadbalancerBackend, err := iLoadbalancerBackendGroup.AddBackendServer(guest.ExternalId, lbb.Weight, lbb.Port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, lbb.SyncWithCloudLoadbalancerBackend(ctx, userCred, iLoadbalancerBackend, "", false)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, lbb *models.SLoadbalancerBackend, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
}
|
||||
lbbg := lbb.GetLoadbalancerBackendGroup()
|
||||
if lbbg == nil {
|
||||
return nil, fmt.Errorf("failed to find lbbg for backend %s", lbb.Name)
|
||||
}
|
||||
lb := lbbg.GetLoadbalancer()
|
||||
if lb == nil {
|
||||
return nil, fmt.Errorf("failed to find lb for backendgroup %s", lbbg.Name)
|
||||
}
|
||||
iRegion, err := lb.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancer, err := iRegion.GetILoadBalancerById(lb.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancerBackendGroup, err := iLoadbalancer.GetILoadbalancerBackendGroupById(lbbg.ExternalId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
guest := lbb.GetGuest()
|
||||
if guest == nil {
|
||||
return nil, fmt.Errorf("failed to find guest for lbb %s", lbb.Name)
|
||||
}
|
||||
return nil, iLoadbalancerBackendGroup.RemoveBackendServer(guest.ExternalId)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestCreateLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) RequestDeleteLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
if jsonutils.QueryBoolean(task.GetParams(), "purge", false) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type SOpenStackRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SOpenStackRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SOpenStackRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_OPENSTACK
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package regiondrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type SQcloudRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SQcloudRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SQcloudRegionDriver) GetProvider() string {
|
||||
return models.CLOUD_PROVIDER_QCLOUD
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package regiondrivers
|
||||
|
||||
type SVirtualizationRegionDriver struct {
|
||||
SBaseRegionDriver
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
_ "yunion.io/x/onecloud/pkg/compute/guestdrivers"
|
||||
_ "yunion.io/x/onecloud/pkg/compute/hostdrivers"
|
||||
_ "yunion.io/x/onecloud/pkg/compute/regiondrivers"
|
||||
_ "yunion.io/x/onecloud/pkg/compute/tasks"
|
||||
_ "yunion.io/x/onecloud/pkg/util/aliyun/provider"
|
||||
_ "yunion.io/x/onecloud/pkg/util/aws/provider"
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerBackendCreateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerBackendCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendCreateTask) taskFail(ctx context.Context, lbb *models.SLoadbalancerBackend, reason string) {
|
||||
lbb.SetStatus(self.GetUserCred(), models.LB_STATUS_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbb := obj.(*models.SLoadbalancerBackend)
|
||||
region := lbb.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbb, fmt.Sprintf("failed to find region for lbb %s", lbb.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerBackendCreateComplete", nil)
|
||||
if err := region.GetDriver().RequestCreateLoadbalancerBackend(ctx, self.GetUserCred(), lbb, self); err != nil {
|
||||
self.taskFail(ctx, lbb, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendCreateTask) OnLoadbalancerBackendCreateComplete(ctx context.Context, lbb *models.SLoadbalancerBackend, data jsonutils.JSONObject) {
|
||||
lbb.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendCreateTask) OnLoadbalancerBackendCreateCompleteFailed(ctx context.Context, lbb *models.SLoadbalancerBackend, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbb, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerBackendDeleteTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerBackendDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendDeleteTask) taskFail(ctx context.Context, lbb *models.SLoadbalancerBackend, reason string) {
|
||||
lbb.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbb := obj.(*models.SLoadbalancerBackend)
|
||||
region := lbb.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbb, fmt.Sprintf("failed to find region for lbb %s", lbb.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerBackendDeleteComplete", nil)
|
||||
if err := region.GetDriver().RequestDeleteLoadbalancerBackend(ctx, self.GetUserCred(), lbb, self); err != nil {
|
||||
self.taskFail(ctx, lbb, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendDeleteTask) OnLoadbalancerBackendDeleteComplete(ctx context.Context, lbb *models.SLoadbalancerBackend, data jsonutils.JSONObject) {
|
||||
lbb.DoPendingDelete(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendDeleteTask) OnLoadbalancerBackendDeleteCompleteFailed(ctx context.Context, lbb *models.SLoadbalancerBackend, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbb, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerLoadbalancerBackendGroupCreateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerLoadbalancerBackendGroupCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerBackendGroup, reason string) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_STATUS_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbbg := obj.(*models.SLoadbalancerBackendGroup)
|
||||
region := lbbg.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbbg, fmt.Sprintf("failed to find region for lb backendgroup %s", lbbg.Name))
|
||||
return
|
||||
}
|
||||
backends := []cloudprovider.SLoadbalancerBackend{}
|
||||
self.GetParams().Unmarshal(&backends, "backends")
|
||||
self.SetStage("OnLoadbalancerBackendGroupCreateComplete", nil)
|
||||
if err := region.GetDriver().RequestCreateLoadbalancerBackendGroup(ctx, self.GetUserCred(), lbbg, backends, self); err != nil {
|
||||
self.taskFail(ctx, lbbg, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) OnLoadbalancerBackendGroupCreateComplete(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup, data jsonutils.JSONObject) {
|
||||
lbbg.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) OnLoadbalancerBackendGroupCreateCompleteFailed(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbbg, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerBackendGroupDeleteTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerBackendGroupDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendGroupDeleteTask) taskFail(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup, reason string) {
|
||||
lbbg.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendGroupDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbbg := obj.(*models.SLoadbalancerBackendGroup)
|
||||
region := lbbg.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbbg, fmt.Sprintf("failed to find region for lb %s", lbbg.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerBackendGroupDeleteComplete", nil)
|
||||
if err := region.GetDriver().RequestDeleteLoadbalancerBackendGroup(ctx, self.GetUserCred(), lbbg, self); err != nil {
|
||||
self.taskFail(ctx, lbbg, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendGroupDeleteTask) OnLoadbalancerBackendGroupDeleteComplete(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup, data jsonutils.JSONObject) {
|
||||
lbbg.PreDeleteSubs(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendGroupDeleteTask) OnLoadbalancerBackendGroupDeleteCompleteFailed(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbbg, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerCreateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason string) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lb := obj.(*models.SLoadbalancer)
|
||||
region := lb.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lb, fmt.Sprintf("failed to find region for lb %s", lb.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerCreateComplete", nil)
|
||||
if err := region.GetDriver().RequestCreateLoadbalancer(ctx, self.GetUserCred(), lb, self); err != nil {
|
||||
self.taskFail(ctx, lb, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) OnLoadbalancerCreateComplete(ctx context.Context, lb *models.SLoadbalancer, data jsonutils.JSONObject) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) OnLoadbalancerCreateCompleteFailed(ctx context.Context, lb *models.SLoadbalancer, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lb, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerDeleteTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerDeleteTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason string) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lb := obj.(*models.SLoadbalancer)
|
||||
region := lb.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lb, fmt.Sprintf("failed to find region for lb %s", lb.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerDeleteComplete", nil)
|
||||
if err := region.GetDriver().RequestDeleteLoadbalancer(ctx, self.GetUserCred(), lb, self); err != nil {
|
||||
self.taskFail(ctx, lb, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerDeleteTask) OnLoadbalancerDeleteComplete(ctx context.Context, lb *models.SLoadbalancer, data jsonutils.JSONObject) {
|
||||
lb.PendingDelete(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerDeleteTask) OnLoadbalancerDeleteCompleteFailed(ctx context.Context, lb *models.SLoadbalancer, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lb, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerListenerCreateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerListenerCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lblis := obj.(*models.SLoadbalancerListener)
|
||||
region := lblis.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lblis, fmt.Sprintf("failed to find region for lblis %s", lblis.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerListenerCreateComplete", nil)
|
||||
if err := region.GetDriver().RequestCreateLoadbalancerListener(ctx, self.GetUserCred(), lblis, self); err != nil {
|
||||
self.taskFail(ctx, lblis, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) OnLoadbalancerListenerCreateComplete(ctx context.Context, lblis *models.SLoadbalancerListener, data jsonutils.JSONObject) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) OnLoadbalancerListenerCreateCompleteFailed(ctx context.Context, lblis *models.SLoadbalancerListener, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lblis, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerListenerDeleteTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerListenerDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerDeleteTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lblis := obj.(*models.SLoadbalancerListener)
|
||||
region := lblis.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lblis, fmt.Sprintf("failed to find region for lblis %s", lblis.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerListenerDeleteComplete", nil)
|
||||
if err := region.GetDriver().RequestDeleteLoadbalancerListener(ctx, self.GetUserCred(), lblis, self); err != nil {
|
||||
self.taskFail(ctx, lblis, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerDeleteTask) OnLoadbalancerListenerDeleteComplete(ctx context.Context, lblis *models.SLoadbalancerListener, data jsonutils.JSONObject) {
|
||||
lblis.PreDeleteSubs(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerDeleteTask) OnLoadbalancerListenerDeleteCompleteFailed(ctx context.Context, lblis *models.SLoadbalancerListener, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lblis, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerAclCreateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerAclCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason string) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_STATUS_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbacl := obj.(*models.SLoadbalancerAcl)
|
||||
region := lbacl.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbacl, fmt.Sprintf("failed to find region for lbacl %s", lbacl.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerAclCreateComplete", nil)
|
||||
if err := region.GetDriver().RequestCreateLoadbalancerAcl(ctx, self.GetUserCred(), lbacl, self); err != nil {
|
||||
self.taskFail(ctx, lbacl, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) OnLoadbalancerAclCreateComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) OnLoadbalancerAclCreateCompleteFailed(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbacl, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerAclDeleteTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerAclDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason string) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbacl := obj.(*models.SLoadbalancerAcl)
|
||||
region := lbacl.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbacl, fmt.Sprintf("failed to find region for lbacl %s", lbacl.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerAclDeleteComplete", nil)
|
||||
if err := region.GetDriver().RequestDeleteLoadbalancerAcl(ctx, self.GetUserCred(), lbacl, self); err != nil {
|
||||
self.taskFail(ctx, lbacl, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) OnLoadbalancerAclDeleteComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.DoPendingDelete(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) OnLoadbalancerAclDeleteCompleteFailed(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbacl, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerCertificateCreateTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerCertificateCreateTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) taskFail(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason string) {
|
||||
lbcert.SetStatus(self.GetUserCred(), models.LB_STATUS_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbcert := obj.(*models.SLoadbalancerCertificate)
|
||||
region := lbcert.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbcert, fmt.Sprintf("failed to find region for lbcert %s", lbcert.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerCertificateCreateComplete", nil)
|
||||
if err := region.GetDriver().RequestCreateLoadbalancerCertificate(ctx, self.GetUserCred(), lbcert, self); err != nil {
|
||||
self.taskFail(ctx, lbcert, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) OnLoadbalancerCertificateCreateComplete(ctx context.Context, lbcert *models.SLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
lbcert.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) OnLoadbalancerCertificateCreateCompleteFailed(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbcert, reason.String())
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type LoadbalancerCertificateDeleteTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(LoadbalancerCertificateDeleteTask{})
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) taskFail(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason string) {
|
||||
lbcert.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
lbcert := obj.(*models.SLoadbalancerCertificate)
|
||||
region := lbcert.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, lbcert, fmt.Sprintf("failed to find region for lbcert %s", lbcert.Name))
|
||||
return
|
||||
}
|
||||
self.SetStage("OnLoadbalancerCertificateDeleteComplete", nil)
|
||||
if err := region.GetDriver().RequestDeleteLoadbalancerCertificate(ctx, self.GetUserCred(), lbcert, self); err != nil {
|
||||
self.taskFail(ctx, lbcert, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnLoadbalancerCertificateDeleteComplete(ctx context.Context, lbcert *models.SLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
lbcert.DoPendingDelete(ctx, self.GetUserCred())
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) OnLoadbalancerCertificateDeleteCompleteFailed(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason jsonutils.JSONObject) {
|
||||
self.taskFail(ctx, lbcert, reason.String())
|
||||
}
|
||||
@@ -15,8 +15,10 @@ type Loadbalancer struct {
|
||||
VpcId string
|
||||
ZoneId string
|
||||
|
||||
BackendGroupId string
|
||||
CloudregionId string
|
||||
BackendGroupId string
|
||||
CloudregionId string
|
||||
ChargeType string
|
||||
LoadbalancerSpec string
|
||||
}
|
||||
|
||||
type LoadbalancerTCPListener struct{}
|
||||
|
||||
@@ -58,6 +58,8 @@ func (entries AclEntries) String() string {
|
||||
type LoadbalancerAclCreateOptions struct {
|
||||
NAME string
|
||||
AclEntry []string `help:"acl entry with cidr and comment separated by #, e.g. 10.9.0.0/16#no comment" json:"-"`
|
||||
Provider string `json:"manager_id"`
|
||||
REGION string `json:"cloudregion_id"`
|
||||
}
|
||||
|
||||
type LoadbalancerAclGetOptions struct {
|
||||
|
||||
@@ -2,7 +2,9 @@ package options
|
||||
|
||||
type LoadbalancerBackendGroupCreateOptions struct {
|
||||
NAME string
|
||||
Loadbalancer string
|
||||
LOADBALANCER string
|
||||
Type string `choices:"default|normal|master_slave"`
|
||||
Backend []string
|
||||
}
|
||||
|
||||
type LoadbalancerBackendGroupGetOptions struct {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package options
|
||||
|
||||
type LoadbalancerCreateOptions struct {
|
||||
NAME string
|
||||
Network string
|
||||
Address string
|
||||
NAME string
|
||||
Network string
|
||||
Address string
|
||||
LoadbalancerSpec string `choices:"slb.s1.small|slb.s2.small|slb.s2.medium|slb.s3.small|slb.s3.medium|slb.s3.large"`
|
||||
ChargeType string `choices:"traffic|bandwidth"`
|
||||
}
|
||||
|
||||
type LoadbalancerGetOptions struct {
|
||||
@@ -21,6 +23,10 @@ type LoadbalancerDeleteOptions struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
type LoadbalancerPurgeOptions struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
type LoadbalancerListOptions struct {
|
||||
BaseListOptions
|
||||
Zone string
|
||||
|
||||
@@ -59,7 +59,7 @@ type SLoadbalancer struct {
|
||||
InternetChargeType string //公网实例的计费方式。取值:paybybandwidth:按带宽计费 paybytraffic:按流量计费(默认值) 说明 当 PayType参数的值为PrePay时,只支持按带宽计费。
|
||||
PayType string //实例的计费类型,取值:PayOnDemand:按量付费 PrePay:预付费
|
||||
ResourceGroupId string //企业资源组ID。
|
||||
|
||||
LoadBalancerSpec string //负载均衡实例的的性能规格
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetName() string {
|
||||
@@ -152,6 +152,14 @@ func (region *SRegion) GetLoadbalancerDetail(loadbalancerId string) (*SLoadbalan
|
||||
return &lb, body.Unmarshal(&lb)
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) Delete() error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = lb.region.RegionId
|
||||
params["LoadBalancerId"] = lb.LoadBalancerId
|
||||
_, err := lb.region.lbRequest("DeleteLoadBalancer", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetILoadbalancerBackendGroups() ([]cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
ibackendgroups := []cloudprovider.ICloudLoadbalancerBackendGroup{}
|
||||
{
|
||||
@@ -183,6 +191,57 @@ func (lb *SLoadbalancer) GetILoadbalancerBackendGroups() ([]cloudprovider.ICloud
|
||||
return ibackendgroups, nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) CreateILoadBalancerBackendGroup(name string, groupType string, backends []cloudprovider.SLoadbalancerBackend) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
switch groupType {
|
||||
case models.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
group, err := lb.region.CreateLoadbalancerBackendGroup(name, lb.LoadBalancerId, backends)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group.lb = lb
|
||||
return group, nil
|
||||
case models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
group, err := lb.region.CreateLoadbalancerMasterSlaveBackendGroup(name, lb.LoadBalancerId, backends)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group.lb = lb
|
||||
return group, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("Unsupport backendgroup type %s", groupType)
|
||||
}
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetLoadbalancerSpec() string {
|
||||
if len(lb.LoadBalancerSpec) == 0 {
|
||||
lb.Refresh()
|
||||
}
|
||||
return lb.LoadBalancerSpec
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetChargeType() string {
|
||||
switch lb.InternetChargeType {
|
||||
case "paybybandwidth":
|
||||
return "bandwidth"
|
||||
case "paybytraffic":
|
||||
return "traffic"
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetILoadbalancerBackendGroupById(groupId string) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
groups, err := lb.GetILoadbalancerBackendGroups()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(groups); i++ {
|
||||
if groups[i].GetGlobalId() == groupId {
|
||||
return groups[i], nil
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetILoadbalancerListeners() ([]cloudprovider.ICloudLoadbalancerListener, error) {
|
||||
loadbalancer, err := lb.region.GetLoadbalancerDetail(lb.LoadBalancerId)
|
||||
if err != nil {
|
||||
|
||||
@@ -68,6 +68,32 @@ func (acl *SLoadbalancerAcl) GetAclEntries() *jsonutils.JSONArray {
|
||||
return result
|
||||
}
|
||||
|
||||
func (region *SRegion) UpdateAclName(aclId, name string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["AclId"] = aclId
|
||||
params["AclName"] = name
|
||||
_, err := region.lbRequest("SetAccessControlListAttribute", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (region *SRegion) RemoveAccessControlListEntry(aclId string, data jsonutils.JSONObject) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["AclId"] = aclId
|
||||
params["AclEntrys"] = data.String()
|
||||
_, err := region.lbRequest("RemoveAccessControlListEntry", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) Delete() error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = acl.region.RegionId
|
||||
params["AclId"] = acl.AclId
|
||||
_, err := acl.region.lbRequest("DeleteAccessControlList", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (region *SRegion) GetLoadbalancerAclDetail(aclId string) (*SLoadbalancerAcl, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
@@ -108,3 +110,106 @@ func (backendgroup *SLoadbalancerBackendGroup) GetILoadbalancerBackends() ([]clo
|
||||
}
|
||||
return ibackends, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateLoadbalancerBackendGroup(name, loadbalancerId string, backends []cloudprovider.SLoadbalancerBackend) (*SLoadbalancerBackendGroup, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["VServerGroupName"] = name
|
||||
params["LoadBalancerId"] = loadbalancerId
|
||||
if len(backends) > 0 {
|
||||
servers := jsonutils.NewArray()
|
||||
for _, backend := range backends {
|
||||
servers.Add(
|
||||
jsonutils.Marshal(
|
||||
map[string]string{
|
||||
"ServerId": backend.ExternalID,
|
||||
"Port": fmt.Sprintf("%d", backend.Port),
|
||||
"Weight": fmt.Sprintf("%d", backend.Weight),
|
||||
},
|
||||
))
|
||||
}
|
||||
params["BackendServers"] = servers.String()
|
||||
}
|
||||
body, err := region.lbRequest("CreateVServerGroup", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupId, err := body.GetString("VServerGroupId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return region.GetLoadbalancerBackendgroupById(groupId)
|
||||
}
|
||||
|
||||
func (region *SRegion) GetLoadbalancerBackendgroupById(groupId string) (*SLoadbalancerBackendGroup, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["VServerGroupId"] = groupId
|
||||
body, err := region.lbRequest("DescribeVServerGroupAttribute", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group := &SLoadbalancerBackendGroup{}
|
||||
return group, body.Unmarshal(group)
|
||||
}
|
||||
|
||||
func (region *SRegion) UpdateLoadBalancerBackendGroupName(name, groupId string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["VServerGroupId"] = groupId
|
||||
params["VServerGroupName"] = name
|
||||
_, err := region.lbRequest("SetVServerGroupAttribute", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) Sync(name string) error {
|
||||
if backendgroup.VServerGroupName != name {
|
||||
return backendgroup.lb.region.UpdateLoadBalancerBackendGroupName(backendgroup.VServerGroupId, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteLoadBalancerBackendGroup(groupId string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["VServerGroupId"] = groupId
|
||||
_, err := region.lbRequest("DeleteVServerGroup", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) Delete() error {
|
||||
return backendgroup.lb.region.DeleteLoadBalancerBackendGroup(backendgroup.VServerGroupId)
|
||||
}
|
||||
|
||||
func (region *SRegion) AddBackendVServer(loadbalancerId, serverId string, weight, port int) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["LoadBalancerId"] = loadbalancerId
|
||||
servers := jsonutils.NewArray()
|
||||
servers.Add(jsonutils.Marshal(map[string]string{"ServerId": serverId, "Weight": fmt.Sprintf("%d", weight*100/256), "Port": fmt.Sprintf("%d", port)}))
|
||||
params["BackendServers"] = servers.String()
|
||||
_, err := region.lbRequest("AddVServerGroupBackendServers", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (region *SRegion) RemoveBackendVServer(loadbalancerId, serverId string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["LoadBalancerId"] = loadbalancerId
|
||||
servers := jsonutils.NewArray()
|
||||
servers.Add(jsonutils.NewString(serverId))
|
||||
params["BackendServers"] = servers.String()
|
||||
_, err := region.lbRequest("RemoveVServerGroupBackendServers", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) AddBackendServer(serverId string, weight, port int) (cloudprovider.ICloudLoadbalancerBackend, error) {
|
||||
if err := backendgroup.lb.region.AddBackendVServer(backendgroup.lb.LoadBalancerId, serverId, weight, port); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SLoadbalancerBackend{lbbg: backendgroup, ServerId: serverId, Weight: weight, Port: port}, nil
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) RemoveBackendServer(serverId string) error {
|
||||
return backendgroup.lb.region.RemoveBackendVServer(backendgroup.lb.LoadBalancerId, serverId)
|
||||
}
|
||||
|
||||
@@ -60,3 +60,44 @@ func (backendgroup *SLoadbalancerDefaultBackendGroup) GetILoadbalancerBackends()
|
||||
}
|
||||
return ibackends, nil
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) Sync(name string) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) Delete() error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (region *SRegion) AddBackendServer(loadbalancerId, serverId string, weight, port int) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["LoadBalancerId"] = loadbalancerId
|
||||
servers := jsonutils.NewArray()
|
||||
servers.Add(jsonutils.Marshal(map[string]string{"ServerId": serverId, "Weight": fmt.Sprintf("%d", weight*100/256)}))
|
||||
params["BackendServers"] = servers.String()
|
||||
_, err := region.lbRequest("AddBackendServers", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) AddBackendServer(serverId string, weight, port int) (cloudprovider.ICloudLoadbalancerBackend, error) {
|
||||
if err := backendgroup.lb.region.AddBackendServer(backendgroup.lb.LoadBalancerId, serverId, weight, port); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SLoadbalancerDefaultBackend{lbbg: backendgroup, ServerId: serverId}, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) RemoveBackendServer(loadbalancerId, serverId string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["LoadBalancerId"] = loadbalancerId
|
||||
servers := jsonutils.NewArray()
|
||||
servers.Add(jsonutils.NewString(serverId))
|
||||
params["BackendServers"] = servers.String()
|
||||
_, err := region.lbRequest("RemoveBackendServers", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) RemoveBackendServer(serverId string) error {
|
||||
return backendgroup.lb.region.RemoveBackendServer(backendgroup.lb.LoadBalancerId, serverId)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
@@ -85,3 +87,86 @@ func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) GetILoadbalancerBacken
|
||||
}
|
||||
return ibackends, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateLoadbalancerMasterSlaveBackendGroup(name, loadbalancerId string, backends []cloudprovider.SLoadbalancerBackend) (*SLoadbalancerMasterSlaveBackendGroup, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["MasterSlaveServerGroupName"] = name
|
||||
params["LoadBalancerId"] = loadbalancerId
|
||||
if len(backends) != 2 {
|
||||
return nil, fmt.Errorf("master slave backendgorup must contain two backend")
|
||||
}
|
||||
servers := jsonutils.NewArray()
|
||||
for _, backend := range backends {
|
||||
serverType := "Slave"
|
||||
if backend.Index == 0 {
|
||||
serverType = "Master"
|
||||
}
|
||||
servers.Add(
|
||||
jsonutils.Marshal(
|
||||
map[string]string{
|
||||
"ServerId": backend.ExternalID,
|
||||
"Port": fmt.Sprintf("%d", backend.Port),
|
||||
"Weight": fmt.Sprintf("%d", backend.Weight),
|
||||
"ServerType": serverType,
|
||||
},
|
||||
))
|
||||
}
|
||||
body, err := region.lbRequest("CreateMasterSlaveVServerGroup", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupId, err := body.GetString("MasterSlaveServerGroupId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return region.GetLoadbalancerMasterSlaveBackendgroupById(groupId)
|
||||
}
|
||||
|
||||
func (region *SRegion) GetLoadbalancerMasterSlaveBackendgroupById(groupId string) (*SLoadbalancerMasterSlaveBackendGroup, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["MasterSlaveServerGroupId"] = groupId
|
||||
body, err := region.lbRequest("DescribeMasterSlaveVServerGroupAttribute", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group := &SLoadbalancerMasterSlaveBackendGroup{}
|
||||
return group, body.Unmarshal(group)
|
||||
}
|
||||
|
||||
func (region *SRegion) UpdateLoadbalancerMasterSlaveBackendgroupName(name, groupId string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["MasterSlaveServerGroupId"] = groupId
|
||||
params["MasterSlaveServerGroupName"] = name
|
||||
_, err := region.lbRequest("SetMasterSlaveVServerGroupAttribute", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) Sync(name string) error {
|
||||
if backendgroup.MasterSlaveServerGroupName != name {
|
||||
return backendgroup.lb.region.UpdateLoadbalancerMasterSlaveBackendgroupName(backendgroup.MasterSlaveServerGroupId, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteLoadbalancerMasterSlaveBackendgroup(groupId string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["MasterSlaveServerGroupId"] = groupId
|
||||
_, err := region.lbRequest("DeleteMasterSlaveServerGroup", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) Delete() error {
|
||||
return backendgroup.lb.region.DeleteLoadbalancerMasterSlaveBackendgroup(backendgroup.MasterSlaveServerGroupId)
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) AddBackendServer(serverId string, weight, port int) (cloudprovider.ICloudLoadbalancerBackend, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) RemoveBackendServer(serverId string) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
@@ -75,6 +75,34 @@ func (certificate *SLoadbalancerServerCertificate) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (region *SRegion) UpdateServerCertificateName(certId, name string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["ServerCertificateId"] = certId
|
||||
params["ServerCertificateName"] = name
|
||||
_, err := region.lbRequest("SetServerCertificateName", params)
|
||||
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)
|
||||
}
|
||||
|
||||
func (region *SRegion) DeleteServerCertificate(certId string) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["ServerCertificateId"] = certId
|
||||
_, err := region.lbRequest("DeleteServerCertificate", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (region *SRegion) GetLoadbalancerServerCertificates() ([]SLoadbalancerServerCertificate, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
|
||||
@@ -3,12 +3,14 @@ package aliyun
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
@@ -678,6 +680,45 @@ func (region *SRegion) GetILoadBalancers() ([]cloudprovider.ICloudLoadbalancer,
|
||||
return ilbs, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerById(loadbalancerId string) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return region.GetLoadbalancerDetail(loadbalancerId)
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerCertificateById(certId string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
certs, err := region.GetLoadbalancerServerCertificates()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(certs); i++ {
|
||||
if certs[i].GetGlobalId() == certId {
|
||||
certs[i].region = region
|
||||
return &certs[i], nil
|
||||
}
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerCertificate(name string, privateKey, certificate string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["ServerCertificateName"] = name
|
||||
params["PrivateKey"] = privateKey
|
||||
params["ServerCertificate"] = certificate
|
||||
body, err := region.lbRequest("UploadServerCertificate", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
certID, err := body.GetString("ServerCertificateId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return region.GetILoadBalancerCertificateById(certID)
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerAclById(aclId string) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return region.GetLoadbalancerAclDetail(aclId)
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
acls, err := region.GetLoadbalancerAcls()
|
||||
if err != nil {
|
||||
@@ -703,3 +744,89 @@ func (region *SRegion) GetILoadbalancerCertificates() ([]cloudprovider.ICloudLoa
|
||||
}
|
||||
return iCertificates, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalancer) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["LoadBalancerName"] = loadbalancer.Name
|
||||
if len(loadbalancer.ZoneID) > 0 {
|
||||
params["MasterZoneId"] = loadbalancer.ZoneID
|
||||
}
|
||||
|
||||
if len(loadbalancer.VpcID) > 0 {
|
||||
params["VpcId"] = loadbalancer.VpcID
|
||||
}
|
||||
|
||||
if len(loadbalancer.NetworkID) > 0 {
|
||||
params["VSwitchId"] = loadbalancer.NetworkID
|
||||
}
|
||||
|
||||
if len(loadbalancer.Address) > 0 {
|
||||
params["Address"] = loadbalancer.Address
|
||||
}
|
||||
|
||||
if len(loadbalancer.AddressType) > 0 {
|
||||
params["AddressType"] = loadbalancer.AddressType
|
||||
}
|
||||
|
||||
if len(loadbalancer.LoadbalancerSpec) > 0 {
|
||||
params["LoadBalancerSpec"] = loadbalancer.LoadbalancerSpec
|
||||
}
|
||||
|
||||
if loadbalancer.Bandwidth > 0 {
|
||||
params["Bandwidth"] = fmt.Sprintf("%d", loadbalancer.Bandwidth)
|
||||
}
|
||||
|
||||
body, err := region.lbRequest("CreateLoadBalancer", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loadBalancerID, err := body.GetString("LoadBalancerId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iLoadbalancer, err := region.GetLoadbalancerDetail(loadBalancerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iLoadbalancer, cloudprovider.WaitStatus(iLoadbalancer, models.LB_STATUS_ENABLED, time.Second*5, time.Minute*5)
|
||||
}
|
||||
|
||||
func (region *SRegion) AddAccessControlListEntry(aclId string, entrys []cloudprovider.SLoadbalancerAccessControlListEntry) error {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["AclId"] = aclId
|
||||
aclArray := jsonutils.NewArray()
|
||||
for i := 0; i < len(entrys); i++ {
|
||||
//阿里云AclEntrys参数必须是CIDR格式的。
|
||||
if regutils.MatchIPAddr(entrys[i].CIDR) {
|
||||
entrys[i].CIDR += "/32"
|
||||
}
|
||||
aclArray.Add(jsonutils.Marshal(map[string]string{"entry": entrys[i].CIDR, "comment": entrys[i].Comment}))
|
||||
}
|
||||
if aclArray.Length() == 0 {
|
||||
return nil
|
||||
}
|
||||
params["AclEntrys"] = aclArray.String()
|
||||
_, err := region.lbRequest("AddAccessControlListEntry", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
params := map[string]string{}
|
||||
params["RegionId"] = region.RegionId
|
||||
params["AclName"] = acl.Name
|
||||
body, err := region.lbRequest("CreateAccessControlList", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aclId, err := body.GetString("AclId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iAcl, err := region.GetLoadbalancerAclDetail(aclId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iAcl, region.AddAccessControlListEntry(aclId, acl.Entrys)
|
||||
}
|
||||
|
||||
@@ -455,6 +455,22 @@ func (region *SRegion) GetILoadBalancers() ([]cloudprovider.ICloudLoadbalancer,
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerById(loadbalancerId string) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerAclById(aclId string) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerCertificateById(certId string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerCertificate(name string, privateKey, certificate string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
@@ -462,3 +478,11 @@ func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalance
|
||||
func (region *SRegion) GetILoadbalancerCertificates() ([]cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalancer) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -507,6 +507,22 @@ func (region *SRegion) GetILoadBalancers() ([]cloudprovider.ICloudLoadbalancer,
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerById(loadbalancerId string) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerAclById(aclId string) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerCertificateById(certId string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerCertificate(name string, privateKey, certificate string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
@@ -514,3 +530,11 @@ func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalance
|
||||
func (region *SRegion) GetILoadbalancerCertificates() ([]cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalancer) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -133,6 +133,22 @@ func (self *SRegion) GetILoadBalancers() ([]cloudprovider.ICloudLoadbalancer, er
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerById(loadbalancerId string) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerAclById(aclId string) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerCertificateById(certId string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerCertificate(name string, privateKey, certificate string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
@@ -645,3 +661,11 @@ func (self *SRegion) addSecurityGroupRule(secGrpId, direction, portStart, portEn
|
||||
rule := SecurityGroupRule{}
|
||||
return DoCreate(self.ecsClient.SecurityGroupRules.Create, params, &rule)
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalancer) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -285,6 +285,22 @@ func (region *SRegion) GetILoadBalancers() ([]cloudprovider.ICloudLoadbalancer,
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerById(loadbalancerId string) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerAclById(aclId string) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerCertificateById(certId string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerCertificate(name string, privateKey, certificate string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
@@ -292,3 +308,11 @@ func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalance
|
||||
func (region *SRegion) GetILoadbalancerCertificates() ([]cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalancer) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -582,6 +582,22 @@ func (region *SRegion) GetILoadBalancers() ([]cloudprovider.ICloudLoadbalancer,
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerById(loadbalancerId string) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerAclById(aclId string) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerCertificateById(certId string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerCertificate(name string, privateKey, certificate string) (cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
@@ -589,3 +605,11 @@ func (region *SRegion) GetILoadbalancerAcls() ([]cloudprovider.ICloudLoadbalance
|
||||
func (region *SRegion) GetILoadbalancerCertificates() ([]cloudprovider.ICloudLoadbalancerCertificate, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbalancer) (cloudprovider.ICloudLoadbalancer, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateILoadBalancerAcl(acl *cloudprovider.SLoadbalancerAccessControlList) (cloudprovider.ICloudLoadbalancerAcl, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user