From 51fcc9e5d83d5c87e0935f2be71dbdf077ed4abe Mon Sep 17 00:00:00 2001 From: ioito Date: Thu, 11 Jul 2019 17:12:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=BF=E4=B8=BB=E6=9C=BA=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=88=A9=E7=94=A8=E7=8E=87=E4=BB=85=E8=AE=A1=E7=AE=97=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/apis/compute/storage_const.go | 2 ++ pkg/compute/models/hosts.go | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/apis/compute/storage_const.go b/pkg/apis/compute/storage_const.go index 4f7a247b4b..14fb7c7549 100644 --- a/pkg/apis/compute/storage_const.go +++ b/pkg/apis/compute/storage_const.go @@ -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} diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index fca810877b..4c01b355ae 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -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 {