From b577c5d41fd0b1f4b5ebb7f74100f4ecede43d19 Mon Sep 17 00:00:00 2001 From: ioito Date: Tue, 10 May 2022 13:51:36 +0800 Subject: [PATCH] fix(region): return storage info with topology --- pkg/apis/compute/vpc.go | 10 ++++++++++ pkg/compute/models/vpcs.go | 12 ++++++++++++ pkg/compute/models/wires.go | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/pkg/apis/compute/vpc.go b/pkg/apis/compute/vpc.go index fca65766cc..73557acf07 100644 --- a/pkg/apis/compute/vpc.go +++ b/pkg/apis/compute/vpc.go @@ -137,6 +137,15 @@ type HostnetworkTopologyOutput struct { MacAddr string `json:"mac_addr"` } +type StorageShortDesc struct { + Id string `json:"name"` + Name string `json:"id"` + Status string `json:"status"` + Enabled bool `json:"enabled"` + StorageType string `json:"storage_type"` + CapacityMb int64 `json:"capacity_mb"` +} + type HostTopologyOutput struct { Name string `json:"name"` Id string `json:"id"` @@ -145,6 +154,7 @@ type HostTopologyOutput struct { HostType string `json:"host_type"` Networks []HostnetworkTopologyOutput `json:"networks"` Schedtags []SchedtagShortDescDetails `json:"schedtags"` + Storages []StorageShortDesc `json:"storages"` } type WireTopologyOutput struct { diff --git a/pkg/compute/models/vpcs.go b/pkg/compute/models/vpcs.go index 62cce6a975..d0acd35ee9 100644 --- a/pkg/compute/models/vpcs.go +++ b/pkg/compute/models/vpcs.go @@ -1757,6 +1757,7 @@ func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.Toke } for i := range hosts { hns := hosts[i].GetBaremetalnetworks() + hss := hosts[i]._getAttachedStorages(tristate.None, tristate.None, nil) host := api.HostTopologyOutput{ Name: hosts[i].Name, Id: hosts[i].Id, @@ -1764,6 +1765,7 @@ func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.Toke HostStatus: hosts[i].HostStatus, HostType: hosts[i].HostType, Networks: []api.HostnetworkTopologyOutput{}, + Storages: []api.StorageShortDesc{}, Schedtags: GetSchedtagsDetailsToResourceV2(&hosts[i], ctx), } for j := range hns { @@ -1772,6 +1774,16 @@ func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.Toke MacAddr: hns[j].MacAddr, }) } + for j := range hss { + host.Storages = append(host.Storages, api.StorageShortDesc{ + Name: hss[j].Name, + Id: hss[j].Id, + Status: hss[j].Status, + Enabled: hss[j].Enabled.Bool(), + StorageType: hss[j].StorageType, + CapacityMb: hss[j].Capacity, + }) + } wire.Hosts = append(wire.Hosts, host) } networks, err := wires[i].GetNetworks(nil, rbacutils.ScopeSystem) diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index e5bd59741a..b7c0579d56 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -1554,6 +1554,7 @@ func (self *SWire) GetDetailsTopology(ctx context.Context, userCred mcclient.Tok } for i := range hosts { hns := hosts[i].GetBaremetalnetworks() + hss := hosts[i]._getAttachedStorages(tristate.None, tristate.None, nil) host := api.HostTopologyOutput{ Name: hosts[i].Name, Id: hosts[i].Id, @@ -1569,6 +1570,16 @@ func (self *SWire) GetDetailsTopology(ctx context.Context, userCred mcclient.Tok MacAddr: hns[j].MacAddr, }) } + for j := range hss { + host.Storages = append(host.Storages, api.StorageShortDesc{ + Name: hss[j].Name, + Id: hss[j].Id, + Status: hss[j].Status, + Enabled: hss[j].Enabled.Bool(), + StorageType: hss[j].StorageType, + CapacityMb: hss[j].Capacity, + }) + } ret.Hosts = append(ret.Hosts, host) } networks, err := self.GetNetworks(nil, rbacutils.ScopeSystem)