Skip to content

Commit

Permalink
add new endpoint to fetch node features (#2422)
Browse files Browse the repository at this point in the history
* add new endpoint to featch node features

* move endpoint from network to system

* move GetNodeFeatures to system monitor

* generate get node features function in system monitor stub

* remove unnecessary error return from GetNodeFeatures
  • Loading branch information
Eslam-Nawara authored Sep 18, 2024
1 parent dbae7a5 commit 089d7c5
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 6 deletions.
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
}

// 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 {
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
}
16 changes: 16 additions & 0 deletions pkg/stubs/system_monitor_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ func (s *SystemMonitorStub) Disks(ctx context.Context) (<-chan pkg.DisksIOCounte
return ch, nil
}

func (s *SystemMonitorStub) GetNodeFeatures(ctx context.Context) (ret0 []pkg.NodeFeature) {
args := []interface{}{}
result, err := s.client.RequestContext(ctx, s.module, s.object, "GetNodeFeatures", args...)
if err != nil {
panic(err)
}
result.PanicOnError()
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_get", 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), nil
}
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

0 comments on commit 089d7c5

Please sign in to comment.