Skip to content

Commit

Permalink
- add server pending deleted for host details
Browse files Browse the repository at this point in the history
- host list by server networks

- guest networks return wire id
  • Loading branch information
wanyaoqi committed Jun 29, 2020
1 parent 561465e commit 8751082
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/compute/guestnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type GuestnetworkDetails struct {

// IP子网名称
Network string `json:"network"`
// 所属Wire
WireId string `json:"wire_id"`
}

type GuestnetworkShortDesc struct {
Expand Down
9 changes: 6 additions & 3 deletions pkg/apis/compute/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ type HostListInput struct {
Uuid []string `json:"uuid"`
// 主机启动模式, 可能值位PXE和ISO
BootMode []string `json:"boot_mode"`
// 虚拟机所在的二层网络
ServerIdForNetwork string `json:"server_id_for_network"`
}

type HostDetails struct {
Expand All @@ -119,9 +121,10 @@ type HostDetails struct {

Schedtags []SchedtagShortDescDetails `json:"schedtags"`

ServerId string `json:"server_id"`
Server string `json:"server"`
ServerIps string `json:"server_ips"`
ServerId string `json:"server_id"`
Server string `json:"server"`
ServerIps string `json:"server_ips"`
ServerPendingDeleted bool `json:"server_pending_deleted"`
// 网卡数量
NicCount int `json:"nic_count"`
// 网卡详情
Expand Down
3 changes: 3 additions & 0 deletions pkg/compute/models/guestnetworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (manager *SGuestnetworkManager) FetchCustomizeColumns(
GuestJointResourceDetails: guestRows[i],
}
netIds[i] = objs[i].(*SGuestnetwork).NetworkId
iNet, _ := NetworkManager.FetchById(netIds[i])
net := iNet.(*SNetwork)
rows[i].WireId = net.WireId
}

netIdMaps, err := db.FetchIdNameMap2(NetworkManager, netIds)
Expand Down
25 changes: 25 additions & 0 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,30 @@ func (manager *SHostManager) ListItemFilter(
q = q.In("boot_mode", query.BootMode)
}

// for provider onecloud
if len(query.ServerIdForNetwork) > 0 {
guest := GuestManager.FetchGuestById(query.ServerIdForNetwork)
if guest != nil && guest.GetHypervisor() == api.HYPERVISOR_KVM {
nets, _ := guest.GetNetworks("")
if len(nets) > 0 {
wires := []string{}
for i := 0; i < len(nets); i++ {
net := nets[i].GetNetwork()
if net.GetVpc().Id != api.DEFAULT_VPC_ID {
q = q.IsNotEmpty("ovn_version")
} else {
if !utils.IsInStringArray(net.WireId, wires) {
wires = append(wires, net.WireId)
hostwires := HostwireManager.Query().SubQuery()
scopeQuery := hostwires.Query(hostwires.Field("host_id")).Equals("wire_id", net.WireId).SubQuery()
q = q.In("id", scopeQuery)
}
}
}
}
}
}

return q, nil
}

Expand Down Expand Up @@ -2521,6 +2545,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, out api.HostDetails, show
if server != nil {
out.ServerId = server.Id
out.Server = server.Name
out.ServerPendingDeleted = server.PendingDeleted
if self.HostType == api.HOST_TYPE_BAREMETAL {
out.ServerIps = strings.Join(server.GetRealIPs(), ",")
}
Expand Down

0 comments on commit 8751082

Please sign in to comment.