mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
fix: break dependencies of climc/mcclient on compute/models
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/util/choices"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
|
||||
@@ -66,7 +67,7 @@ func newInvalidTypeError(key string, typ string, err error) error {
|
||||
return newError(ERR_INVALID_TYPE, "expecting %s type for %q: %s", typ, key, err)
|
||||
}
|
||||
|
||||
func newInvalidChoiceError(key string, choices Choices, choice string) error {
|
||||
func newInvalidChoiceError(key string, choices choices.Choices, choice string) error {
|
||||
return newError(ERR_INVALID_CHOICE, "invalid %q, want %s, got %s", key, choices, choice)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/util/choices"
|
||||
)
|
||||
|
||||
type ValidatorFunc func(*jsonutils.JSONDict) error
|
||||
@@ -106,12 +108,12 @@ func (v *Validator) validateEx(data *jsonutils.JSONDict) (err error, isSet bool)
|
||||
|
||||
type ValidatorStringChoices struct {
|
||||
Validator
|
||||
Choices Choices
|
||||
Choices choices.Choices
|
||||
defaultVal string
|
||||
Value string
|
||||
}
|
||||
|
||||
func NewStringChoicesValidator(key string, choices Choices) *ValidatorStringChoices {
|
||||
func NewStringChoicesValidator(key string, choices choices.Choices) *ValidatorStringChoices {
|
||||
v := &ValidatorStringChoices{
|
||||
Validator: Validator{Key: key},
|
||||
Choices: choices,
|
||||
@@ -150,14 +152,14 @@ func (v *ValidatorStringChoices) Validate(data *jsonutils.JSONDict) error {
|
||||
|
||||
type ValidatorStringMultiChoices struct {
|
||||
Validator
|
||||
Choices Choices
|
||||
Choices choices.Choices
|
||||
defaultVal string
|
||||
Value string
|
||||
sep string
|
||||
keepDup bool
|
||||
}
|
||||
|
||||
func NewStringMultiChoicesValidator(key string, choices Choices) *ValidatorStringMultiChoices {
|
||||
func NewStringMultiChoicesValidator(key string, choices choices.Choices) *ValidatorStringMultiChoices {
|
||||
v := &ValidatorStringMultiChoices{
|
||||
Validator: Validator{Key: key},
|
||||
Choices: choices,
|
||||
|
||||
+25
-19
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
package consts
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/util/choices"
|
||||
)
|
||||
|
||||
// Load balancer status transition (for spec status)
|
||||
@@ -46,7 +46,7 @@ const (
|
||||
LB_STATUS_UNKNOWN = "unknown"
|
||||
)
|
||||
|
||||
var LB_STATUS_SPEC = validators.NewChoices(
|
||||
var LB_STATUS_SPEC = choices.NewChoices(
|
||||
LB_STATUS_ENABLED,
|
||||
LB_STATUS_DISABLED,
|
||||
)
|
||||
@@ -60,7 +60,7 @@ const (
|
||||
LB_BACKENDGROUP_TYPE_MASTER_SLAVE = "master_slave"
|
||||
)
|
||||
|
||||
var LB_BACKENDGROUP_TYPE = validators.NewChoices(
|
||||
var LB_BACKENDGROUP_TYPE = choices.NewChoices(
|
||||
LB_BACKENDGROUP_TYPE_DEFAULT,
|
||||
LB_BACKENDGROUP_TYPE_NORMAL,
|
||||
LB_BACKENDGROUP_TYPE_MASTER_SLAVE,
|
||||
@@ -78,7 +78,7 @@ const (
|
||||
LB_ADDR_TYPE_INTERNET = "internet"
|
||||
)
|
||||
|
||||
var LB_ADDR_TYPES = validators.NewChoices(
|
||||
var LB_ADDR_TYPES = choices.NewChoices(
|
||||
LB_ADDR_TYPE_INTERNET,
|
||||
LB_ADDR_TYPE_INTRANET,
|
||||
)
|
||||
@@ -88,7 +88,7 @@ const (
|
||||
LB_NETWORK_TYPE_VPC = "vpc"
|
||||
)
|
||||
|
||||
var LB_NETWORK_TYPES = validators.NewChoices(
|
||||
var LB_NETWORK_TYPES = choices.NewChoices(
|
||||
LB_NETWORK_TYPE_CLASSIC,
|
||||
LB_NETWORK_TYPE_VPC,
|
||||
)
|
||||
@@ -101,7 +101,7 @@ const (
|
||||
LB_LISTENER_TYPE_HTTPS = "https"
|
||||
)
|
||||
|
||||
var LB_LISTENER_TYPES = validators.NewChoices(
|
||||
var LB_LISTENER_TYPES = choices.NewChoices(
|
||||
LB_LISTENER_TYPE_TCP,
|
||||
LB_LISTENER_TYPE_UDP,
|
||||
LB_LISTENER_TYPE_HTTP,
|
||||
@@ -113,7 +113,7 @@ const (
|
||||
LB_ACL_TYPE_WHITE = "white"
|
||||
)
|
||||
|
||||
var LB_ACL_TYPES = validators.NewChoices(
|
||||
var LB_ACL_TYPES = choices.NewChoices(
|
||||
LB_ACL_TYPE_BLACK,
|
||||
LB_ACL_TYPE_WHITE,
|
||||
)
|
||||
@@ -128,7 +128,7 @@ const (
|
||||
LB_TLS_CERT_PUBKEY_ALGO_ECDSA = "ECDSA"
|
||||
)
|
||||
|
||||
var LB_TLS_CERT_PUBKEY_ALGOS = validators.NewChoices(
|
||||
var LB_TLS_CERT_PUBKEY_ALGOS = choices.NewChoices(
|
||||
LB_TLS_CERT_PUBKEY_ALGO_RSA,
|
||||
LB_TLS_CERT_PUBKEY_ALGO_ECDSA,
|
||||
)
|
||||
@@ -141,7 +141,7 @@ const (
|
||||
LB_TLS_CIPHER_POLICY_1_2_strict = "tls_cipher_policy_1_2_strict"
|
||||
)
|
||||
|
||||
var LB_TLS_CIPHER_POLICIES = validators.NewChoices(
|
||||
var LB_TLS_CIPHER_POLICIES = choices.NewChoices(
|
||||
LB_TLS_CIPHER_POLICY_1_0,
|
||||
LB_TLS_CIPHER_POLICY_1_1,
|
||||
LB_TLS_CIPHER_POLICY_1_2,
|
||||
@@ -153,7 +153,7 @@ const (
|
||||
LB_STICKY_SESSION_TYPE_SERVER = "server"
|
||||
)
|
||||
|
||||
var LB_STICKY_SESSION_TYPES = validators.NewChoices(
|
||||
var LB_STICKY_SESSION_TYPES = choices.NewChoices(
|
||||
LB_STICKY_SESSION_TYPE_INSERT,
|
||||
LB_STICKY_SESSION_TYPE_SERVER,
|
||||
)
|
||||
@@ -165,18 +165,18 @@ const (
|
||||
LB_HEALTH_CHECK_HTTP = "http"
|
||||
)
|
||||
|
||||
var LB_HEALTH_CHECK_TYPES = validators.NewChoices(
|
||||
var LB_HEALTH_CHECK_TYPES = choices.NewChoices(
|
||||
LB_HEALTH_CHECK_TCP,
|
||||
LB_HEALTH_CHECK_UDP,
|
||||
LB_HEALTH_CHECK_HTTP,
|
||||
)
|
||||
|
||||
var LB_HEALTH_CHECK_TYPES_TCP = validators.NewChoices(
|
||||
var LB_HEALTH_CHECK_TYPES_TCP = choices.NewChoices(
|
||||
LB_HEALTH_CHECK_TCP,
|
||||
LB_HEALTH_CHECK_HTTP,
|
||||
)
|
||||
|
||||
var LB_HEALTH_CHECK_TYPES_UDP = validators.NewChoices(
|
||||
var LB_HEALTH_CHECK_TYPES_UDP = choices.NewChoices(
|
||||
LB_HEALTH_CHECK_UDP,
|
||||
)
|
||||
|
||||
@@ -189,7 +189,7 @@ const (
|
||||
LB_HEALTH_CHECK_HTTP_CODE_DEFAULT = "http_2xx,http_3xx"
|
||||
)
|
||||
|
||||
var LB_HEALTH_CHECK_HTTP_CODES = validators.NewChoices(
|
||||
var LB_HEALTH_CHECK_HTTP_CODES = choices.NewChoices(
|
||||
LB_HEALTH_CHECK_HTTP_CODE_1xx,
|
||||
LB_HEALTH_CHECK_HTTP_CODE_2xx,
|
||||
LB_HEALTH_CHECK_HTTP_CODE_3xx,
|
||||
@@ -202,7 +202,7 @@ const (
|
||||
LB_BOOL_OFF = "off"
|
||||
)
|
||||
|
||||
var LB_BOOL_VALUES = validators.NewChoices(
|
||||
var LB_BOOL_VALUES = choices.NewChoices(
|
||||
LB_BOOL_ON,
|
||||
LB_BOOL_OFF,
|
||||
)
|
||||
@@ -219,7 +219,7 @@ const (
|
||||
LB_SCHEDULER_TCH = "tch" // 4-tuple-based consistent hash
|
||||
)
|
||||
|
||||
var LB_SCHEDULER_TYPES = validators.NewChoices(
|
||||
var LB_SCHEDULER_TYPES = choices.NewChoices(
|
||||
LB_SCHEDULER_RR,
|
||||
LB_SCHEDULER_WRR,
|
||||
LB_SCHEDULER_WLC,
|
||||
@@ -233,7 +233,7 @@ const (
|
||||
LB_BACKEND_HOST = "host"
|
||||
)
|
||||
|
||||
var LB_BACKEND_TYPES = validators.NewChoices(
|
||||
var LB_BACKEND_TYPES = choices.NewChoices(
|
||||
LB_BACKEND_GUEST,
|
||||
LB_BACKEND_HOST,
|
||||
)
|
||||
@@ -244,8 +244,14 @@ const (
|
||||
LB_BACKEND_ROLE_SLAVE = "slave"
|
||||
)
|
||||
|
||||
var LB_BACKEND_ROLES = validators.NewChoices(
|
||||
var LB_BACKEND_ROLES = choices.NewChoices(
|
||||
LB_BACKEND_ROLE_MASTER,
|
||||
LB_BACKEND_ROLE_DEFAULT,
|
||||
LB_BACKEND_ROLE_SLAVE,
|
||||
)
|
||||
|
||||
const (
|
||||
LB_CHARGE_TYPE_BY_TRAFFIC = "traffic"
|
||||
LB_CHARGE_TYPE_BY_BANDWIDTH = "bandwidth"
|
||||
LB_CHARGE_TYPE_BY_HOUR = "hour"
|
||||
)
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"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/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -153,7 +154,7 @@ func (lbacl *SLoadbalancerAcl) ValidateUpdateData(ctx context.Context, userCred
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lbacl.SSharableVirtualResourceBase.PostUpdate(ctx, userCred, query, data)
|
||||
lbacl.SetStatus(userCred, LB_SYNC_CONF, "")
|
||||
lbacl.SetStatus(userCred, consts.LB_SYNC_CONF, "")
|
||||
lbacl.StartLoadBalancerAclSyncTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ func (lbacl *SLoadbalancerAcl) StartLoadBalancerAclSyncTask(ctx context.Context,
|
||||
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_CREATING, "")
|
||||
lbacl.SetStatus(userCred, consts.LB_CREATING, "")
|
||||
if err := lbacl.StartLoadBalancerAclCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalanceracl error: %v", err)
|
||||
}
|
||||
@@ -290,7 +291,7 @@ func (lbacl *SLoadbalancerAcl) PerformPurge(ctx context.Context, userCred mcclie
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbacl.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
lbacl.SetStatus(userCred, consts.LB_STATUS_DELETING, "")
|
||||
return lbacl.StartLoadBalancerAclDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
@@ -340,7 +341,7 @@ func (man *SLoadbalancerAclManager) SyncLoadbalancerAcls(ctx context.Context, us
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
err = removed[i].SetStatus(userCred, LB_STATUS_UNKNOWN, "sync to delete")
|
||||
err = removed[i].SetStatus(userCred, consts.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"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/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -88,7 +89,7 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont
|
||||
}
|
||||
for i := 0; i < len(backends); i++ {
|
||||
if len(backends[i].BackendType) == 0 {
|
||||
backends[i].BackendType = LB_BACKEND_GUEST
|
||||
backends[i].BackendType = consts.LB_BACKEND_GUEST
|
||||
}
|
||||
if backends[i].Weight < 0 || backends[i].Weight > 256 {
|
||||
return nil, httperrors.NewInputParameterError("weight %s not support, only support range 0 ~ 256")
|
||||
@@ -101,7 +102,7 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont
|
||||
}
|
||||
|
||||
switch backends[i].BackendType {
|
||||
case LB_BACKEND_GUEST:
|
||||
case consts.LB_BACKEND_GUEST:
|
||||
_guest, err := GuestManager.FetchByIdOrName(userCred, backends[i].ID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -125,7 +126,7 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont
|
||||
return nil, err
|
||||
}
|
||||
backends[i].Address = address
|
||||
case LB_BACKEND_HOST:
|
||||
case consts.LB_BACKEND_HOST:
|
||||
if !db.IsAdminAllowCreate(userCred, man) {
|
||||
return nil, httperrors.NewForbiddenError("only sysadmin can specify host as backend")
|
||||
}
|
||||
@@ -261,7 +262,7 @@ func (lbbg *SLoadbalancerBackendGroup) PostCreate(ctx context.Context, userCred
|
||||
if backends != nil {
|
||||
params.Add(backends, "backends")
|
||||
}
|
||||
lbbg.SetStatus(userCred, LB_CREATING, "")
|
||||
lbbg.SetStatus(userCred, consts.LB_CREATING, "")
|
||||
if err := lbbg.StartLoadBalancerBackendGroupCreateTask(ctx, userCred, params, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer backendgroup error: %v", err)
|
||||
}
|
||||
@@ -298,7 +299,7 @@ func (lbbg *SLoadbalancerBackendGroup) PerformPurge(ctx context.Context, userCre
|
||||
}
|
||||
|
||||
func (lbbg *SLoadbalancerBackendGroup) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbbg.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
lbbg.SetStatus(userCred, consts.LB_STATUS_DELETING, "")
|
||||
return lbbg.StartLoadBalancerBackendGroupDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
@@ -350,7 +351,7 @@ func (man *SLoadbalancerBackendGroupManager) SyncLoadbalancerBackendgroups(ctx c
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
err = removed[i].SetStatus(userCred, LB_STATUS_UNKNOWN, "sync to delete")
|
||||
err = removed[i].SetStatus(userCred, consts.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
@@ -463,7 +464,7 @@ func (man *SLoadbalancerBackendGroupManager) initBackendGroupType() error {
|
||||
}
|
||||
for i := 0; i < len(backendgroups); i++ {
|
||||
_, err := man.TableSpec().Update(&backendgroups[i], func() error {
|
||||
backendgroups[i].Type = LB_BACKENDGROUP_TYPE_NORMAL
|
||||
backendgroups[i].Type = consts.LB_BACKENDGROUP_TYPE_NORMAL
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"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/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -75,7 +76,7 @@ func (man *SLoadbalancerBackendManager) ListItemFilter(ctx context.Context, q *s
|
||||
|
||||
func (man *SLoadbalancerBackendManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
backendGroupV := validators.NewModelIdOrNameValidator("backend_group", "loadbalancerbackendgroup", ownerProjId)
|
||||
backendTypeV := validators.NewStringChoicesValidator("backend_type", LB_BACKEND_TYPES)
|
||||
backendTypeV := validators.NewStringChoicesValidator("backend_type", consts.LB_BACKEND_TYPES)
|
||||
keyV := map[string]validators.IValidator{
|
||||
"backend_group": backendGroupV,
|
||||
"backend_type": backendTypeV,
|
||||
@@ -95,7 +96,7 @@ func (man *SLoadbalancerBackendManager) ValidateCreateData(ctx context.Context,
|
||||
var baseName string
|
||||
var backendV *validators.ValidatorModelIdOrName
|
||||
switch backendType {
|
||||
case LB_BACKEND_GUEST:
|
||||
case consts.LB_BACKEND_GUEST:
|
||||
backendV = validators.NewModelIdOrNameValidator("backend", "server", ownerProjId)
|
||||
err := backendV.Validate(data)
|
||||
if err != nil {
|
||||
@@ -103,7 +104,7 @@ func (man *SLoadbalancerBackendManager) ValidateCreateData(ctx context.Context,
|
||||
}
|
||||
guest := backendV.Model.(*SGuest)
|
||||
baseName = guest.Name
|
||||
case LB_BACKEND_HOST:
|
||||
case consts.LB_BACKEND_HOST:
|
||||
if !db.IsAdminAllowCreate(userCred, man) {
|
||||
return nil, fmt.Errorf("only sysadmin can specify host as backend")
|
||||
}
|
||||
@@ -205,7 +206,7 @@ func (lbb *SLoadbalancerBackend) ValidateUpdateData(ctx context.Context, userCre
|
||||
|
||||
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_CREATING, "")
|
||||
lbb.SetStatus(userCred, consts.LB_CREATING, "")
|
||||
if err := lbb.StartLoadBalancerBackendCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer backend error: %v", err)
|
||||
}
|
||||
@@ -235,7 +236,7 @@ func (lbb *SLoadbalancerBackend) PerformPurge(ctx context.Context, userCred mccl
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbb.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
lbb.SetStatus(userCred, consts.LB_STATUS_DELETING, "")
|
||||
return lbb.StartLoadBalancerBackendDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
@@ -292,7 +293,7 @@ func (man *SLoadbalancerBackendManager) SyncLoadbalancerBackends(ctx context.Con
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
err = removed[i].SetStatus(userCred, LB_STATUS_UNKNOWN, "sync to delete")
|
||||
err = removed[i].SetStatus(userCred, consts.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"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/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -90,15 +91,15 @@ func (man *SLoadbalancerCertificateManager) validateCertKey(ctx context.Context,
|
||||
// x509.PublicKeyAlgorithm.String() is only available since go1.10
|
||||
switch cert.PublicKeyAlgorithm {
|
||||
case x509.RSA:
|
||||
certPubKeyAlgo = LB_TLS_CERT_PUBKEY_ALGO_RSA
|
||||
certPubKeyAlgo = consts.LB_TLS_CERT_PUBKEY_ALGO_RSA
|
||||
case x509.ECDSA:
|
||||
certPubKeyAlgo = LB_TLS_CERT_PUBKEY_ALGO_ECDSA
|
||||
certPubKeyAlgo = consts.LB_TLS_CERT_PUBKEY_ALGO_ECDSA
|
||||
default:
|
||||
certPubKeyAlgo = fmt.Sprintf("algo %#v", cert.PublicKeyAlgorithm)
|
||||
}
|
||||
if !LB_TLS_CERT_PUBKEY_ALGOS.Has(certPubKeyAlgo) {
|
||||
if !consts.LB_TLS_CERT_PUBKEY_ALGOS.Has(certPubKeyAlgo) {
|
||||
return nil, httperrors.NewInputParameterError("invalid cert pubkey algorithm: %s, want %s",
|
||||
certPubKeyAlgo, LB_TLS_CERT_PUBKEY_ALGOS.String())
|
||||
certPubKeyAlgo, consts.LB_TLS_CERT_PUBKEY_ALGOS.String())
|
||||
}
|
||||
}
|
||||
err := pkeyV.MatchCertificate(cert)
|
||||
@@ -117,7 +118,7 @@ func (man *SLoadbalancerCertificateManager) validateCertKey(ctx context.Context,
|
||||
data.Set("public_key_algorithm", jsonutils.NewString(certPubKeyAlgo))
|
||||
data.Set("public_key_bit_len", jsonutils.NewInt(int64(certV.PublicKeyBitLen())))
|
||||
data.Set("signature_algorithm", jsonutils.NewString(cert.SignatureAlgorithm.String()))
|
||||
data.Set("fingerprint", jsonutils.NewString(LB_TLS_CERT_FINGERPRINT_ALGO_SHA256+":"+certV.FingerprintSha256String()))
|
||||
data.Set("fingerprint", jsonutils.NewString(consts.LB_TLS_CERT_FINGERPRINT_ALGO_SHA256+":"+certV.FingerprintSha256String()))
|
||||
return data, nil
|
||||
}
|
||||
|
||||
@@ -163,7 +164,7 @@ func (man *SLoadbalancerCertificateManager) InitializeData() error {
|
||||
continue
|
||||
}
|
||||
d := sha256.Sum256(c.Raw)
|
||||
fp = LB_TLS_CERT_FINGERPRINT_ALGO_SHA256 + ":" + hex.EncodeToString(d[:])
|
||||
fp = consts.LB_TLS_CERT_FINGERPRINT_ALGO_SHA256 + ":" + hex.EncodeToString(d[:])
|
||||
}
|
||||
_, err := man.TableSpec().Update(lbcert, func() error {
|
||||
lbcert.Fingerprint = fp
|
||||
@@ -204,7 +205,7 @@ func (lbcert *SLoadbalancerCertificate) ValidateUpdateData(ctx context.Context,
|
||||
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_CREATING, "")
|
||||
lbcert.SetStatus(userCred, consts.LB_CREATING, "")
|
||||
if err := lbcert.StartLoadBalancerCertificateCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancercertificate error: %v", err)
|
||||
}
|
||||
@@ -275,7 +276,7 @@ func (lbcert *SLoadbalancerCertificate) PerformPurge(ctx context.Context, userCr
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbcert.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
lbcert.SetStatus(userCred, consts.LB_STATUS_DELETING, "")
|
||||
return lbcert.StartLoadBalancerCertificateDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
@@ -321,7 +322,7 @@ func (man *SLoadbalancerCertificateManager) SyncLoadbalancerCertificates(ctx con
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
err = removed[i].SetStatus(userCred, LB_STATUS_UNKNOWN, "sync to delete")
|
||||
err = removed[i].SetStatus(userCred, consts.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"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/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -94,7 +95,7 @@ func (man *SLoadbalancerListenerRuleManager) ValidateCreateData(ctx context.Cont
|
||||
domainV := validators.NewDomainNameValidator("domain")
|
||||
pathV := validators.NewURLPathValidator("path")
|
||||
keyV := map[string]validators.IValidator{
|
||||
"status": validators.NewStringChoicesValidator("status", LB_STATUS_SPEC).Default(LB_STATUS_ENABLED),
|
||||
"status": validators.NewStringChoicesValidator("status", consts.LB_STATUS_SPEC).Default(consts.LB_STATUS_ENABLED),
|
||||
|
||||
"listener": listenerV,
|
||||
"backend_group": backendGroupV,
|
||||
@@ -113,7 +114,7 @@ func (man *SLoadbalancerListenerRuleManager) ValidateCreateData(ctx context.Cont
|
||||
data.Set("cloudregion_id", jsonutils.NewString(listener.CloudregionId))
|
||||
data.Set("manager_id", jsonutils.NewString(listener.ManagerId))
|
||||
listenerType := listener.ListenerType
|
||||
if listenerType != LB_LISTENER_TYPE_HTTP && listenerType != LB_LISTENER_TYPE_HTTPS {
|
||||
if listenerType != consts.LB_LISTENER_TYPE_HTTP && listenerType != consts.LB_LISTENER_TYPE_HTTPS {
|
||||
return nil, fmt.Errorf("listener type must be http/https, got %s", listenerType)
|
||||
}
|
||||
{
|
||||
@@ -148,7 +149,7 @@ func (man *SLoadbalancerListenerRuleManager) ValidateCreateData(ctx context.Cont
|
||||
func (lbr *SLoadbalancerListenerRule) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
lbr.SVirtualResourceBase.PostCreate(ctx, userCred, ownerProjId, query, data)
|
||||
|
||||
lbr.SetStatus(userCred, LB_CREATING, "")
|
||||
lbr.SetStatus(userCred, consts.LB_CREATING, "")
|
||||
if err := lbr.StartLoadBalancerListenerRuleCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer listener rule error: %v", err)
|
||||
}
|
||||
@@ -174,7 +175,7 @@ func (lbr *SLoadbalancerListenerRule) PerformPurge(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
func (lbr *SLoadbalancerListenerRule) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lbr.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
lbr.SetStatus(userCred, consts.LB_STATUS_DELETING, "")
|
||||
return lbr.StartLoadBalancerListenerRuleDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
@@ -303,7 +304,7 @@ func (man *SLoadbalancerListenerRuleManager) SyncLoadbalancerListenerRules(ctx c
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
err = removed[i].SetStatus(userCred, LB_STATUS_UNKNOWN, "sync to delete")
|
||||
err = removed[i].SetStatus(userCred, consts.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"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/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -122,10 +123,10 @@ func (man *SLoadbalancerListenerManager) checkListenerUniqueness(ctx context.Con
|
||||
Equals("loadbalancer_id", lb.Id).
|
||||
Equals("listener_port", listenerPort)
|
||||
switch listenerType {
|
||||
case LB_LISTENER_TYPE_TCP, LB_LISTENER_TYPE_HTTP, LB_LISTENER_TYPE_HTTPS:
|
||||
q = q.NotEquals("listener_type", LB_LISTENER_TYPE_UDP)
|
||||
case LB_LISTENER_TYPE_UDP:
|
||||
q = q.Equals("listener_type", LB_LISTENER_TYPE_UDP)
|
||||
case consts.LB_LISTENER_TYPE_TCP, consts.LB_LISTENER_TYPE_HTTP, consts.LB_LISTENER_TYPE_HTTPS:
|
||||
q = q.NotEquals("listener_type", consts.LB_LISTENER_TYPE_UDP)
|
||||
case consts.LB_LISTENER_TYPE_UDP:
|
||||
q = q.Equals("listener_type", consts.LB_LISTENER_TYPE_UDP)
|
||||
default:
|
||||
return fmt.Errorf("unexpected listener type: %s", listenerType)
|
||||
}
|
||||
@@ -166,25 +167,25 @@ func (man *SLoadbalancerListenerManager) ListItemFilter(ctx context.Context, q *
|
||||
|
||||
func (man *SLoadbalancerListenerManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
lbV := validators.NewModelIdOrNameValidator("loadbalancer", "loadbalancer", ownerProjId)
|
||||
listenerTypeV := validators.NewStringChoicesValidator("listener_type", LB_LISTENER_TYPES)
|
||||
listenerTypeV := validators.NewStringChoicesValidator("listener_type", consts.LB_LISTENER_TYPES)
|
||||
listenerPortV := validators.NewPortValidator("listener_port")
|
||||
backendGroupV := validators.NewModelIdOrNameValidator("backend_group", "loadbalancerbackendgroup", ownerProjId)
|
||||
aclStatusV := validators.NewStringChoicesValidator("acl_status", LB_BOOL_VALUES)
|
||||
aclTypeV := validators.NewStringChoicesValidator("acl_type", LB_ACL_TYPES)
|
||||
aclStatusV := validators.NewStringChoicesValidator("acl_status", consts.LB_BOOL_VALUES)
|
||||
aclTypeV := validators.NewStringChoicesValidator("acl_type", consts.LB_ACL_TYPES)
|
||||
aclV := validators.NewModelIdOrNameValidator("acl", "loadbalanceracl", ownerProjId)
|
||||
keyV := map[string]validators.IValidator{
|
||||
"status": validators.NewStringChoicesValidator("status", LB_STATUS_SPEC).Default(LB_STATUS_ENABLED),
|
||||
"status": validators.NewStringChoicesValidator("status", consts.LB_STATUS_SPEC).Default(consts.LB_STATUS_ENABLED),
|
||||
|
||||
"loadbalancer": lbV,
|
||||
"listener_type": listenerTypeV,
|
||||
"listener_port": listenerPortV,
|
||||
"backend_group": backendGroupV.Optional(true),
|
||||
|
||||
"acl_status": aclStatusV.Default(LB_BOOL_OFF),
|
||||
"acl_status": aclStatusV.Default(consts.LB_BOOL_OFF),
|
||||
"acl_type": aclTypeV.Optional(true),
|
||||
"acl": aclV.Optional(true),
|
||||
|
||||
"scheduler": validators.NewStringChoicesValidator("scheduler", LB_SCHEDULER_TYPES),
|
||||
"scheduler": validators.NewStringChoicesValidator("scheduler", consts.LB_SCHEDULER_TYPES),
|
||||
"bandwidth": validators.NewRangeValidator("bandwidth", 0, 10000).Optional(true),
|
||||
|
||||
"client_request_timeout": validators.NewRangeValidator("client_request_timeout", 0, 600).Default(10),
|
||||
@@ -192,8 +193,8 @@ func (man *SLoadbalancerListenerManager) ValidateCreateData(ctx context.Context,
|
||||
"backend_connect_timeout": validators.NewRangeValidator("backend_connect_timeout", 0, 180).Default(5),
|
||||
"backend_idle_timeout": validators.NewRangeValidator("backend_idle_timeout", 0, 600).Default(90),
|
||||
|
||||
"sticky_session": validators.NewStringChoicesValidator("sticky_session", LB_BOOL_VALUES).Default(LB_BOOL_OFF),
|
||||
"sticky_session_type": validators.NewStringChoicesValidator("sticky_session_type", LB_STICKY_SESSION_TYPES).Default(LB_STICKY_SESSION_TYPE_INSERT),
|
||||
"sticky_session": validators.NewStringChoicesValidator("sticky_session", consts.LB_BOOL_VALUES).Default(consts.LB_BOOL_OFF),
|
||||
"sticky_session_type": validators.NewStringChoicesValidator("sticky_session_type", consts.LB_STICKY_SESSION_TYPES).Default(consts.LB_STICKY_SESSION_TYPE_INSERT),
|
||||
"sticky_session_cookie": validators.NewRegexpValidator("sticky_session_cookie", regexp.MustCompile(`\w+`)).Optional(true),
|
||||
"sticky_session_cookie_timeout": validators.NewNonNegativeValidator("sticky_session_cookie_timeout").Optional(true),
|
||||
|
||||
@@ -235,9 +236,9 @@ func (man *SLoadbalancerListenerManager) ValidateCreateData(ctx context.Context,
|
||||
}
|
||||
}
|
||||
{
|
||||
if listenerType == LB_LISTENER_TYPE_HTTPS {
|
||||
if listenerType == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
certV := validators.NewModelIdOrNameValidator("certificate", "loadbalancercertificate", ownerProjId)
|
||||
tlsCipherPolicyV := validators.NewStringChoicesValidator("tls_cipher_policy", LB_TLS_CIPHER_POLICIES).Default(LB_TLS_CIPHER_POLICY_1_2)
|
||||
tlsCipherPolicyV := validators.NewStringChoicesValidator("tls_cipher_policy", consts.LB_TLS_CIPHER_POLICIES).Default(consts.LB_TLS_CIPHER_POLICY_1_2)
|
||||
httpsV := map[string]validators.IValidator{
|
||||
"certificate": certV,
|
||||
"tls_cipher_policy": tlsCipherPolicyV,
|
||||
@@ -258,12 +259,12 @@ func (man *SLoadbalancerListenerManager) ValidateCreateData(ctx context.Context,
|
||||
// health check default depends on input parameters
|
||||
checkTypeV := man.checkTypeV(listenerType)
|
||||
keyVHealth := map[string]validators.IValidator{
|
||||
"health_check": validators.NewStringChoicesValidator("health_check", LB_BOOL_VALUES).Default(LB_BOOL_ON),
|
||||
"health_check": validators.NewStringChoicesValidator("health_check", consts.LB_BOOL_VALUES).Default(consts.LB_BOOL_ON),
|
||||
"health_check_type": checkTypeV,
|
||||
|
||||
"health_check_domain": validators.NewDomainNameValidator("health_check_domain").AllowEmpty(true).Default(""),
|
||||
"health_check_path": validators.NewURLPathValidator("health_check_path").Default(""),
|
||||
"health_check_http_code": validators.NewStringMultiChoicesValidator("health_check_http_code", LB_HEALTH_CHECK_HTTP_CODES).Sep(",").Default(LB_HEALTH_CHECK_HTTP_CODE_DEFAULT),
|
||||
"health_check_http_code": validators.NewStringMultiChoicesValidator("health_check_http_code", consts.LB_HEALTH_CHECK_HTTP_CODES).Sep(",").Default(consts.LB_HEALTH_CHECK_HTTP_CODE_DEFAULT),
|
||||
|
||||
"health_check_rise": validators.NewRangeValidator("health_check_rise", 1, 1000).Default(3),
|
||||
"health_check_fall": validators.NewRangeValidator("health_check_fall", 1, 1000).Default(3),
|
||||
@@ -291,19 +292,19 @@ func (man *SLoadbalancerListenerManager) ValidateCreateData(ctx context.Context,
|
||||
|
||||
func (man *SLoadbalancerListenerManager) checkTypeV(listenerType string) validators.IValidator {
|
||||
switch listenerType {
|
||||
case LB_LISTENER_TYPE_HTTP, LB_LISTENER_TYPE_HTTPS:
|
||||
return validators.NewStringChoicesValidator("health_check_type", LB_HEALTH_CHECK_TYPES_TCP).Default(LB_HEALTH_CHECK_HTTP)
|
||||
case LB_LISTENER_TYPE_TCP:
|
||||
return validators.NewStringChoicesValidator("health_check_type", LB_HEALTH_CHECK_TYPES_TCP).Default(LB_HEALTH_CHECK_TCP)
|
||||
case LB_LISTENER_TYPE_UDP:
|
||||
return validators.NewStringChoicesValidator("health_check_type", LB_HEALTH_CHECK_TYPES_UDP).Default(LB_HEALTH_CHECK_UDP)
|
||||
case consts.LB_LISTENER_TYPE_HTTP, consts.LB_LISTENER_TYPE_HTTPS:
|
||||
return validators.NewStringChoicesValidator("health_check_type", consts.LB_HEALTH_CHECK_TYPES_TCP).Default(consts.LB_HEALTH_CHECK_HTTP)
|
||||
case consts.LB_LISTENER_TYPE_TCP:
|
||||
return validators.NewStringChoicesValidator("health_check_type", consts.LB_HEALTH_CHECK_TYPES_TCP).Default(consts.LB_HEALTH_CHECK_TCP)
|
||||
case consts.LB_LISTENER_TYPE_UDP:
|
||||
return validators.NewStringChoicesValidator("health_check_type", consts.LB_HEALTH_CHECK_TYPES_UDP).Default(consts.LB_HEALTH_CHECK_UDP)
|
||||
}
|
||||
// should it happen, panic then
|
||||
return nil
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerListenerManager) validateAcl(aclStatusV *validators.ValidatorStringChoices, aclTypeV *validators.ValidatorStringChoices, aclV *validators.ValidatorModelIdOrName, data *jsonutils.JSONDict) error {
|
||||
if aclStatusV.Value == LB_BOOL_ON {
|
||||
if aclStatusV.Value == consts.LB_BOOL_ON {
|
||||
if aclV.Model == nil {
|
||||
return httperrors.NewInputParameterError("missing acl")
|
||||
}
|
||||
@@ -324,7 +325,7 @@ func (lblis *SLoadbalancerListener) PerformStatus(ctx context.Context, userCred
|
||||
if _, err := lblis.SVirtualResourceBase.PerformStatus(ctx, userCred, query, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if lblis.Status == LB_STATUS_ENABLED {
|
||||
if lblis.Status == consts.LB_STATUS_ENABLED {
|
||||
return nil, lblis.StartLoadBalancerListenerStartTask(ctx, userCred, "")
|
||||
}
|
||||
return nil, lblis.StartLoadBalancerListenerStopTask(ctx, userCred, "")
|
||||
@@ -354,7 +355,7 @@ func (lblis *SLoadbalancerListener) AllowPerformSyncstatus(ctx context.Context,
|
||||
|
||||
func (lblis *SLoadbalancerListener) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
params := jsonutils.NewDict()
|
||||
if utils.IsInStringArray(lblis.Status, []string{LB_STATUS_ENABLED, LB_STATUS_DISABLED}) {
|
||||
if utils.IsInStringArray(lblis.Status, []string{consts.LB_STATUS_ENABLED, consts.LB_STATUS_DISABLED}) {
|
||||
params.Add(jsonutils.NewString(lblis.Status), "origin_status")
|
||||
}
|
||||
return nil, lblis.StartLoadBalancerListenerSyncstatusTask(ctx, userCred, params, "")
|
||||
@@ -372,15 +373,15 @@ func (lblis *SLoadbalancerListener) StartLoadBalancerListenerSyncstatusTask(ctx
|
||||
func (lblis *SLoadbalancerListener) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
ownerProjId := lblis.GetOwnerProjectId()
|
||||
backendGroupV := validators.NewModelIdOrNameValidator("backend_group", "loadbalancerbackendgroup", ownerProjId)
|
||||
aclStatusV := validators.NewStringChoicesValidator("acl_status", LB_BOOL_VALUES)
|
||||
aclStatusV := validators.NewStringChoicesValidator("acl_status", consts.LB_BOOL_VALUES)
|
||||
aclStatusV.Default(lblis.AclStatus)
|
||||
aclTypeV := validators.NewStringChoicesValidator("acl_type", LB_ACL_TYPES)
|
||||
if LB_ACL_TYPES.Has(lblis.AclType) {
|
||||
aclTypeV := validators.NewStringChoicesValidator("acl_type", consts.LB_ACL_TYPES)
|
||||
if consts.LB_ACL_TYPES.Has(lblis.AclType) {
|
||||
aclTypeV.Default(lblis.AclType)
|
||||
}
|
||||
aclV := validators.NewModelIdOrNameValidator("acl", "loadbalanceracl", ownerProjId)
|
||||
certV := validators.NewModelIdOrNameValidator("certificate", "loadbalancercertificate", ownerProjId)
|
||||
tlsCipherPolicyV := validators.NewStringChoicesValidator("tls_cipher_policy", LB_TLS_CIPHER_POLICIES).Default(LB_TLS_CIPHER_POLICY_1_2)
|
||||
tlsCipherPolicyV := validators.NewStringChoicesValidator("tls_cipher_policy", consts.LB_TLS_CIPHER_POLICIES).Default(consts.LB_TLS_CIPHER_POLICY_1_2)
|
||||
keyV := map[string]validators.IValidator{
|
||||
"backend_group": backendGroupV,
|
||||
|
||||
@@ -388,7 +389,7 @@ func (lblis *SLoadbalancerListener) ValidateUpdateData(ctx context.Context, user
|
||||
"acl_type": aclTypeV,
|
||||
"acl": aclV,
|
||||
|
||||
"scheduler": validators.NewStringChoicesValidator("scheduler", LB_SCHEDULER_TYPES),
|
||||
"scheduler": validators.NewStringChoicesValidator("scheduler", consts.LB_SCHEDULER_TYPES),
|
||||
"bandwidth": validators.NewRangeValidator("bandwidth", 0, 10000),
|
||||
|
||||
"client_request_timeout": validators.NewRangeValidator("client_request_timeout", 0, 600),
|
||||
@@ -396,17 +397,17 @@ func (lblis *SLoadbalancerListener) ValidateUpdateData(ctx context.Context, user
|
||||
"backend_connect_timeout": validators.NewRangeValidator("backend_connect_timeout", 0, 180),
|
||||
"backend_idle_timeout": validators.NewRangeValidator("backend_idle_timeout", 0, 600),
|
||||
|
||||
"sticky_session": validators.NewStringChoicesValidator("sticky_session", LB_BOOL_VALUES),
|
||||
"sticky_session_type": validators.NewStringChoicesValidator("sticky_session_type", LB_STICKY_SESSION_TYPES),
|
||||
"sticky_session": validators.NewStringChoicesValidator("sticky_session", consts.LB_BOOL_VALUES),
|
||||
"sticky_session_type": validators.NewStringChoicesValidator("sticky_session_type", consts.LB_STICKY_SESSION_TYPES),
|
||||
"sticky_session_cookie": validators.NewRegexpValidator("sticky_session_cookie", regexp.MustCompile(`\w+`)),
|
||||
"sticky_session_cookie_timeout": validators.NewNonNegativeValidator("sticky_session_cookie_timeout"),
|
||||
|
||||
"health_check": validators.NewStringChoicesValidator("health_check", LB_BOOL_VALUES),
|
||||
"health_check": validators.NewStringChoicesValidator("health_check", consts.LB_BOOL_VALUES),
|
||||
"health_check_type": LoadbalancerListenerManager.checkTypeV(lblis.ListenerType),
|
||||
|
||||
"health_check_domain": validators.NewDomainNameValidator("health_check_domain").AllowEmpty(true),
|
||||
"health_check_path": validators.NewURLPathValidator("health_check_path"),
|
||||
"health_check_http_code": validators.NewStringMultiChoicesValidator("health_check_http_code", LB_HEALTH_CHECK_HTTP_CODES).Sep(","),
|
||||
"health_check_http_code": validators.NewStringMultiChoicesValidator("health_check_http_code", consts.LB_HEALTH_CHECK_HTTP_CODES).Sep(","),
|
||||
|
||||
"health_check_rise": validators.NewRangeValidator("health_check_rise", 1, 1000),
|
||||
"health_check_fall": validators.NewRangeValidator("health_check_fall", 1, 1000),
|
||||
@@ -457,10 +458,10 @@ func (lblis *SLoadbalancerListener) PostUpdate(ctx context.Context, userCred mcc
|
||||
|
||||
func (lblis *SLoadbalancerListener) StartLoadBalancerListenerSyncTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
if utils.IsInStringArray(lblis.Status, []string{LB_STATUS_ENABLED, LB_STATUS_DISABLED}) {
|
||||
if utils.IsInStringArray(lblis.Status, []string{consts.LB_STATUS_ENABLED, consts.LB_STATUS_DISABLED}) {
|
||||
params.Add(jsonutils.NewString(lblis.Status), "origin_status")
|
||||
}
|
||||
lblis.SetStatus(userCred, LB_SYNC_CONF, "")
|
||||
lblis.SetStatus(userCred, consts.LB_SYNC_CONF, "")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerListenerSyncTask", lblis, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -503,7 +504,7 @@ func (lblis *SLoadbalancerListener) GetExtraDetails(ctx context.Context, userCre
|
||||
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_CREATING, "")
|
||||
lblis.SetStatus(userCred, consts.LB_CREATING, "")
|
||||
if err := lblis.StartLoadBalancerListenerCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer listener error: %v", err)
|
||||
}
|
||||
@@ -546,7 +547,7 @@ func (lblis *SLoadbalancerListener) StartLoadBalancerListenerDeleteTask(ctx cont
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
lblis.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
lblis.SetStatus(userCred, consts.LB_STATUS_DELETING, "")
|
||||
return lblis.StartLoadBalancerListenerDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
@@ -601,7 +602,7 @@ func (lblis *SLoadbalancerListener) GetLoadbalancerListenerParams() (*cloudprovi
|
||||
listener.AccessControlListType = lblis.AclType
|
||||
listener.AccessControlListStatus = lblis.AclStatus
|
||||
}
|
||||
if certificate := lblis.GetLoadbalancerCertificate(); certificate != nil && lblis.ListenerType == LB_LISTENER_TYPE_HTTPS {
|
||||
if certificate := lblis.GetLoadbalancerCertificate(); certificate != nil && lblis.ListenerType == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
listener.CertificateID = certificate.ExternalId
|
||||
}
|
||||
|
||||
@@ -696,7 +697,7 @@ func (man *SLoadbalancerListenerManager) SyncLoadbalancerListeners(ctx context.C
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
err = removed[i].SetStatus(userCred, LB_STATUS_UNKNOWN, "sync to delete")
|
||||
err = removed[i].SetStatus(userCred, consts.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
@@ -756,7 +757,7 @@ func (lblis *SLoadbalancerListener) constructFieldsFromCloudListener(lb *SLoadba
|
||||
lblis.BackendServerPort = extListener.GetBackendServerPort()
|
||||
|
||||
switch lblis.ListenerType {
|
||||
case LB_LISTENER_TYPE_HTTPS:
|
||||
case consts.LB_LISTENER_TYPE_HTTPS:
|
||||
lblis.TLSCipherPolicy = extListener.GetTLSCipherPolicy()
|
||||
lblis.EnableHttp2 = extListener.HTTP2Enabled()
|
||||
if certificateId := extListener.GetCertificateId(); len(certificateId) > 0 {
|
||||
@@ -765,7 +766,7 @@ func (lblis *SLoadbalancerListener) constructFieldsFromCloudListener(lb *SLoadba
|
||||
}
|
||||
}
|
||||
fallthrough
|
||||
case LB_LISTENER_TYPE_HTTP:
|
||||
case consts.LB_LISTENER_TYPE_HTTP:
|
||||
lblis.StickySession = extListener.GetStickySession()
|
||||
lblis.StickySessionType = extListener.GetStickySessionType()
|
||||
lblis.StickySessionCookie = extListener.GetStickySessionCookie()
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"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/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -36,12 +37,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
LB_CHARGE_TYPE_BY_TRAFFIC = "traffic"
|
||||
LB_CHARGE_TYPE_BY_BANDWIDTH = "bandwidth"
|
||||
LB_CHARGE_TYPE_BY_HOUR = "hour"
|
||||
)
|
||||
|
||||
// TODO build errors on pkg/httperrors/errors.go
|
||||
// NewGetManagerError
|
||||
// NewMissingArgumentError
|
||||
@@ -100,20 +95,20 @@ func (man *SLoadbalancerManager) ValidateCreateData(ctx context.Context, userCre
|
||||
addressType, _ := data.GetString("address_type")
|
||||
zoneV := validators.NewModelIdOrNameValidator("zone", "zone", "")
|
||||
managerIdV := validators.NewModelIdOrNameValidator("manager_id", "cloudprovider", "")
|
||||
if addressType == LB_ADDR_TYPE_INTERNET {
|
||||
if addressType == consts.LB_ADDR_TYPE_INTERNET {
|
||||
networkV.Optional(true)
|
||||
} else {
|
||||
zoneV.Optional(true)
|
||||
managerIdV.Optional(true)
|
||||
}
|
||||
addressV := validators.NewIPv4AddrValidator("address")
|
||||
addressTypeV := validators.NewStringChoicesValidator("address_type", LB_ADDR_TYPES)
|
||||
addressTypeV := validators.NewStringChoicesValidator("address_type", consts.LB_ADDR_TYPES)
|
||||
{
|
||||
keyV := map[string]validators.IValidator{
|
||||
"status": validators.NewStringChoicesValidator("status", LB_STATUS_SPEC).Default(LB_STATUS_ENABLED),
|
||||
"status": validators.NewStringChoicesValidator("status", consts.LB_STATUS_SPEC).Default(consts.LB_STATUS_ENABLED),
|
||||
|
||||
"address": addressV.Optional(true),
|
||||
"address_type": addressTypeV.Default(LB_ADDR_TYPE_INTRANET),
|
||||
"address_type": addressTypeV.Default(consts.LB_ADDR_TYPE_INTRANET),
|
||||
"network": networkV,
|
||||
"zone": zoneV,
|
||||
"manager_id": managerIdV,
|
||||
@@ -125,7 +120,7 @@ func (man *SLoadbalancerManager) ValidateCreateData(ctx context.Context, userCre
|
||||
}
|
||||
}
|
||||
var region *SCloudregion
|
||||
if addressTypeV.Value == LB_ADDR_TYPE_INTRANET {
|
||||
if addressTypeV.Value == consts.LB_ADDR_TYPE_INTRANET {
|
||||
network := networkV.Model.(*SNetwork)
|
||||
if ipAddr := addressV.IP; ipAddr != nil {
|
||||
ipS := ipAddr.String()
|
||||
@@ -168,8 +163,8 @@ func (man *SLoadbalancerManager) ValidateCreateData(ctx context.Context, userCre
|
||||
}
|
||||
data.Set("cloudregion_id", jsonutils.NewString(region.GetId()))
|
||||
// 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))
|
||||
data.Set("network_type", jsonutils.NewString(consts.LB_NETWORK_TYPE_CLASSIC))
|
||||
data.Set("address_type", jsonutils.NewString(consts.LB_ADDR_TYPE_INTRANET))
|
||||
} else {
|
||||
zone := zoneV.Model.(*SZone)
|
||||
region = zone.GetRegion()
|
||||
@@ -181,8 +176,8 @@ func (man *SLoadbalancerManager) ValidateCreateData(ctx context.Context, userCre
|
||||
data.Set("address", jsonutils.NewString(""))
|
||||
data.Set("network_id", jsonutils.NewString(""))
|
||||
data.Set("cloudregion_id", jsonutils.NewString(region.GetId()))
|
||||
data.Set("network_type", jsonutils.NewString(LB_NETWORK_TYPE_VPC))
|
||||
data.Set("address_type", jsonutils.NewString(LB_ADDR_TYPE_INTERNET))
|
||||
data.Set("network_type", jsonutils.NewString(consts.LB_NETWORK_TYPE_VPC))
|
||||
data.Set("address_type", jsonutils.NewString(consts.LB_ADDR_TYPE_INTERNET))
|
||||
}
|
||||
if _, err := man.SVirtualResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data); err != nil {
|
||||
return nil, err
|
||||
@@ -198,7 +193,7 @@ func (lb *SLoadbalancer) PerformStatus(ctx context.Context, userCred mcclient.To
|
||||
if _, err := lb.SVirtualResourceBase.PerformStatus(ctx, userCred, query, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if lb.Status == LB_STATUS_ENABLED {
|
||||
if lb.Status == consts.LB_STATUS_ENABLED {
|
||||
return nil, lb.StartLoadBalancerStartTask(ctx, userCred, "")
|
||||
}
|
||||
return nil, lb.StartLoadBalancerStopTask(ctx, userCred, "")
|
||||
@@ -233,7 +228,7 @@ func (lb *SLoadbalancer) PerformSyncstatus(ctx context.Context, userCred mcclien
|
||||
func (lb *SLoadbalancer) StartLoadBalancerSyncstatusTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(lb.Status), "origin_status")
|
||||
lb.SetStatus(userCred, LB_SYNC_STATUS, "")
|
||||
lb.SetStatus(userCred, consts.LB_SYNC_STATUS, "")
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerSyncstatusTask", lb, userCred, params, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -248,7 +243,7 @@ func (lb *SLoadbalancer) PostCreate(ctx context.Context, userCred mcclient.Token
|
||||
// NOTE this means lb.UpdateVersion will be 0, then 1 after creation
|
||||
// NOTE need ways to notify error
|
||||
|
||||
lb.SetStatus(userCred, LB_CREATING, "")
|
||||
lb.SetStatus(userCred, consts.LB_CREATING, "")
|
||||
if err := lb.StartLoadBalancerCreateTask(ctx, userCred, ""); err != nil {
|
||||
log.Errorf("Failed to create loadbalancer error: %v", err)
|
||||
}
|
||||
@@ -330,7 +325,7 @@ func (lb *SLoadbalancer) GetCreateLoadbalancerParams(iRegion cloudprovider.IClou
|
||||
}
|
||||
params.ZoneID = iZone.GetId()
|
||||
}
|
||||
if lb.AddressType == LB_ADDR_TYPE_INTRANET {
|
||||
if lb.AddressType == consts.LB_ADDR_TYPE_INTRANET {
|
||||
vpc := lb.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, fmt.Errorf("failed to find vpc for lb %s", lb.Name)
|
||||
@@ -416,7 +411,7 @@ 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 {
|
||||
lb.SetStatus(userCred, LB_STATUS_DELETING, "")
|
||||
lb.SetStatus(userCred, consts.LB_STATUS_DELETING, "")
|
||||
return lb.StartLoadBalancerDeleteTask(ctx, userCred, jsonutils.NewDict(), "")
|
||||
}
|
||||
|
||||
@@ -487,7 +482,7 @@ func (man *SLoadbalancerManager) SyncLoadbalancers(ctx context.Context, userCred
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].ValidateDeleteCondition(ctx)
|
||||
if err != nil { // cannot delete
|
||||
err = removed[i].SetStatus(userCred, LB_STATUS_UNKNOWN, "sync to delete")
|
||||
err = removed[i].SetStatus(userCred, consts.LB_STATUS_UNKNOWN, "sync to delete")
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
|
||||
@@ -5,13 +5,15 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"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 {
|
||||
@@ -44,14 +46,14 @@ func (self *SAliyunRegionDriver) ValidateUpdateLoadbalancerCertificateData(ctx c
|
||||
|
||||
func (self *SAliyunRegionDriver) ValidateDeleteLoadbalancerBackendCondition(ctx context.Context, lbb *models.SLoadbalancerBackend) error {
|
||||
backendGroup := lbb.GetLoadbalancerBackendGroup()
|
||||
if backendGroup.Type == models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE {
|
||||
if backendGroup.Type == consts.LB_BACKENDGROUP_TYPE_MASTER_SLAVE {
|
||||
return httperrors.NewUnsupportOperationError("backend %s belong master slave backendgroup, not allow delete", lbb.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAliyunRegionDriver) ValidateDeleteLoadbalancerBackendGroupCondition(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup) error {
|
||||
if lbbg.Type == models.LB_BACKENDGROUP_TYPE_DEFAULT {
|
||||
if lbbg.Type == consts.LB_BACKENDGROUP_TYPE_DEFAULT {
|
||||
return httperrors.NewUnsupportOperationError("not allow to delete default backend group")
|
||||
}
|
||||
return nil
|
||||
@@ -60,9 +62,9 @@ func (self *SAliyunRegionDriver) ValidateDeleteLoadbalancerBackendGroupCondition
|
||||
func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, lb *models.SLoadbalancer, backends []cloudprovider.SLoadbalancerBackend) (*jsonutils.JSONDict, error) {
|
||||
groupType, _ := data.GetString("type")
|
||||
switch groupType {
|
||||
case "", models.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
case "", consts.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
break
|
||||
case models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
case consts.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
if len(backends) != 2 {
|
||||
return nil, httperrors.NewInputParameterError("master slave backendgorup must contain two backend")
|
||||
}
|
||||
@@ -81,10 +83,10 @@ func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx
|
||||
}
|
||||
|
||||
func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerBackendData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, backendType string, lb *models.SLoadbalancer, backendGroup *models.SLoadbalancerBackendGroup, backend db.IModel) (*jsonutils.JSONDict, error) {
|
||||
if backendType != models.LB_BACKEND_GUEST {
|
||||
if backendType != consts.LB_BACKEND_GUEST {
|
||||
return nil, httperrors.NewUnsupportOperationError("internal error: unexpected backend type %s", backendType)
|
||||
}
|
||||
if !utils.IsInStringArray(backendGroup.Type, []string{models.LB_BACKENDGROUP_TYPE_DEFAULT, models.LB_BACKENDGROUP_TYPE_NORMAL}) {
|
||||
if !utils.IsInStringArray(backendGroup.Type, []string{consts.LB_BACKENDGROUP_TYPE_DEFAULT, consts.LB_BACKENDGROUP_TYPE_NORMAL}) {
|
||||
return nil, httperrors.NewUnsupportOperationError("backendgroup %s not support this operation", backendGroup.Name)
|
||||
}
|
||||
guest := backend.(*models.SGuest)
|
||||
@@ -118,7 +120,7 @@ func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerListenerRuleData(ctx
|
||||
if !ok {
|
||||
return nil, httperrors.NewMissingParameterError("backend_group")
|
||||
}
|
||||
if backendgroup.Type != models.LB_BACKENDGROUP_TYPE_NORMAL {
|
||||
if backendgroup.Type != consts.LB_BACKENDGROUP_TYPE_NORMAL {
|
||||
return nil, httperrors.NewInputParameterError("backend group type must be normal")
|
||||
}
|
||||
return data, nil
|
||||
@@ -130,7 +132,7 @@ func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerListenerData(ctx cont
|
||||
return nil, httperrors.NewMissingParameterError("backend_group")
|
||||
}
|
||||
listenerType, _ := data.GetString("listener_type")
|
||||
if utils.IsInStringArray(listenerType, []string{models.LB_LISTENER_TYPE_HTTP, models.LB_LISTENER_TYPE_HTTPS}) && !utils.IsInStringArray(backendgroup.Type, []string{models.LB_BACKENDGROUP_TYPE_DEFAULT, models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE}) {
|
||||
if utils.IsInStringArray(listenerType, []string{consts.LB_LISTENER_TYPE_HTTP, consts.LB_LISTENER_TYPE_HTTPS}) && !utils.IsInStringArray(backendgroup.Type, []string{consts.LB_BACKENDGROUP_TYPE_DEFAULT, consts.LB_BACKENDGROUP_TYPE_MASTER_SLAVE}) {
|
||||
return nil, httperrors.NewUnsupportOperationError("http or https listener only supportd default or master_slave backendgroup")
|
||||
}
|
||||
|
||||
@@ -154,11 +156,11 @@ func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerListenerData(ctx cont
|
||||
"health_check_timeout": validators.NewRangeValidator("health_check_timeout", 1, 300),
|
||||
"health_check_interval": validators.NewRangeValidator("health_check_interval", 1, 50),
|
||||
}
|
||||
if !utils.IsInStringArray(listenerType, []string{models.LB_LISTENER_TYPE_UDP, models.LB_LISTENER_TYPE_TCP}) {
|
||||
if !utils.IsInStringArray(listenerType, []string{consts.LB_LISTENER_TYPE_UDP, consts.LB_LISTENER_TYPE_TCP}) {
|
||||
keyV["client_idle_timeout"] = validators.NewRangeValidator("client_idle_timeout", 1, 60)
|
||||
}
|
||||
|
||||
if backendgroup.Type == models.LB_BACKENDGROUP_TYPE_DEFAULT {
|
||||
if backendgroup.Type == consts.LB_BACKENDGROUP_TYPE_DEFAULT {
|
||||
keyV["backend_server_port"] = validators.NewPortValidator("backend_server_port")
|
||||
}
|
||||
|
||||
@@ -192,11 +194,11 @@ func (self *SAliyunRegionDriver) ValidateUpdateLoadbalancerListenerData(ctx cont
|
||||
|
||||
backendgroup, ok := backendGroup.(*models.SLoadbalancerBackendGroup)
|
||||
if ok {
|
||||
if utils.IsInStringArray(listenerType, []string{models.LB_LISTENER_TYPE_HTTP, models.LB_LISTENER_TYPE_HTTPS}) && !utils.IsInStringArray(backendgroup.Type, []string{models.LB_BACKENDGROUP_TYPE_DEFAULT, models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE}) {
|
||||
if utils.IsInStringArray(listenerType, []string{consts.LB_LISTENER_TYPE_HTTP, consts.LB_LISTENER_TYPE_HTTPS}) && !utils.IsInStringArray(backendgroup.Type, []string{consts.LB_BACKENDGROUP_TYPE_DEFAULT, consts.LB_BACKENDGROUP_TYPE_MASTER_SLAVE}) {
|
||||
return nil, httperrors.NewUnsupportOperationError("http or https listener only supportd default or master_slave backendgroup")
|
||||
}
|
||||
|
||||
if backendgroup.Type == models.LB_BACKENDGROUP_TYPE_DEFAULT {
|
||||
if backendgroup.Type == consts.LB_BACKENDGROUP_TYPE_DEFAULT {
|
||||
keyV["backend_server_port"] = validators.NewPortValidator("backend_server_port")
|
||||
}
|
||||
|
||||
@@ -206,7 +208,7 @@ func (self *SAliyunRegionDriver) ValidateUpdateLoadbalancerListenerData(ctx cont
|
||||
}
|
||||
}
|
||||
|
||||
if !utils.IsInStringArray(listenerType, []string{models.LB_LISTENER_TYPE_UDP, models.LB_LISTENER_TYPE_TCP}) {
|
||||
if !utils.IsInStringArray(listenerType, []string{consts.LB_LISTENER_TYPE_UDP, consts.LB_LISTENER_TYPE_TCP}) {
|
||||
keyV["client_idle_timeout"] = validators.NewRangeValidator("client_idle_timeout", 1, 60)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"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/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
type SKVMRegionDriver struct {
|
||||
@@ -46,7 +48,7 @@ func (self *SKVMRegionDriver) ValidateUpdateLoadbalancerCertificateData(ctx cont
|
||||
func (self *SKVMRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, lb *models.SLoadbalancer, backends []cloudprovider.SLoadbalancerBackend) (*jsonutils.JSONDict, error) {
|
||||
for _, backend := range backends {
|
||||
switch backend.BackendType {
|
||||
case models.LB_BACKEND_GUEST:
|
||||
case consts.LB_BACKEND_GUEST:
|
||||
if backend.ZoneId != lb.ZoneId {
|
||||
return nil, fmt.Errorf("zone of host %q (%s) != zone of loadbalancer %q (%s)",
|
||||
backend.HostName, backend.ZoneId, lb.Name, lb.ZoneId)
|
||||
@@ -58,7 +60,7 @@ func (self *SKVMRegionDriver) ValidateCreateLoadbalancerBackendGroupData(ctx con
|
||||
|
||||
func (self *SKVMRegionDriver) ValidateCreateLoadbalancerBackendData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, backendType string, lb *models.SLoadbalancer, backendGroup *models.SLoadbalancerBackendGroup, backend db.IModel) (*jsonutils.JSONDict, error) {
|
||||
switch backendType {
|
||||
case models.LB_BACKEND_GUEST:
|
||||
case consts.LB_BACKEND_GUEST:
|
||||
guest := backend.(*models.SGuest)
|
||||
{
|
||||
// guest zone must match that of loadbalancer's
|
||||
@@ -104,7 +106,7 @@ func (self *SKVMRegionDriver) ValidateUpdateLoadbalancerListenerData(ctx context
|
||||
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 {
|
||||
if lb.AddressType == consts.LB_ADDR_TYPE_INTRANET {
|
||||
// TODO support use reserved ip address
|
||||
// TODO prefer ip address from server_type loadbalancer?
|
||||
req := &models.SLoadbalancerNetworkRequestData{
|
||||
@@ -140,10 +142,10 @@ func (self *SKVMRegionDriver) RequestStopLoadbalancer(ctx context.Context, userC
|
||||
|
||||
func (self *SKVMRegionDriver) RequestSyncstatusLoadbalancer(ctx context.Context, userCred mcclient.TokenCredential, lb *models.SLoadbalancer, task taskman.ITask) error {
|
||||
originStatus, _ := task.GetParams().GetString("origin_status")
|
||||
if utils.IsInStringArray(originStatus, []string{models.LB_STATUS_ENABLED, models.LB_STATUS_DISABLED}) {
|
||||
if utils.IsInStringArray(originStatus, []string{consts.LB_STATUS_ENABLED, consts.LB_STATUS_DISABLED}) {
|
||||
lb.SetStatus(userCred, originStatus, "")
|
||||
} else {
|
||||
lb.SetStatus(userCred, models.LB_STATUS_ENABLED, "")
|
||||
lb.SetStatus(userCred, consts.LB_STATUS_ENABLED, "")
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
@@ -191,7 +193,7 @@ func (self *SKVMRegionDriver) RequestCreateLoadbalancerBackendGroup(ctx context.
|
||||
Address: backend.Address,
|
||||
Port: backend.Port,
|
||||
}
|
||||
loadbalancerBackend.Status = models.LB_STATUS_ENABLED
|
||||
loadbalancerBackend.Status = consts.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 {
|
||||
@@ -248,10 +250,10 @@ func (self *SKVMRegionDriver) RequestStopLoadbalancerListener(ctx context.Contex
|
||||
|
||||
func (self *SKVMRegionDriver) RequestSyncstatusLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lblis *models.SLoadbalancerListener, task taskman.ITask) error {
|
||||
originStatus, _ := task.GetParams().GetString("origin_status")
|
||||
if utils.IsInStringArray(originStatus, []string{models.LB_STATUS_ENABLED, models.LB_STATUS_DISABLED}) {
|
||||
if utils.IsInStringArray(originStatus, []string{consts.LB_STATUS_ENABLED, consts.LB_STATUS_DISABLED}) {
|
||||
lblis.SetStatus(userCred, originStatus, "")
|
||||
} else {
|
||||
lblis.SetStatus(userCred, models.LB_STATUS_ENABLED, "")
|
||||
lblis.SetStatus(userCred, consts.LB_STATUS_ENABLED, "")
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
|
||||
@@ -6,14 +6,16 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"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/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"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 SManagedVirtualizationRegionDriver struct {
|
||||
@@ -53,7 +55,7 @@ func (self *SManagedVirtualizationRegionDriver) ValidateUpdateLoadbalancerCertif
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizationRegionDriver) ValidateCreateLoadbalancerBackendData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, backendType string, lb *models.SLoadbalancer, backendGroup *models.SLoadbalancerBackendGroup, backend db.IModel) (*jsonutils.JSONDict, error) {
|
||||
if backendType != models.LB_BACKEND_GUEST {
|
||||
if backendType != consts.LB_BACKEND_GUEST {
|
||||
return nil, httperrors.NewUnsupportOperationError("internal error: unexpected backend type %s", backendType)
|
||||
}
|
||||
guest := backend.(*models.SGuest)
|
||||
@@ -184,7 +186,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestSyncstatusLoadbalancer(ct
|
||||
return nil, err
|
||||
}
|
||||
status := iLoadbalancer.GetStatus()
|
||||
if utils.IsInStringArray(status, []string{models.LB_STATUS_ENABLED, models.LB_STATUS_DISABLED}) {
|
||||
if utils.IsInStringArray(status, []string{consts.LB_STATUS_ENABLED, consts.LB_STATUS_DISABLED}) {
|
||||
return nil, lb.SetStatus(userCred, status, "")
|
||||
}
|
||||
return nil, fmt.Errorf("Unknown loadbalancer status %s", status)
|
||||
@@ -626,7 +628,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestSyncstatusLoadbalancerLis
|
||||
return nil, err
|
||||
}
|
||||
status := iListener.GetStatus()
|
||||
if utils.IsInStringArray(status, []string{models.LB_STATUS_ENABLED, models.LB_STATUS_DISABLED}) {
|
||||
if utils.IsInStringArray(status, []string{consts.LB_STATUS_ENABLED, consts.LB_STATUS_DISABLED}) {
|
||||
return nil, lblis.SetStatus(userCred, status, "")
|
||||
}
|
||||
return nil, fmt.Errorf("Unknown loadbalancer listener status %s", status)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason string) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_CREATE_FAILED, reason)
|
||||
lbacl.SetStatus(self.GetUserCred(), consts.LB_CREATE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_ALLOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_CREATE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, models.LB_CREATE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, consts.LB_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerAclCreateTask) OnInit(ctx context.Context, obj db.IStand
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclCreateTask) OnLoadbalancerAclCreateComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lbacl.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_ALLOCATE, lbacl.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclDeleteTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason string) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
lbacl.SetStatus(self.GetUserCred(), consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_DELOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_DELETE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, models.LB_STATUS_DELETE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerAcl, reason string) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_SYNC_CONF_FAILED, reason)
|
||||
lbacl.SetStatus(self.GetUserCred(), consts.LB_SYNC_CONF_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_SYNC_CONF, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_SYNC_CONF, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, models.LB_SYNC_CONF_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, consts.LB_SYNC_CONF_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerAclSyncTask) OnInit(ctx context.Context, obj db.IStandal
|
||||
}
|
||||
|
||||
func (self *LoadbalancerAclSyncTask) OnLoadbalancerAclSyncComplete(ctx context.Context, lbacl *models.SLoadbalancerAcl, data jsonutils.JSONObject) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lbacl.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_SYNC_CONF, lbacl.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_SYNC_CONF, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendCreateTask) taskFail(ctx context.Context, lbb *models.SLoadbalancerBackend, reason string) {
|
||||
lbb.SetStatus(self.GetUserCred(), models.LB_CREATE_FAILED, reason)
|
||||
lbb.SetStatus(self.GetUserCred(), consts.LB_CREATE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbb, db.ACT_ALLOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbb, logclient.ACT_CREATE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbb.Id, lbb.Name, models.LB_CREATE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbb.Id, lbb.Name, consts.LB_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerBackendCreateTask) OnInit(ctx context.Context, obj db.IS
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendCreateTask) OnLoadbalancerBackendCreateComplete(ctx context.Context, lbb *models.SLoadbalancerBackend, data jsonutils.JSONObject) {
|
||||
lbb.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lbb.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lbb, db.ACT_ALLOCATE, lbb.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbb, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
@@ -20,7 +21,7 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendDeleteTask) taskFail(ctx context.Context, lbb *models.SLoadbalancerBackend, reason string) {
|
||||
lbb.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
lbb.SetStatus(self.GetUserCred(), consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -23,10 +24,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) taskFail(ctx context.Context, lbacl *models.SLoadbalancerBackendGroup, reason string) {
|
||||
lbacl.SetStatus(self.GetUserCred(), models.LB_CREATE_FAILED, reason)
|
||||
lbacl.SetStatus(self.GetUserCred(), consts.LB_CREATE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbacl, db.ACT_ALLOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_CREATE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, models.LB_CREATE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, consts.LB_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) OnInit(ctx context.C
|
||||
}
|
||||
|
||||
func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) OnLoadbalancerBackendGroupCreateComplete(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup, data jsonutils.JSONObject) {
|
||||
lbbg.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lbbg.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lbbg, db.ACT_ALLOCATE, lbbg.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbbg, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerBackendGroupDeleteTask) taskFail(ctx context.Context, lbbg *models.SLoadbalancerBackendGroup, reason string) {
|
||||
lbbg.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
lbbg.SetStatus(self.GetUserCred(), consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbbg, db.ACT_DELOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbbg, logclient.ACT_DELETE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbbg.Id, lbbg.Name, models.LB_STATUS_DELETE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbbg.Id, lbbg.Name, consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) taskFail(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason string) {
|
||||
lbcert.SetStatus(self.GetUserCred(), models.LB_CREATE_FAILED, reason)
|
||||
lbcert.SetStatus(self.GetUserCred(), consts.LB_CREATE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_ALLOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_CREATE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbcert.Id, lbcert.Name, models.LB_CREATE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbcert.Id, lbcert.Name, consts.LB_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerCertificateCreateTask) OnInit(ctx context.Context, obj d
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateCreateTask) OnLoadbalancerCertificateCreateComplete(ctx context.Context, lbcert *models.SLoadbalancerCertificate, data jsonutils.JSONObject) {
|
||||
lbcert.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lbcert.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_ALLOCATE, lbcert.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCertificateDeleteTask) taskFail(ctx context.Context, lbcert *models.SLoadbalancerCertificate, reason string) {
|
||||
lbcert.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
lbcert.SetStatus(self.GetUserCred(), consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbcert, db.ACT_DELOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_DELETE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbcert.Id, lbcert.Name, models.LB_STATUS_DELETE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbcert.Id, lbcert.Name, consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason string) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_CREATE_FAILED, reason)
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_CREATE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lb, db.ACT_ALLOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_CREATE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, models.LB_CREATE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, consts.LB_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerCreateTask) OnInit(ctx context.Context, obj db.IStandalo
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) OnLoadbalancerCreateComplete(ctx context.Context, lb *models.SLoadbalancer, data jsonutils.JSONObject) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lb, db.ACT_ALLOCATE, lb.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStage("OnLoadbalancerStartComplete", nil)
|
||||
@@ -55,11 +56,11 @@ func (self *LoadbalancerCreateTask) OnLoadbalancerCreateCompleteFailed(ctx conte
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) OnLoadbalancerStartComplete(ctx context.Context, lb *models.SLoadbalancer, data jsonutils.JSONObject) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerCreateTask) OnLoadbalancerStartCompleteFailed(ctx context.Context, lb *models.SLoadbalancer, reason jsonutils.JSONObject) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_DISABLED, reason.String())
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_DISABLED, reason.String())
|
||||
self.SetStageFailed(ctx, reason.String())
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerDeleteTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason string) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lb, db.ACT_DELOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_DELETE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, models.LB_STATUS_DELETE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_CREATE_FAILED, reason)
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_CREATE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_ALLOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_CREATE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, models.LB_CREATE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, consts.LB_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerListenerCreateTask) OnInit(ctx context.Context, obj db.I
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) OnLoadbalancerListenerCreateComplete(ctx context.Context, lblis *models.SLoadbalancerListener, data jsonutils.JSONObject) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_ALLOCATE, lblis.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStage("OnLoadbalancerListenerStartComplete", nil)
|
||||
@@ -55,11 +56,11 @@ func (self *LoadbalancerListenerCreateTask) OnLoadbalancerListenerCreateComplete
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) OnLoadbalancerListenerStartComplete(ctx context.Context, lblis *models.SLoadbalancerListener, data jsonutils.JSONObject) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateTask) OnLoadbalancerListenerStartCompleteFailed(ctx context.Context, lblis *models.SLoadbalancerListener, reason jsonutils.JSONObject) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_DISABLED, reason.String())
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_DISABLED, reason.String())
|
||||
self.SetStageFailed(ctx, reason.String())
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerDeleteTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_DELOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_DELETE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, models.LB_STATUS_DELETE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerRuleCreateTask) taskFail(ctx context.Context, lbr *models.SLoadbalancerListenerRule, reason string) {
|
||||
lbr.SetStatus(self.GetUserCred(), models.LB_CREATE_FAILED, reason)
|
||||
lbr.SetStatus(self.GetUserCred(), consts.LB_CREATE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbr, db.ACT_ALLOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbr, logclient.ACT_CREATE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbr.Id, lbr.Name, models.LB_CREATE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbr.Id, lbr.Name, consts.LB_CREATE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerListenerRuleCreateTask) OnInit(ctx context.Context, obj
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerRuleCreateTask) OnLoadbalancerListenerRuleCreateComplete(ctx context.Context, lbr *models.SLoadbalancerListenerRule, data jsonutils.JSONObject) {
|
||||
lbr.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lbr.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lbr, db.ACT_ALLOCATE, lbr.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbr, logclient.ACT_CREATE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerRuleDeleteTask) taskFail(ctx context.Context, lbr *models.SLoadbalancerListenerRule, reason string) {
|
||||
lbr.SetStatus(self.GetUserCred(), models.LB_STATUS_DELETE_FAILED, reason)
|
||||
lbr.SetStatus(self.GetUserCred(), consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lbr, db.ACT_DELOCATE_FAIL, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lbr, logclient.ACT_DELETE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lbr.Id, lbr.Name, models.LB_STATUS_DELETE_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lbr.Id, lbr.Name, consts.LB_STATUS_DELETE_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerStartTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_DISABLED, reason)
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_DISABLED, reason)
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_ENABLE, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_ENABLE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, models.LB_STATUS_DISABLED, reason)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, consts.LB_STATUS_DISABLED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerListenerStartTask) OnInit(ctx context.Context, obj db.IS
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerStartTask) OnLoadbalancerListenerStartComplete(ctx context.Context, lblis *models.SLoadbalancerListener, data jsonutils.JSONObject) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_ENABLE, lblis.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_ENABLE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerStopTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, reason)
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, reason)
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_DISABLE, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_DISABLE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, models.LB_STATUS_ENABLED, reason)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, consts.LB_STATUS_ENABLED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerListenerStopTask) OnInit(ctx context.Context, obj db.ISt
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerStopTask) OnLoadbalancerListenerStopComplete(ctx context.Context, lblis *models.SLoadbalancerListener, data jsonutils.JSONObject) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_DISABLED, "")
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_DISABLED, "")
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_DISABLE, lblis.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_DISABLE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerSyncTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_SYNC_CONF_FAILED, reason)
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_SYNC_CONF_FAILED, reason)
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_SYNC_CONF, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_SYNC_CONF, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, models.LB_SYNC_CONF_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, consts.LB_SYNC_CONF_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -58,6 +59,6 @@ func (self *LoadbalancerListenerSyncTask) OnLoadbalancerListenerSyncStatusComple
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerSyncTask) OnLoadbalancerListenerSyncStatusCompleteFailed(ctx context.Context, lblis *models.SLoadbalancerListener, reason jsonutils.JSONObject) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_UNKNOWN, reason.String())
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_UNKNOWN, reason.String())
|
||||
self.SetStageFailed(ctx, reason.String())
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerSyncstatusTask) taskFail(ctx context.Context, lblis *models.SLoadbalancerListener, reason string) {
|
||||
lblis.SetStatus(self.GetUserCred(), models.LB_STATUS_UNKNOWN, reason)
|
||||
lblis.SetStatus(self.GetUserCred(), consts.LB_STATUS_UNKNOWN, reason)
|
||||
db.OpsLog.LogEvent(lblis, db.ACT_SYNC_STATUS, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_SYNC_STATUS, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, models.LB_SYNC_CONF_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lblis.Id, lblis.Name, consts.LB_SYNC_CONF_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerStartTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason string) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_DISABLED, reason)
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_DISABLED, reason)
|
||||
db.OpsLog.LogEvent(lb, db.ACT_ENABLE, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_ENABLE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, models.LB_STATUS_DISABLED, reason)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, consts.LB_STATUS_DISABLED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerStartTask) OnInit(ctx context.Context, obj db.IStandalon
|
||||
}
|
||||
|
||||
func (self *LoadbalancerStartTask) OnLoadbalancerStartComplete(ctx context.Context, lb *models.SLoadbalancer, data jsonutils.JSONObject) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, "")
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, "")
|
||||
db.OpsLog.LogEvent(lb, db.ACT_ENABLE, lb.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_ENABLE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerStopTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason string) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_ENABLED, reason)
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_ENABLED, reason)
|
||||
db.OpsLog.LogEvent(lb, db.ACT_DISABLE, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_DISABLE, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, models.LB_STATUS_ENABLED, reason)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, consts.LB_STATUS_ENABLED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (self *LoadbalancerStopTask) OnInit(ctx context.Context, obj db.IStandalone
|
||||
}
|
||||
|
||||
func (self *LoadbalancerStopTask) OnLoadbalancerStopComplete(ctx context.Context, lb *models.SLoadbalancer, data jsonutils.JSONObject) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_DISABLED, "")
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_DISABLED, "")
|
||||
db.OpsLog.LogEvent(lb, db.ACT_DISABLE, lb.GetShortDesc(ctx), self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_DISABLE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
@@ -22,10 +23,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (self *LoadbalancerSyncstatusTask) taskFail(ctx context.Context, lb *models.SLoadbalancer, reason string) {
|
||||
lb.SetStatus(self.GetUserCred(), models.LB_STATUS_UNKNOWN, reason)
|
||||
lb.SetStatus(self.GetUserCred(), consts.LB_STATUS_UNKNOWN, reason)
|
||||
db.OpsLog.LogEvent(lb, db.ACT_SYNC_STATUS, reason, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, lb, logclient.ACT_SYNC_STATUS, reason, self.UserCred, false)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, models.LB_SYNC_CONF_FAILED, reason)
|
||||
notifyclient.NotifySystemError(lb.Id, lb.Name, consts.LB_SYNC_CONF_FAILED, reason)
|
||||
self.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -54,8 +54,8 @@ func NewBackend(s string, index int) (*SBackend, error) {
|
||||
}
|
||||
backend.Port = port
|
||||
case "backend_type":
|
||||
if utils.IsInStringArray(value[1], []string{models.LB_BACKEND_GUEST, models.LB_BACKEND_HOST}) {
|
||||
return nil, fmt.Errorf("invalid backend type %s only support %s %s", value[1], models.LB_BACKEND_GUEST, models.LB_BACKEND_HOST)
|
||||
if utils.IsInStringArray(value[1], []string{consts.LB_BACKEND_GUEST, consts.LB_BACKEND_HOST}) {
|
||||
return nil, fmt.Errorf("invalid backend type %s only support %s %s", value[1], consts.LB_BACKEND_GUEST, consts.LB_BACKEND_HOST)
|
||||
}
|
||||
backend.BackendType = value[1]
|
||||
case "id":
|
||||
|
||||
@@ -6,8 +6,9 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type ListenerProtocol string
|
||||
@@ -77,9 +78,9 @@ func (lb *SLoadbalancer) GetGlobalId() string {
|
||||
|
||||
func (lb *SLoadbalancer) GetStatus() string {
|
||||
if lb.LoadBalancerStatus == "active" {
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
}
|
||||
return models.LB_STATUS_DISABLED
|
||||
return consts.LB_STATUS_DISABLED
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetMetadata() *jsonutils.JSONDict {
|
||||
@@ -194,14 +195,14 @@ func (lb *SLoadbalancer) GetILoadBalancerBackendGroups() ([]cloudprovider.ICloud
|
||||
|
||||
func (lb *SLoadbalancer) CreateILoadBalancerBackendGroup(group *cloudprovider.SLoadbalancerBackendGroup) (cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
switch group.GroupType {
|
||||
case models.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
case consts.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
group, err := lb.region.CreateLoadbalancerBackendGroup(group.Name, lb.LoadBalancerId, group.Backends)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group.lb = lb
|
||||
return group, nil
|
||||
case models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
case consts.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
group, err := lb.region.CreateLoadbalancerMasterSlaveBackendGroup(group.Name, lb.LoadBalancerId, group.Backends)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -215,13 +216,13 @@ func (lb *SLoadbalancer) CreateILoadBalancerBackendGroup(group *cloudprovider.SL
|
||||
|
||||
func (lb *SLoadbalancer) CreateILoadBalancerListener(listener *cloudprovider.SLoadbalancerListener) (cloudprovider.ICloudLoadbalancerListener, error) {
|
||||
switch listener.ListenerType {
|
||||
case models.LB_LISTENER_TYPE_TCP:
|
||||
case consts.LB_LISTENER_TYPE_TCP:
|
||||
return lb.region.CreateLoadbalancerTCPListener(lb, listener)
|
||||
case models.LB_LISTENER_TYPE_UDP:
|
||||
case consts.LB_LISTENER_TYPE_UDP:
|
||||
return lb.region.CreateLoadbalancerUDPListener(lb, listener)
|
||||
case models.LB_LISTENER_TYPE_HTTP:
|
||||
case consts.LB_LISTENER_TYPE_HTTP:
|
||||
return lb.region.CreateLoadbalancerHTTPListener(lb, listener)
|
||||
case models.LB_LISTENER_TYPE_HTTPS:
|
||||
case consts.LB_LISTENER_TYPE_HTTPS:
|
||||
return lb.region.CreateLoadbalancerHTTPSListener(lb, listener)
|
||||
}
|
||||
return nil, fmt.Errorf("unsupport listener type %s", listener.ListenerType)
|
||||
@@ -237,9 +238,9 @@ func (lb *SLoadbalancer) GetLoadbalancerSpec() string {
|
||||
func (lb *SLoadbalancer) GetChargeType() string {
|
||||
switch lb.InternetChargeType {
|
||||
case "paybybandwidth":
|
||||
return models.LB_CHARGE_TYPE_BY_BANDWIDTH
|
||||
return consts.LB_CHARGE_TYPE_BY_BANDWIDTH
|
||||
case "paybytraffic":
|
||||
return models.LB_CHARGE_TYPE_BY_TRAFFIC
|
||||
return consts.LB_CHARGE_TYPE_BY_TRAFFIC
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerBackend struct {
|
||||
@@ -62,11 +62,11 @@ func (backend *SLoadbalancerBackend) GetPort() int {
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerBackend) GetBackendType() string {
|
||||
return models.LB_BACKEND_GUEST
|
||||
return consts.LB_BACKEND_GUEST
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerBackend) GetBackendRole() string {
|
||||
return models.LB_BACKEND_ROLE_DEFAULT
|
||||
return consts.LB_BACKEND_ROLE_DEFAULT
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerBackend) GetBackendId() string {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type Rule struct {
|
||||
@@ -54,7 +54,7 @@ func (backendgroup *SLoadbalancerBackendGroup) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) GetStatus() string {
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) IsDefault() bool {
|
||||
@@ -62,7 +62,7 @@ func (backendgroup *SLoadbalancerBackendGroup) IsDefault() bool {
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) GetType() string {
|
||||
return models.LB_BACKENDGROUP_TYPE_NORMAL
|
||||
return consts.LB_BACKENDGROUP_TYPE_NORMAL
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) GetMetadata() *jsonutils.JSONDict {
|
||||
|
||||
@@ -4,7 +4,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerDefaultBackend struct {
|
||||
@@ -51,11 +52,11 @@ func (backend *SLoadbalancerDefaultBackend) GetPort() int {
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerDefaultBackend) GetBackendType() string {
|
||||
return models.LB_BACKEND_GUEST
|
||||
return consts.LB_BACKEND_GUEST
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerDefaultBackend) GetBackendRole() string {
|
||||
return models.LB_BACKEND_ROLE_DEFAULT
|
||||
return consts.LB_BACKEND_ROLE_DEFAULT
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerDefaultBackend) GetBackendId() string {
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerDefaultBackendGroup struct {
|
||||
@@ -25,7 +26,7 @@ func (backendgroup *SLoadbalancerDefaultBackendGroup) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) GetStatus() string {
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) IsDefault() bool {
|
||||
@@ -33,7 +34,7 @@ func (backendgroup *SLoadbalancerDefaultBackendGroup) IsDefault() bool {
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) GetType() string {
|
||||
return models.LB_BACKENDGROUP_TYPE_DEFAULT
|
||||
return consts.LB_BACKENDGROUP_TYPE_DEFAULT
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) GetMetadata() *jsonutils.JSONDict {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerHTTPListener struct {
|
||||
@@ -78,11 +78,11 @@ func (listerner *SLoadbalancerHTTPListener) GetGlobalId() string {
|
||||
func (listerner *SLoadbalancerHTTPListener) GetStatus() string {
|
||||
switch listerner.Status {
|
||||
case "starting", "running":
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
case "configuring", "stopping", "stopped":
|
||||
return models.LB_STATUS_DISABLED
|
||||
return consts.LB_STATUS_DISABLED
|
||||
default:
|
||||
return models.LB_STATUS_UNKNOWN
|
||||
return consts.LB_STATUS_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ func (listerner *SLoadbalancerHTTPListener) CreateILoadBalancerListenerRule(rule
|
||||
Url: rule.Path,
|
||||
RuleName: rule.Name,
|
||||
}
|
||||
if len(rule.BackendGroupID) > 0 { //&& rule.BackendGroupType == models.LB_BACKENDGROUP_TYPE_NORMAL {
|
||||
if len(rule.BackendGroupID) > 0 { //&& rule.BackendGroupType == consts.LB_BACKENDGROUP_TYPE_NORMAL {
|
||||
_rule.VServerGroupId = rule.BackendGroupID
|
||||
}
|
||||
listenerRule, err := listerner.lb.region.CreateLoadbalancerListenerRule(listerner.ListenerPort, listerner.lb.LoadBalancerId, _rule)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerHTTPSListener struct {
|
||||
@@ -73,11 +73,11 @@ func (listerner *SLoadbalancerHTTPSListener) GetGlobalId() string {
|
||||
func (listerner *SLoadbalancerHTTPSListener) GetStatus() string {
|
||||
switch listerner.Status {
|
||||
case "starting", "running":
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
case "configuring", "stopping", "stopped":
|
||||
return models.LB_STATUS_DISABLED
|
||||
return consts.LB_STATUS_DISABLED
|
||||
default:
|
||||
return models.LB_STATUS_UNKNOWN
|
||||
return consts.LB_STATUS_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ func (listerner *SLoadbalancerHTTPSListener) CreateILoadBalancerListenerRule(rul
|
||||
Url: rule.Path,
|
||||
RuleName: rule.Name,
|
||||
}
|
||||
if len(rule.BackendGroupID) > 0 { //&& rule.BackendGroupType == models.LB_BACKENDGROUP_TYPE_NORMAL {
|
||||
if len(rule.BackendGroupID) > 0 { //&& rule.BackendGroupType == consts.LB_BACKENDGROUP_TYPE_NORMAL {
|
||||
_rule.VServerGroupId = rule.BackendGroupID
|
||||
}
|
||||
listenerRule, err := listerner.lb.region.CreateLoadbalancerListenerRule(listerner.ListenerPort, listerner.lb.LoadBalancerId, _rule)
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerMasterSlaveBackend struct {
|
||||
@@ -54,7 +55,7 @@ func (backend *SLoadbalancerMasterSlaveBackend) GetPort() int {
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerMasterSlaveBackend) GetBackendType() string {
|
||||
return models.LB_BACKEND_GUEST
|
||||
return consts.LB_BACKEND_GUEST
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerMasterSlaveBackend) GetBackendRole() string {
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerMasterSlaveBackendGroup struct {
|
||||
@@ -28,7 +29,7 @@ func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) GetStatus() string {
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) GetMetadata() *jsonutils.JSONDict {
|
||||
@@ -48,7 +49,7 @@ func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) IsDefault() bool {
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) GetType() string {
|
||||
return models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE
|
||||
return consts.LB_BACKENDGROUP_TYPE_MASTER_SLAVE
|
||||
}
|
||||
|
||||
func (region *SRegion) GetLoadbalancerMasterSlaveBackendgroups(loadbalancerId string) ([]SLoadbalancerMasterSlaveBackendGroup, error) {
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerTCPListener struct {
|
||||
@@ -56,11 +57,11 @@ func (listerner *SLoadbalancerTCPListener) GetGlobalId() string {
|
||||
func (listerner *SLoadbalancerTCPListener) GetStatus() string {
|
||||
switch listerner.Status {
|
||||
case "starting", "running":
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
case "configuring", "stopping", "stopped":
|
||||
return models.LB_STATUS_DISABLED
|
||||
return consts.LB_STATUS_DISABLED
|
||||
default:
|
||||
return models.LB_STATUS_UNKNOWN
|
||||
return consts.LB_STATUS_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,11 +238,11 @@ func (region *SRegion) constructBaseCreateListenerParams(lb *SLoadbalancer, list
|
||||
params["AclType"] = listener.AccessControlListType
|
||||
}
|
||||
switch listener.BackendGroupType {
|
||||
case models.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
case consts.LB_BACKENDGROUP_TYPE_NORMAL:
|
||||
params["VServerGroupId"] = listener.BackendGroupID
|
||||
case models.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
case consts.LB_BACKENDGROUP_TYPE_MASTER_SLAVE:
|
||||
params["MasterSlaveServerGroupId"] = listener.BackendGroupID
|
||||
case models.LB_BACKENDGROUP_TYPE_DEFAULT:
|
||||
case consts.LB_BACKENDGROUP_TYPE_DEFAULT:
|
||||
params["BackendServerPort"] = fmt.Sprintf("%d", listener.BackendServerPort)
|
||||
}
|
||||
if len(listener.Name) > 0 {
|
||||
@@ -251,7 +252,7 @@ func (region *SRegion) constructBaseCreateListenerParams(lb *SLoadbalancer, list
|
||||
params["EstablishedTimeout"] = fmt.Sprintf("%d", listener.EstablishedTimeout)
|
||||
}
|
||||
|
||||
if utils.IsInStringArray(listener.ListenerType, []string{models.LB_LISTENER_TYPE_TCP, models.LB_LISTENER_TYPE_UDP}) {
|
||||
if utils.IsInStringArray(listener.ListenerType, []string{consts.LB_LISTENER_TYPE_TCP, consts.LB_LISTENER_TYPE_UDP}) {
|
||||
if listener.HealthCheckTimeout >= 1 && listener.HealthCheckTimeout <= 300 {
|
||||
params["HealthCheckConnectTimeout"] = fmt.Sprintf("%d", listener.HealthCheckTimeout)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLoadbalancerUDPListener struct {
|
||||
@@ -55,11 +56,11 @@ func (listerner *SLoadbalancerUDPListener) GetGlobalId() string {
|
||||
func (listerner *SLoadbalancerUDPListener) GetStatus() string {
|
||||
switch listerner.Status {
|
||||
case "starting", "running":
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
case "configuring", "stopping", "stopped":
|
||||
return models.LB_STATUS_DISABLED
|
||||
return consts.LB_STATUS_DISABLED
|
||||
default:
|
||||
return models.LB_STATUS_UNKNOWN
|
||||
return consts.LB_STATUS_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
@@ -847,7 +848,7 @@ func (region *SRegion) CreateILoadBalancer(loadbalancer *cloudprovider.SLoadbala
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iLoadbalancer, cloudprovider.WaitStatus(iLoadbalancer, models.LB_STATUS_ENABLED, time.Second*5, time.Minute*5)
|
||||
return iLoadbalancer, cloudprovider.WaitStatus(iLoadbalancer, consts.LB_STATUS_ENABLED, time.Second*5, time.Minute*5)
|
||||
}
|
||||
|
||||
func (region *SRegion) AddAccessControlListEntry(aclId string, entrys []cloudprovider.SLoadbalancerAccessControlListEntry) error {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package validators
|
||||
package choices
|
||||
|
||||
import (
|
||||
"strings"
|
||||
@@ -0,0 +1 @@
|
||||
package choices // import "yunion.io/x/onecloud/pkg/util/choices"
|
||||
@@ -8,8 +8,9 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -57,7 +58,7 @@ func (self *SLoadbalancer) GetLoadbalancerSpec() string {
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetChargeType() string {
|
||||
return models.LB_CHARGE_TYPE_BY_HOUR
|
||||
return consts.LB_CHARGE_TYPE_BY_HOUR
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/product/214/30689
|
||||
@@ -124,7 +125,7 @@ func onecloudHealthCodeToQcloud(codes string) int {
|
||||
// 应用型负载均衡 https监听默认开启SNI。传统型不支持设置SNI
|
||||
func (self *SLoadbalancer) CreateILoadBalancerListener(listener *cloudprovider.SLoadbalancerListener) (cloudprovider.ICloudLoadbalancerListener, error) {
|
||||
sniSwitch := 0
|
||||
if listener.ListenerType == models.LB_LISTENER_TYPE_HTTPS {
|
||||
if listener.ListenerType == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
sniSwitch = 1
|
||||
}
|
||||
|
||||
@@ -201,11 +202,11 @@ func (self *SLoadbalancer) GetGlobalId() string {
|
||||
func (self *SLoadbalancer) GetStatus() string {
|
||||
switch self.Status {
|
||||
case 0:
|
||||
return models.LB_STATUS_INIT
|
||||
return consts.LB_STATUS_INIT
|
||||
case 1:
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
default:
|
||||
return models.LB_STATUS_UNKNOWN
|
||||
return consts.LB_STATUS_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,16 +241,16 @@ func (self *SLoadbalancer) GetAddress() string {
|
||||
func (self *SLoadbalancer) GetAddressType() string {
|
||||
switch self.LoadBalancerType {
|
||||
case LB_ADDR_TYPE_INTERNAL:
|
||||
return models.LB_ADDR_TYPE_INTRANET
|
||||
return consts.LB_ADDR_TYPE_INTRANET
|
||||
case LB_ADDR_TYPE_OPEN:
|
||||
return models.LB_ADDR_TYPE_INTERNET
|
||||
return consts.LB_ADDR_TYPE_INTERNET
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetNetworkType() string {
|
||||
return models.LB_NETWORK_TYPE_VPC
|
||||
return consts.LB_NETWORK_TYPE_VPC
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetNetworkId() string {
|
||||
@@ -302,7 +303,7 @@ func (self *SLoadbalancer) GetILoadBalancerBackendGroups() ([]cloudprovider.IClo
|
||||
for i := range listeners {
|
||||
listener := listeners[i]
|
||||
t := listener.GetListenerType()
|
||||
if t == models.LB_LISTENER_TYPE_HTTP || t == models.LB_LISTENER_TYPE_HTTPS {
|
||||
if t == consts.LB_LISTENER_TYPE_HTTP || t == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
rules := listener.Rules
|
||||
for i := range rules {
|
||||
rule := rules[i]
|
||||
|
||||
@@ -2,7 +2,8 @@ package qcloud
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
// 腾讯云没有LB ACL
|
||||
@@ -21,7 +22,7 @@ func (self *SLBACL) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SLBACL) GetStatus() string {
|
||||
return models.LB_BOOL_OFF
|
||||
return consts.LB_BOOL_OFF
|
||||
}
|
||||
|
||||
func (self *SLBACL) Refresh() error {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLBBackend struct {
|
||||
@@ -88,11 +88,11 @@ func (self *SLBBackend) GetPort() int {
|
||||
}
|
||||
|
||||
func (self *SLBBackend) GetBackendType() string {
|
||||
return models.LB_BACKEND_GUEST
|
||||
return consts.LB_BACKEND_GUEST
|
||||
}
|
||||
|
||||
func (self *SLBBackend) GetBackendRole() string {
|
||||
return models.LB_BACKEND_ROLE_DEFAULT
|
||||
return consts.LB_BACKEND_ROLE_DEFAULT
|
||||
}
|
||||
|
||||
func (self *SLBBackend) GetBackendId() string {
|
||||
|
||||
@@ -3,12 +3,13 @@ package qcloud
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"strings"
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLBBackendGroup struct {
|
||||
@@ -140,7 +141,7 @@ func backendGroupIdGen(lbid string, secondId string) string {
|
||||
|
||||
func (self *SLBBackendGroup) GetId() string {
|
||||
t := self.listener.GetListenerType()
|
||||
if t == models.LB_LISTENER_TYPE_HTTP || t == models.LB_LISTENER_TYPE_HTTPS {
|
||||
if t == consts.LB_LISTENER_TYPE_HTTP || t == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
// http https 后端服务器只与规则绑定
|
||||
return backendGroupIdGen(self.lb.GetId(), self.rule.GetId())
|
||||
} else if self.lb.Forward == LB_TYPE_APPLICATION {
|
||||
@@ -160,7 +161,7 @@ func (self *SLBBackendGroup) GetGlobalId() string {
|
||||
}
|
||||
|
||||
func (self *SLBBackendGroup) GetStatus() string {
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
}
|
||||
|
||||
func (self *SLBBackendGroup) Refresh() error {
|
||||
@@ -181,7 +182,7 @@ func (self *SLBBackendGroup) IsDefault() bool {
|
||||
}
|
||||
|
||||
func (self *SLBBackendGroup) GetType() string {
|
||||
return models.LB_BACKENDGROUP_TYPE_NORMAL
|
||||
return consts.LB_BACKENDGROUP_TYPE_NORMAL
|
||||
}
|
||||
|
||||
func (self *SLBBackendGroup) GetILoadbalancerBackends() ([]cloudprovider.ICloudLoadbalancerBackend, error) {
|
||||
|
||||
@@ -8,15 +8,15 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
var HTTP_CODES = []string{
|
||||
models.LB_HEALTH_CHECK_HTTP_CODE_1xx,
|
||||
models.LB_HEALTH_CHECK_HTTP_CODE_2xx,
|
||||
models.LB_HEALTH_CHECK_HTTP_CODE_3xx,
|
||||
models.LB_HEALTH_CHECK_HTTP_CODE_4xx,
|
||||
models.LB_HEALTH_CHECK_HTTP_CODE_5xx,
|
||||
consts.LB_HEALTH_CHECK_HTTP_CODE_1xx,
|
||||
consts.LB_HEALTH_CHECK_HTTP_CODE_2xx,
|
||||
consts.LB_HEALTH_CHECK_HTTP_CODE_3xx,
|
||||
consts.LB_HEALTH_CHECK_HTTP_CODE_4xx,
|
||||
consts.LB_HEALTH_CHECK_HTTP_CODE_5xx,
|
||||
}
|
||||
|
||||
type certificate struct {
|
||||
@@ -212,7 +212,7 @@ func (self *SLBListener) GetGlobalId() string {
|
||||
|
||||
// 腾讯云负载均衡没有启用禁用操作
|
||||
func (self *SLBListener) GetStatus() string {
|
||||
return models.LB_STATUS_ENABLED
|
||||
return consts.LB_STATUS_ENABLED
|
||||
}
|
||||
|
||||
func (self *SLBListener) Refresh() error {
|
||||
@@ -245,15 +245,15 @@ func (self *SLBListener) GetMetadata() *jsonutils.JSONDict {
|
||||
func (self *SLBListener) GetListenerType() string {
|
||||
switch self.Protocol {
|
||||
case "TCP":
|
||||
return models.LB_LISTENER_TYPE_TCP
|
||||
return consts.LB_LISTENER_TYPE_TCP
|
||||
case "UDP":
|
||||
return models.LB_LISTENER_TYPE_UDP
|
||||
return consts.LB_LISTENER_TYPE_UDP
|
||||
case "HTTP":
|
||||
return models.LB_LISTENER_TYPE_HTTP
|
||||
return consts.LB_LISTENER_TYPE_HTTP
|
||||
case "HTTPS":
|
||||
return models.LB_LISTENER_TYPE_HTTPS
|
||||
return consts.LB_LISTENER_TYPE_HTTPS
|
||||
case "TCP_SSL":
|
||||
return models.LB_LISTENER_TYPE_TCP
|
||||
return consts.LB_LISTENER_TYPE_TCP
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
@@ -266,18 +266,18 @@ func (self *SLBListener) GetListenerPort() int {
|
||||
func (self *SLBListener) GetScheduler() string {
|
||||
switch strings.ToLower(self.Scheduler) {
|
||||
case "wrr":
|
||||
return models.LB_SCHEDULER_WRR
|
||||
return consts.LB_SCHEDULER_WRR
|
||||
case "ip_hash":
|
||||
return models.LB_SCHEDULER_SCH
|
||||
return consts.LB_SCHEDULER_SCH
|
||||
case "least_conn":
|
||||
return models.LB_SCHEDULER_WLC
|
||||
return consts.LB_SCHEDULER_WLC
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SLBListener) GetAclStatus() string {
|
||||
return models.LB_BOOL_OFF
|
||||
return consts.LB_BOOL_OFF
|
||||
}
|
||||
|
||||
func (self *SLBListener) GetAclType() string {
|
||||
@@ -290,17 +290,17 @@ func (self *SLBListener) GetAclId() string {
|
||||
|
||||
func (self *SLBListener) GetHealthCheck() string {
|
||||
if self.HealthCheck.HealthSwitch == 0 {
|
||||
return models.LB_BOOL_OFF
|
||||
return consts.LB_BOOL_OFF
|
||||
} else {
|
||||
return models.LB_BOOL_ON
|
||||
return consts.LB_BOOL_ON
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SLBListener) GetHealthCheckType() string {
|
||||
if len(self.HealthCheck.HTTPCheckMethod) > 0 {
|
||||
return models.LB_HEALTH_CHECK_HTTP
|
||||
return consts.LB_HEALTH_CHECK_HTTP
|
||||
} else {
|
||||
return models.LB_HEALTH_CHECK_TCP
|
||||
return consts.LB_HEALTH_CHECK_TCP
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ func (self *SLBListener) GetHealthCheckExp() string {
|
||||
func (self *SLBListener) GetBackendGroup() *SLBBackendGroup {
|
||||
t := self.GetListenerType()
|
||||
// http、https类型的监听不能直接绑定服务器
|
||||
if t == models.LB_LISTENER_TYPE_HTTP || t == models.LB_LISTENER_TYPE_HTTPS {
|
||||
if t == consts.LB_LISTENER_TYPE_HTTP || t == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
return nil
|
||||
} else {
|
||||
return &SLBBackendGroup{lb: self.lb, listener: self}
|
||||
@@ -380,21 +380,21 @@ func (self *SLBListener) GetILoadbalancerListenerRules() ([]cloudprovider.ICloud
|
||||
|
||||
func (self *SLBListener) GetStickySession() string {
|
||||
if self.SessionExpireTime == 0 {
|
||||
return models.LB_BOOL_OFF
|
||||
return consts.LB_BOOL_OFF
|
||||
} else {
|
||||
return models.LB_BOOL_ON
|
||||
return consts.LB_BOOL_ON
|
||||
}
|
||||
}
|
||||
|
||||
// 支持基于 cookie 插入的会话保持能力 https://cloud.tencent.com/document/product/214/6154
|
||||
func (self *SLBListener) GetStickySessionType() string {
|
||||
return models.LB_STICKY_SESSION_TYPE_INSERT
|
||||
return consts.LB_STICKY_SESSION_TYPE_INSERT
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/product/214/2736
|
||||
// 经测试应用型负载均衡返回都是 tgw_l7_route。
|
||||
func (self *SLBListener) GetStickySessionCookie() string {
|
||||
if self.GetListenerType() == models.LB_LISTENER_TYPE_HTTPS {
|
||||
if self.GetListenerType() == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
return "tgw_l7_route"
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ https://cloud.tencent.com/document/product/214/6151
|
||||
*/
|
||||
func (self *SLBListener) XForwardedForEnabled() bool {
|
||||
switch self.GetListenerType() {
|
||||
case models.LB_LISTENER_TYPE_HTTP, models.LB_LISTENER_TYPE_HTTPS:
|
||||
case consts.LB_LISTENER_TYPE_HTTP, consts.LB_LISTENER_TYPE_HTTPS:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -424,7 +424,7 @@ func (self *SLBListener) XForwardedForEnabled() bool {
|
||||
// 负载均衡开启Gzip配置及检测方法说明 https://cloud.tencent.com/document/product/214/5404
|
||||
func (self *SLBListener) GzipEnabled() bool {
|
||||
switch self.GetListenerType() {
|
||||
case models.LB_LISTENER_TYPE_HTTP, models.LB_LISTENER_TYPE_HTTPS:
|
||||
case consts.LB_LISTENER_TYPE_HTTP, consts.LB_LISTENER_TYPE_HTTPS:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -647,7 +647,7 @@ func (self *SRegion) UpdateLoadbalancerListener(t LB_TYPE, lbid string, listener
|
||||
|
||||
func getHealthCheck(listener *cloudprovider.SLoadbalancerListener) *healthCheck {
|
||||
var hc *healthCheck
|
||||
if listener.HealthCheck == models.LB_BOOL_ON {
|
||||
if listener.HealthCheck == consts.LB_BOOL_ON {
|
||||
hc = &healthCheck{
|
||||
HealthSwitch: 1,
|
||||
UnHealthNum: listener.HealthCheckFail,
|
||||
@@ -683,13 +683,13 @@ func getCertificate(listener *cloudprovider.SLoadbalancerListener) *certificate
|
||||
|
||||
func getProtocol(listener *cloudprovider.SLoadbalancerListener) string {
|
||||
switch listener.ListenerType {
|
||||
case models.LB_LISTENER_TYPE_HTTPS:
|
||||
case consts.LB_LISTENER_TYPE_HTTPS:
|
||||
return "HTTPS"
|
||||
case models.LB_LISTENER_TYPE_HTTP:
|
||||
case consts.LB_LISTENER_TYPE_HTTP:
|
||||
return "HTTP"
|
||||
case models.LB_LISTENER_TYPE_TCP:
|
||||
case consts.LB_LISTENER_TYPE_TCP:
|
||||
return "TCP"
|
||||
case models.LB_LISTENER_TYPE_UDP:
|
||||
case consts.LB_LISTENER_TYPE_UDP:
|
||||
return "UDP"
|
||||
case "tcp_ssl":
|
||||
return "TCP_SSL"
|
||||
@@ -700,13 +700,13 @@ func getProtocol(listener *cloudprovider.SLoadbalancerListener) string {
|
||||
|
||||
func getClassicLBProtocol(listener *cloudprovider.SLoadbalancerListener) int {
|
||||
switch listener.ListenerType {
|
||||
case models.LB_LISTENER_TYPE_HTTP:
|
||||
case consts.LB_LISTENER_TYPE_HTTP:
|
||||
return 1
|
||||
case models.LB_LISTENER_TYPE_HTTPS:
|
||||
case consts.LB_LISTENER_TYPE_HTTPS:
|
||||
return 4
|
||||
case models.LB_LISTENER_TYPE_TCP:
|
||||
case consts.LB_LISTENER_TYPE_TCP:
|
||||
return 2
|
||||
case models.LB_LISTENER_TYPE_UDP:
|
||||
case consts.LB_LISTENER_TYPE_UDP:
|
||||
return 3
|
||||
default:
|
||||
return 0 // 非法值
|
||||
@@ -716,11 +716,11 @@ func getClassicLBProtocol(listener *cloudprovider.SLoadbalancerListener) int {
|
||||
func getScheduler(listener *cloudprovider.SLoadbalancerListener) *string {
|
||||
var sch string
|
||||
switch listener.Scheduler {
|
||||
case models.LB_SCHEDULER_WRR:
|
||||
case consts.LB_SCHEDULER_WRR:
|
||||
sch = "WRR"
|
||||
case models.LB_SCHEDULER_WLC:
|
||||
case consts.LB_SCHEDULER_WLC:
|
||||
sch = "LEAST_CONN"
|
||||
case models.LB_SCHEDULER_SCH:
|
||||
case consts.LB_SCHEDULER_SCH:
|
||||
sch = "IP_HASH"
|
||||
default:
|
||||
return nil
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/compute/consts"
|
||||
)
|
||||
|
||||
type SLBListenerRule struct {
|
||||
@@ -81,7 +81,7 @@ func (self *SLBListenerRule) GetPath() string {
|
||||
|
||||
func (self *SLBListenerRule) GetBackendGroup() *SLBBackendGroup {
|
||||
t := self.listener.GetListenerType()
|
||||
if t == models.LB_LISTENER_TYPE_HTTP || t == models.LB_LISTENER_TYPE_HTTPS {
|
||||
if t == consts.LB_LISTENER_TYPE_HTTP || t == consts.LB_LISTENER_TYPE_HTTPS {
|
||||
return &SLBBackendGroup{
|
||||
lb: self.listener.lb,
|
||||
listener: self.listener,
|
||||
|
||||
Reference in New Issue
Block a user