Merge pull request #11377 from ioito/automated-cherry-pick-of-#11375-upstream-release-3.7

Automated cherry pick of #11375: fix(host): update rbd storage capacity
This commit is contained in:
Zexi Li
2021-06-11 17:46:34 +08:00
committed by GitHub
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -347,7 +347,7 @@ func StartSyncStorageSizeTask(interval time.Duration) {
manager := GetManager()
for i := 0; i < len(manager.Storages); i++ {
iS := manager.Storages[i]
if iS.StorageType() == api.STORAGE_LOCAL {
if iS.StorageType() == api.STORAGE_LOCAL || iS.StorageType() == api.STORAGE_RBD {
err := iS.SyncStorageSize()
if err != nil {
log.Errorf("sync storage %s size failed: %s", iS.GetStorageName(), err)
+14
View File
@@ -606,6 +606,20 @@ func (s *SRbdStorage) getCapacity() (*sCephCapacity, error) {
return ret, nil
}
func (s *SRbdStorage) SyncStorageSize() error {
content := jsonutils.NewDict()
capacity, err := s.getCapacity()
if err != nil {
return errors.Wrapf(err, "getCapacity")
}
content.Set("capacity", jsonutils.NewInt(int64(capacity.CapacitySizeByte/1024/1024)))
content.Set("actual_capacity_used", jsonutils.NewInt(int64(capacity.UsedCapacitySizeByte/1024/1024)))
_, err = modules.Storages.Put(
hostutils.GetComputeSession(context.Background()),
s.StorageId, content)
return errors.Wrapf(err, "storage update")
}
func (s *SRbdStorage) SyncStorageInfo() (jsonutils.JSONObject, error) {
content := map[string]interface{}{}
if len(s.StorageId) > 0 {