Merge pull request #1367 from yousong/bugfix/yousong-lb

Bugfix/yousong lb
This commit is contained in:
yunion-ci-robot
2019-06-25 11:45:51 +08:00
committed by GitHub
5 changed files with 58 additions and 11 deletions
+24
View File
@@ -0,0 +1,24 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package db
import (
"time"
)
type IPendingDeletable interface {
GetPendingDeleted() bool
GetPendingDeletedAt() time.Time
}
+10
View File
@@ -486,6 +486,16 @@ func (model *SVirtualResourceBase) SyncCloudProjectId(userCred mcclient.TokenCre
}
}
// GetPendingDeleted implements IPendingDeltable
func (model *SVirtualResourceBase) GetPendingDeleted() bool {
return model.PendingDeleted
}
// GetPendingDeletedAt implements IPendingDeltable
func (model *SVirtualResourceBase) GetPendingDeletedAt() time.Time {
return model.PendingDeletedAt
}
func (manager *SVirtualResourceBaseManager) OrderByExtraFields(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
q, err := manager.SStatusStandaloneResourceBaseManager.OrderByExtraFields(ctx, q, userCred, query)
if err != nil {
+1 -1
View File
@@ -113,7 +113,7 @@ func newModelManagerError(modelKeyword string) error {
func newModelNotFoundError(modelKeyword, idOrName string, err error) error {
errFmt := "cannot find %q with id/name %q"
params := []interface{}{modelKeyword, idOrName}
if err != sql.ErrNoRows {
if err != nil && err != sql.ErrNoRows {
errFmt += ": %s"
params = append(params, err.Error())
}
+22 -9
View File
@@ -381,11 +381,12 @@ func NewNonNegativeValidator(key string) *ValidatorRange {
type ValidatorModelIdOrName struct {
Validator
ModelKeyword string
OwnerId mcclient.IIdentityProvider
ModelManager db.IModelManager
Model db.IModel
modelIdKey string
ModelKeyword string
OwnerId mcclient.IIdentityProvider
ModelManager db.IModelManager
Model db.IModel
modelIdKey string
noPendingDeleted bool
}
func (v *ValidatorModelIdOrName) GetProjectId() string {
@@ -434,10 +435,11 @@ func (v *ValidatorModelIdOrName) getValue() interface{} {
func NewModelIdOrNameValidator(key string, modelKeyword string, ownerId mcclient.IIdentityProvider) *ValidatorModelIdOrName {
v := &ValidatorModelIdOrName{
Validator: Validator{Key: key},
OwnerId: ownerId,
ModelKeyword: modelKeyword,
modelIdKey: key + "_id",
Validator: Validator{Key: key},
OwnerId: ownerId,
ModelKeyword: modelKeyword,
modelIdKey: key + "_id",
noPendingDeleted: true,
}
v.SetParent(v)
return v
@@ -448,6 +450,12 @@ func (v *ValidatorModelIdOrName) ModelIdKey(modelIdKey string) *ValidatorModelId
return v
}
// AllowPendingDeleted allows the to-be-validated id or name to be of a pending deleted model
func (v *ValidatorModelIdOrName) AllowPendingDeleted(b bool) *ValidatorModelIdOrName {
v.noPendingDeleted = !b
return v
}
func (v *ValidatorModelIdOrName) validate(data *jsonutils.JSONDict) error {
if err, isSet := v.Validator.validateEx(data); err != nil || !isSet {
return err
@@ -466,6 +474,11 @@ func (v *ValidatorModelIdOrName) validate(data *jsonutils.JSONDict) error {
if err != nil {
return newModelNotFoundError(v.ModelKeyword, modelIdOrName, err)
}
if v.noPendingDeleted {
if pd, ok := model.(db.IPendingDeletable); ok && pd.GetPendingDeleted() {
return newModelNotFoundError(v.ModelKeyword, modelIdOrName, nil)
}
}
v.Model = model
return nil
}
+1 -1
View File
@@ -534,7 +534,7 @@ vrrp_instance YunionLB {
auth_type PASS
auth_pass {{ .vrrp.pass }}
}
{{ if .vrrp.notify_script -}} notify {{ .vrrp.notify_script }} {{- end }}
{{ if .vrrp.notify_script -}} notify {{ .vrrp.notify_script }} root {{- end }}
{{ if .vrrp.unicast_peer -}} unicast_peer { {{- println }}
{{- range .vrrp.unicast_peer }} {{ println . }} {{- end }}
}