lblistener: allow setting http/https listener backendgroup to empty

This commit is contained in:
Yousong Zhou
2020-01-14 21:06:17 +08:00
parent dcb4366e6d
commit dd01610931
2 changed files with 7 additions and 2 deletions

View File

@@ -355,7 +355,7 @@ func (lblis *SLoadbalancerListener) StartLoadBalancerListenerSyncstatusTask(ctx
func (lblis *SLoadbalancerListener) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
ownerId := lblis.GetOwnerId()
backendGroupV := validators.NewModelIdOrNameValidator("backend_group", "loadbalancerbackendgroup", ownerId)
backendGroupV.Optional(true)
backendGroupV.AllowEmpty(true).Optional(true)
if err := backendGroupV.Validate(data); err != nil {
return nil, err
}

View File

@@ -577,7 +577,12 @@ func (self *SKVMRegionDriver) ValidateUpdateLoadbalancerListenerData(ctx context
}
{
if lbbg, ok := backendGroup.(*models.SLoadbalancerBackendGroup); ok && lbbg.LoadbalancerId != lblis.LoadbalancerId {
if backendGroup == nil {
if lblis.ListenerType != api.LB_LISTENER_TYPE_HTTP &&
lblis.ListenerType != api.LB_LISTENER_TYPE_HTTPS {
return nil, httperrors.NewInputParameterError("non http listener must have backend group set")
}
} else if lbbg, ok := backendGroup.(*models.SLoadbalancerBackendGroup); ok && lbbg.LoadbalancerId != lblis.LoadbalancerId {
return nil, httperrors.NewInputParameterError("backend group %s(%s) belongs to loadbalancer %s instead of %s",
lbbg.Name, lbbg.Id, lbbg.LoadbalancerId, lblis.LoadbalancerId)
}