mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
fix(region): add vpc host topology
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user