add read only for quota switcher

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
wang yan 2019-09-03 14:05:37 +08:00
parent b75cbe1a7e
commit d8e17b122e

View File

@ -88,14 +88,20 @@ func (ia *InternalAPI) SwitchQuota() {
ia.SendBadRequestError(err) ia.SendBadRequestError(err)
return return
} }
cur := config.ReadOnly()
// quota per project from disable to enable, it needs to update the quota usage bases on the DB records. // quota per project from disable to enable, it needs to update the quota usage bases on the DB records.
if !config.QuotaPerProjectEnable() && req.Enabled { if !config.QuotaPerProjectEnable() && req.Enabled {
if !cur {
config.GetCfgManager().Set(common.ReadOnly, true)
config.GetCfgManager().Save()
}
if err := ia.ensureQuota(); err != nil { if err := ia.ensureQuota(); err != nil {
ia.SendInternalServerError(err) ia.SendInternalServerError(err)
return return
} }
} }
defer func() { defer func() {
config.GetCfgManager().Set(common.ReadOnly, cur)
config.GetCfgManager().Set(common.QuotaPerProjectEnable, req.Enabled) config.GetCfgManager().Set(common.QuotaPerProjectEnable, req.Enabled)
config.GetCfgManager().Save() config.GetCfgManager().Save()
}() }()