Skip to content

Commit 35f4f74

Browse files
authored
Merge pull request #8 from threefoldtech/add-node-features-endpoint
add new endpoint to featch node features
2 parents 146e178 + 7ea4e9f commit 35f4f74

File tree

8 files changed

+68
-5
lines changed

8 files changed

+68
-5
lines changed

client/node.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ func (n *NodeClient) Counters(ctx context.Context) (counters Counters, err error
212212
const cmd = "zos.statistics.get"
213213
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &counters)
214214
return
215-
216215
}
217216

218217
// Pools returns statistics of separate pools
@@ -267,7 +266,6 @@ func (n *NodeClient) NetworkListAllInterfaces(ctx context.Context) (result map[s
267266
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &result)
268267

269268
return
270-
271269
}
272270

273271
// NetworkSetPublicExitDevice select which physical interface to use as an exit device
@@ -322,6 +320,13 @@ func (n *NodeClient) NetworkGetPublicConfig(ctx context.Context) (cfg pkg.Public
322320
return
323321
}
324322

323+
func (n *NodeClient) SystemGetNodeFeatures(ctx context.Context) (feat []pkg.NodeFeature, err error) {
324+
const cmd = "zos.system.node_features_get"
325+
326+
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &feat)
327+
return
328+
}
329+
325330
func (n *NodeClient) SystemVersion(ctx context.Context) (ver Version, err error) {
326331
const cmd = "zos.system.version"
327332

docs/manual/api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ name must be one of (free) names returned by `zos.network.admin.interfaces`
217217
|---|---|---|
218218
| `zos.system.hypervisor` | - | `string` |
219219

220+
### Get Node Features
221+
222+
| command |body| return|
223+
|---|---|---|
224+
| `zos.system.node_features_get` | - |`[]NodeFeature` |
225+
226+
227+
Where
228+
229+
```json
230+
NodeFeature: "string"
231+
232+
```
233+
234+
returns the types of workloads can be deployed depending on the network manager running on the node
235+
220236
## GPUs
221237

222238
### List Gpus

pkg/monitor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ type PoolStats struct {
7878
// PoolsStats alias for map[string]PoolStats
7979
type PoolsStats map[string]PoolStats
8080

81+
// Types of workloads can be deployed depending on the network manager running on the node
82+
type NodeFeature string
83+
8184
// SystemMonitor interface (provided by noded)
8285
type SystemMonitor interface {
8386
NodeID() uint32
8487
Memory(ctx context.Context) <-chan VirtualMemoryStat
8588
CPU(ctx context.Context) <-chan TimesStat
8689
Disks(ctx context.Context) <-chan DisksIOCountersStat
8790
Nics(ctx context.Context) <-chan NicsIOCounterStat
91+
GetNodeFeatures() []NodeFeature
8892
}
8993

9094
// HostMonitor interface (provided by noded)

pkg/monitord/system.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import (
1010
"github.com/shirou/gopsutil/mem"
1111
"github.com/shirou/gopsutil/net"
1212
"github.com/threefoldtech/zos/pkg"
13+
"github.com/threefoldtech/zos/pkg/gridtypes/zos"
1314
)
1415

15-
var (
16-
_ pkg.SystemMonitor = (*systemMonitor)(nil)
17-
)
16+
var _ pkg.SystemMonitor = (*systemMonitor)(nil)
1817

1918
// systemMonitor stream
2019
type systemMonitor struct {
@@ -199,3 +198,19 @@ func (m *systemMonitor) Nics(ctx context.Context) <-chan pkg.NicsIOCounterStat {
199198

200199
return ch
201200
}
201+
202+
// Get the types of workloads can be deployed depending on the network manager running on the node
203+
func (n *systemMonitor) GetNodeFeatures() []pkg.NodeFeature {
204+
feat := []pkg.NodeFeature{
205+
pkg.NodeFeature(zos.ZMachineLightType),
206+
pkg.NodeFeature(zos.NetworkLightType),
207+
pkg.NodeFeature(zos.ZDBType),
208+
pkg.NodeFeature(zos.ZMountType),
209+
pkg.NodeFeature(zos.VolumeType),
210+
pkg.NodeFeature(zos.PublicIPv4Type),
211+
pkg.NodeFeature(zos.PublicIPType),
212+
pkg.NodeFeature(zos.QuantumSafeFSType),
213+
pkg.NodeFeature(zos.ZLogsType),
214+
}
215+
return feat
216+
}

pkg/stubs/system_monitor_stub.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ func (s *SystemMonitorStub) Disks(ctx context.Context) (<-chan pkg.DisksIOCounte
7575
return ch, nil
7676
}
7777

78+
func (s *SystemMonitorStub) GetNodeFeatures(ctx context.Context) (ret0 []pkg.NodeFeature) {
79+
args := []interface{}{}
80+
result, err := s.client.RequestContext(ctx, s.module, s.object, "GetNodeFeatures", args...)
81+
if err != nil {
82+
panic(err)
83+
}
84+
result.PanicOnError()
85+
loader := zbus.Loader{
86+
&ret0,
87+
}
88+
if err := result.Unmarshal(&loader); err != nil {
89+
panic(err)
90+
}
91+
return
92+
}
93+
7894
func (s *SystemMonitorStub) Memory(ctx context.Context) (<-chan pkg.VirtualMemoryStat, error) {
7995
ch := make(chan pkg.VirtualMemoryStat, 1)
8096
recv, err := s.client.Stream(ctx, s.module, s.object, "Memory")

pkg/zos_api/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) {
1313
system.WithHandler("dmi", g.systemDMIHandler)
1414
system.WithHandler("hypervisor", g.systemHypervisorHandler)
1515
system.WithHandler("diagnostics", g.systemDiagnosticsHandler)
16+
system.WithHandler("node_features_get", g.systemNodeFeaturesHandler)
1617

1718
perf := root.SubRoute("perf")
1819
perf.WithHandler("get", g.perfGetHandler)

pkg/zos_api/system.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ func (g *ZosAPI) systemHypervisorHandler(ctx context.Context, payload []byte) (i
3737
func (g *ZosAPI) systemDiagnosticsHandler(ctx context.Context, payload []byte) (interface{}, error) {
3838
return g.diagnosticsManager.GetSystemDiagnostics(ctx)
3939
}
40+
41+
func (g *ZosAPI) systemNodeFeaturesHandler(ctx context.Context, payload []byte) (interface{}, error) {
42+
return g.systemMonitorStub.GetNodeFeatures(ctx), nil
43+
}

pkg/zos_api/zos_api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type ZosAPI struct {
1515
oracle *capacity.ResourceOracle
1616
versionMonitorStub *stubs.VersionMonitorStub
17+
systemMonitorStub *stubs.SystemMonitorStub
1718
provisionStub *stubs.ProvisionStub
1819
networkerLightStub *stubs.NetworkerLightStub
1920
statisticsStub *stubs.StatisticsStub
@@ -37,6 +38,7 @@ func NewZosAPI(manager substrate.Manager, client zbus.Client, msgBrokerCon strin
3738
api := ZosAPI{
3839
oracle: capacity.NewResourceOracle(storageModuleStub),
3940
versionMonitorStub: stubs.NewVersionMonitorStub(client),
41+
systemMonitorStub: stubs.NewSystemMonitorStub(client),
4042
provisionStub: stubs.NewProvisionStub(client),
4143
networkerLightStub: stubs.NewNetworkerLightStub(client),
4244
statisticsStub: stubs.NewStatisticsStub(client),

0 commit comments

Comments
 (0)