宿主机存储利用率仅计算本地存储

This commit is contained in:
ioito
2019-07-11 17:16:21 +08:00
parent 63e645c377
commit 51fcc9e5d8
2 changed files with 8 additions and 3 deletions
+2
View File
@@ -102,6 +102,8 @@ var (
STORAGE_ZSTACK_LOCAL_STORAGE, STORAGE_ZSTACK_CEPH, STORAGE_GPFS,
}
HOST_STORAGE_LOCAL_TYPES = []string{STORAGE_LOCAL, STORAGE_BAREMETAL}
STORAGE_LIMITED_TYPES = []string{STORAGE_LOCAL, STORAGE_BAREMETAL, STORAGE_NAS, STORAGE_RBD, STORAGE_NFS, STORAGE_GPFS}
SHARED_FILE_STORAGE = []string{STORAGE_NFS, STORAGE_GPFS}
+6 -3
View File
@@ -1069,10 +1069,13 @@ func (cap *SStorageCapacity) ToJson() *jsonutils.JSONDict {
return ret
}
func (self *SHost) GetAttachedStorageCapacity() SStorageCapacity {
func (self *SHost) GetAttachedLocalStorageCapacity() SStorageCapacity {
ret := SStorageCapacity{}
storages := self.GetAttachedStorages("")
for _, s := range storages {
if !utils.IsInStringArray(s.StorageType, api.HOST_STORAGE_LOCAL_TYPES) {
continue
}
ret.Add(s.getStorageCapacity())
}
return ret
@@ -2350,7 +2353,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict
memCommitRate = float64(usage.GuestVmemSize) * 1.0 / float64(totalMem)
}
extra.Add(jsonutils.NewFloat(memCommitRate), "mem_commit_rate")
capa := self.GetAttachedStorageCapacity()
capa := self.GetAttachedLocalStorageCapacity()
extra.Add(jsonutils.NewInt(int64(capa.Capacity)), "storage")
extra.Add(jsonutils.NewInt(int64(capa.Used)), "storage_used")
extra.Add(jsonutils.NewInt(int64(capa.Wasted)), "storage_waste")
@@ -3067,7 +3070,7 @@ func (self *SHost) PerformInitialize(
guest.SetAllMetadata(ctx, map[string]interface{}{
"is_fake_baremetal_server": true, "host_ip": self.AccessIp}, userCred)
caps := self.GetAttachedStorageCapacity()
caps := self.GetAttachedLocalStorageCapacity()
diskConfig := &api.DiskConfig{SizeMb: int(caps.GetFree())}
err = guest.CreateDisksOnHost(ctx, userCred, self, []*api.DiskConfig{diskConfig}, nil, true, true, nil, nil, true)
if err != nil {