Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new endpoint to fetch node features #2422

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func (n *NodeClient) Counters(ctx context.Context) (counters Counters, err error
const cmd = "zos.statistics.get"
err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &counters)
return

}

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

return

}

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

func (n *NodeClient) SystemGetNodeFeatures(ctx context.Context) (feat []pkg.NodeFeature, err error) {
const cmd = "zos.system.node_features_get"

err = n.bus.Call(ctx, n.nodeTwin, cmd, nil, &feat)
return
}

func (n *NodeClient) SystemVersion(ctx context.Context) (ver Version, err error) {
const cmd = "zos.system.version"

Expand Down
16 changes: 16 additions & 0 deletions docs/manual/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ name must be one of (free) names returned by `zos.network.admin.interfaces`
|---|---|---|
| `zos.system.hypervisor` | - | `string` |

### Get Node Features

| command |body| return|
|---|---|---|
| `zos.system.node_features_get` | - |`[]NodeFeature` |


Where

```json
NodeFeature: "string"

```

returns the types of workloads can be deployed depending on the network manager running on the node

## GPUs

### List Gpus
Expand Down
4 changes: 4 additions & 0 deletions pkg/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ type PoolStats struct {
// PoolsStats alias for map[string]PoolStats
type PoolsStats map[string]PoolStats

// Types of workloads can be deployed depending on the network manager running on the node
type NodeFeature string

// SystemMonitor interface (provided by noded)
type SystemMonitor interface {
NodeID() uint32
Memory(ctx context.Context) <-chan VirtualMemoryStat
CPU(ctx context.Context) <-chan TimesStat
Disks(ctx context.Context) <-chan DisksIOCountersStat
Nics(ctx context.Context) <-chan NicsIOCounterStat
GetNodeFeatures() ([]NodeFeature, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the suggested interface, will this ever fail? worst case would be an empty slice :)

}

// HostMonitor interface (provided by noded)
Expand Down
23 changes: 20 additions & 3 deletions pkg/monitord/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/net"
"github.com/threefoldtech/zos/pkg"
"github.com/threefoldtech/zos/pkg/gridtypes/zos"
)

var (
_ pkg.SystemMonitor = (*systemMonitor)(nil)
)
var _ pkg.SystemMonitor = (*systemMonitor)(nil)

// systemMonitor stream
type systemMonitor struct {
Expand Down Expand Up @@ -199,3 +198,21 @@ func (m *systemMonitor) Nics(ctx context.Context) <-chan pkg.NicsIOCounterStat {

return ch
}

// Get the types of workloads can be deployed depending on the network manager running on the node
func (n *systemMonitor) GetNodeFeatures() ([]pkg.NodeFeature, error) {
feat := []pkg.NodeFeature{
pkg.NodeFeature(zos.ZMountType),
pkg.NodeFeature(zos.NetworkType),
pkg.NodeFeature(zos.ZDBType),
pkg.NodeFeature(zos.ZMachineType),
pkg.NodeFeature(zos.VolumeType),
pkg.NodeFeature(zos.PublicIPv4Type),
pkg.NodeFeature(zos.PublicIPType),
pkg.NodeFeature(zos.GatewayNameProxyType),
pkg.NodeFeature(zos.GatewayFQDNProxyType),
pkg.NodeFeature(zos.QuantumSafeFSType),
pkg.NodeFeature(zos.ZLogsType),
}
return feat, nil
}
17 changes: 17 additions & 0 deletions pkg/stubs/system_monitor_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ func (s *SystemMonitorStub) Disks(ctx context.Context) (<-chan pkg.DisksIOCounte
return ch, nil
}

func (s *SystemMonitorStub) GetNodeFeatures(ctx context.Context) (ret0 []pkg.NodeFeature, ret1 error) {
args := []interface{}{}
result, err := s.client.RequestContext(ctx, s.module, s.object, "GetNodeFeatures", args...)
if err != nil {
panic(err)
}
result.PanicOnError()
ret1 = result.CallError()
loader := zbus.Loader{
&ret0,
}
if err := result.Unmarshal(&loader); err != nil {
panic(err)
}
return
}

func (s *SystemMonitorStub) Memory(ctx context.Context) (<-chan pkg.VirtualMemoryStat, error) {
ch := make(chan pkg.VirtualMemoryStat, 1)
recv, err := s.client.Stream(ctx, s.module, s.object, "Memory")
Expand Down
2 changes: 1 addition & 1 deletion pkg/zos_api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

func (g *ZosAPI) SetupRoutes(router *peer.Router) {

root := router.SubRoute("zos")
root.Use(g.log)
system := root.SubRoute("system")
system.WithHandler("version", g.systemVersionHandler)
system.WithHandler("dmi", g.systemDMIHandler)
system.WithHandler("hypervisor", g.systemHypervisorHandler)
system.WithHandler("diagnostics", g.systemDiagnosticsHandler)
system.WithHandler("node_features", g.systemNodeFeaturesHandler)

perf := root.SubRoute("perf")
perf.WithHandler("get", g.perfGetHandler)
Expand Down
4 changes: 4 additions & 0 deletions pkg/zos_api/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ func (g *ZosAPI) systemHypervisorHandler(ctx context.Context, payload []byte) (i
func (g *ZosAPI) systemDiagnosticsHandler(ctx context.Context, payload []byte) (interface{}, error) {
return g.diagnosticsManager.GetSystemDiagnostics(ctx)
}

func (g *ZosAPI) systemNodeFeaturesHandler(ctx context.Context, payload []byte) (interface{}, error) {
return g.systemMonitorStub.GetNodeFeatures(ctx)
}
2 changes: 2 additions & 0 deletions pkg/zos_api/zos_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type ZosAPI struct {
oracle *capacity.ResourceOracle
versionMonitorStub *stubs.VersionMonitorStub
systemMonitorStub *stubs.SystemMonitorStub
provisionStub *stubs.ProvisionStub
networkerStub *stubs.NetworkerStub
statisticsStub *stubs.StatisticsStub
Expand All @@ -37,6 +38,7 @@ func NewZosAPI(manager substrate.Manager, client zbus.Client, msgBrokerCon strin
api := ZosAPI{
oracle: capacity.NewResourceOracle(storageModuleStub),
versionMonitorStub: stubs.NewVersionMonitorStub(client),
systemMonitorStub: stubs.NewSystemMonitorStub(client),
provisionStub: stubs.NewProvisionStub(client),
networkerStub: stubs.NewNetworkerStub(client),
statisticsStub: stubs.NewStatisticsStub(client),
Expand Down
Loading