fix(region): add vpc host topology

This commit is contained in:
ioito
2021-12-27 10:48:39 +08:00
parent 67a0073b2f
commit 8433fc5ffb
3 changed files with 49 additions and 0 deletions
+14
View File
@@ -132,12 +132,26 @@ type NetworkTopologyOutput struct {
Address []SNetworkUsedAddress `json:"address"`
}
type HostnetworkTopologyOutput struct {
IpAddr string `json:"ip_addr"`
MacAddr string `json:"mac_addr"`
}
type HostTopologyOutput struct {
Name string `json:"name"`
Status string `json:"status"`
HostStatus string `json:"host_status"`
HostType string `json:"host_type"`
Networks []HostnetworkTopologyOutput `json:"networks"`
}
type WireTopologyOutput struct {
Name string `json:"name"`
Status string `json:"status"`
Bandwidth int `json:"bandwidth"`
Zone string `json:"zone"`
Networks []NetworkTopologyOutput `json:"networks"`
Hosts []HostTopologyOutput `json:"hosts"`
}
type VpcTopologyOutput struct {
+22
View File
@@ -1738,6 +1738,7 @@ func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.Toke
Status: wires[i].Status,
Bandwidth: wires[i].Bandwidth,
Networks: []api.NetworkTopologyOutput{},
Hosts: []api.HostTopologyOutput{},
}
if len(wires[i].ZoneId) > 0 {
zone, _ := wires[i].GetZone()
@@ -1745,6 +1746,27 @@ func (self *SVpc) GetDetailsTopology(ctx context.Context, userCred mcclient.Toke
wire.Zone = zone.Name
}
}
hosts, err := wires[i].GetHosts()
if err != nil {
return nil, errors.Wrapf(err, "GetHosts for wire %s", wires[i].Id)
}
for i := range hosts {
hns := hosts[i].GetBaremetalnetworks()
host := api.HostTopologyOutput{
Name: hosts[i].Name,
Status: hosts[i].Status,
HostStatus: hosts[i].HostStatus,
HostType: hosts[i].HostType,
Networks: []api.HostnetworkTopologyOutput{},
}
for j := range hns {
host.Networks = append(host.Networks, api.HostnetworkTopologyOutput{
IpAddr: hns[j].IpAddr,
MacAddr: hns[j].MacAddr,
})
}
wire.Hosts = append(wire.Hosts, host)
}
networks, err := wires[i].GetNetworks(nil, rbacutils.ScopeSystem)
if err != nil {
return nil, errors.Wrapf(err, "GetNetworks")
+13
View File
@@ -251,6 +251,19 @@ func (wire *SWire) GetHostwires() ([]SHostwire, error) {
return hostwires, nil
}
func (self *SWire) GetHosts() ([]SHost, error) {
networks := NetworkManager.Query().SubQuery()
hns := HostnetworkManager.Query("baremetal_id")
sq := hns.Join(networks, sqlchemy.Equals(hns.Field("network_id"), networks.Field("id"))).SubQuery()
q := HostManager.Query().In("id", sq)
hosts := []SHost{}
err := db.FetchModelObjects(HostManager, q, &hosts)
if err != nil {
return nil, errors.Wrapf(err, "db.FetchModelObjects")
}
return hosts, nil
}
func (wire *SWire) NetworkCount() (int, error) {
q := NetworkManager.Query().Equals("wire_id", wire.Id)
return q.CountWithError()