-
Notifications
You must be signed in to change notification settings - Fork 291
/
ctl_network_rpc.go
88 lines (71 loc) · 2.29 KB
/
ctl_network_rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// (C) Copyright 2019-2022 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package server
import (
"strings"
"golang.org/x/net/context"
ctlpb "github.com/daos-stack/daos/src/control/common/proto/ctl"
"github.com/daos-stack/daos/src/control/lib/hardware"
"github.com/daos-stack/daos/src/control/lib/hardware/hwprov"
)
// FabricScan performs a scan of fabric interfaces given a list of providers.
func (cs *ControlService) FabricScan(ctx context.Context, providers ...string) (*hardware.FabricInterfaceSet, error) {
return cs.fabric.Scan(ctx, providers...)
}
// NetworkScan retrieves details of network interfaces on remote hosts.
func (cs *ControlService) NetworkScan(ctx context.Context, req *ctlpb.NetworkScanReq) (*ctlpb.NetworkScanResp, error) {
providers, err := cs.srvCfg.Fabric.GetProviders()
if err != nil {
return nil, err
}
switch {
case strings.EqualFold(req.GetProvider(), "all"):
providers = []string{}
case req.GetProvider() != "":
providers = []string{req.GetProvider()}
}
topo, err := hwprov.DefaultTopologyProvider(cs.log).GetTopology(ctx)
if err != nil {
return nil, err
}
if err := cs.fabric.CacheTopology(topo); err != nil {
return nil, err
}
result, err := cs.fabric.Scan(ctx, providers...)
if err != nil {
return nil, err
}
resp := cs.fabricInterfaceSetToNetworkScanResp(result)
resp.Numacount = int32(topo.NumNUMANodes())
resp.Corespernuma = int32(topo.NumCoresPerNUMA())
return resp, nil
}
func (cs *ControlService) fabricInterfaceSetToNetworkScanResp(fis *hardware.FabricInterfaceSet) *ctlpb.NetworkScanResp {
resp := new(ctlpb.NetworkScanResp)
resp.Interfaces = make([]*ctlpb.FabricInterface, 0, fis.NumNetDevices())
for _, name := range fis.Names() {
fi, err := fis.GetInterface(name)
if err != nil {
cs.log.Errorf("unexpected error getting IF %q: %s", name, err.Error())
continue
}
if fi.DeviceClass == hardware.Loopback {
continue
}
for _, hwFI := range fi.NetInterfaces.ToSlice() {
for _, prov := range fi.Providers.ToSlice() {
resp.Interfaces = append(resp.Interfaces, &ctlpb.FabricInterface{
Provider: prov.Name,
Device: hwFI,
Numanode: uint32(fi.NUMANode),
Netdevclass: uint32(fi.DeviceClass),
Priority: uint32(prov.Priority),
})
}
}
}
return resp
}