From 19566ef98113f4455bb2ffbeab21411d94f1643a Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Tue, 17 Sep 2024 17:17:23 +0300 Subject: [PATCH 1/5] add new endpoint to featch node features --- client/node.go | 9 +++++++-- docs/manual/api.md | 26 ++++++++++++++++++++++++++ pkg/network.go | 29 +++++++++++++++++++++++++++++ pkg/network/networker.go | 18 ++++++++++++++++++ pkg/stubs/network_stub.go | 17 +++++++++++++++++ pkg/zos_api/network.go | 8 ++++++++ pkg/zos_api/routes.go | 2 +- 7 files changed, 106 insertions(+), 3 deletions(-) diff --git a/client/node.go b/client/node.go index 073d0154b..79ec62515 100644 --- a/client/node.go +++ b/client/node.go @@ -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 @@ -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 @@ -322,6 +320,13 @@ func (n *NodeClient) NetworkGetPublicConfig(ctx context.Context) (cfg pkg.Public return } +func (n *NodeClient) NetworkGetNodeFeatures(ctx context.Context) (feat pkg.NodeFeatures, err error) { + const cmd = "zos.network.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" diff --git a/docs/manual/api.md b/docs/manual/api.md index 4127a5e4f..798fdbb86 100644 --- a/docs/manual/api.md +++ b/docs/manual/api.md @@ -149,6 +149,32 @@ PublicConfig { returns the node public config or error if not set. If a node has public config it means it can act like an access node to user private networks +### Get node features + +| command |body| return| +|---|---|---| +| `zos.network.node_features_get` | - |`NodeFeatures` | + +Where + +```json +NodeFeatures { + "zmount_type": "string", + "network_type": "string", + "zdb_type": "string", + "zmachine_type": "string", + "volume_type": "string", + "public_ipv4_type": "string", + "public_ip_type": "string", + "gateway_name_proxy_type": "string", + "gateway_fqdn_proxy_type": "string", + "qantum_safe_fs_type": "string", + "zlog_type": "string", +} +``` + +returns the features of the network manager running on the node + ## Admin The next set of commands are ONLY possible to be called by the `farmer` only. diff --git a/pkg/network.go b/pkg/network.go index f373cd215..7d3bbce66 100644 --- a/pkg/network.go +++ b/pkg/network.go @@ -198,6 +198,9 @@ type Networker interface { // Get node public namespace config GetPublicConfig() (PublicConfig, error) + // Get the features of the network manager running on the node + GetNodeFeatures() (NodeFeatures, error) + // GetPublicExitDevice either return "singe" or "dual()" GetPublicExitDevice() (ExitDevice, error) @@ -257,6 +260,32 @@ type PublicConfig struct { Domain string `json:"domain"` } +type NodeFeatures struct { + // ZMountType type + ZMountType gridtypes.WorkloadType `json:"zmount_type"` + // NetworkType type + NetworkType gridtypes.WorkloadType `json:"network_type"` + // ZDBType type + ZDBType gridtypes.WorkloadType `json:"zdb_type"` + // ZMachineType type + ZMachineType gridtypes.WorkloadType `json:"zmachine_type"` + // VolumeType type + VolumeType gridtypes.WorkloadType `json:"volume_type"` + // PublicIPv4Type type [deprecated] + PublicIPv4Type gridtypes.WorkloadType `json:"public_ipv4_type"` + // PublicIPType type is the new way to assign public ips + // to a VM. this has flags (V4, and V6) that has to be set. + PublicIPType gridtypes.WorkloadType `json:"public_ip_type"` + // GatewayNameProxyType type + GatewayNameProxyType gridtypes.WorkloadType `json:"gateway_name_proxy_type"` + // GatewayFQDNProxyType type + GatewayFQDNProxyType gridtypes.WorkloadType `json:"gateway_fqdn_proxy_type"` + // QuantumSafeFSType type + QuantumSafeFSType gridtypes.WorkloadType `json:"qantum_safe_fs_type"` + // ZLogsType type + ZLogsType gridtypes.WorkloadType `json:"zlog_type"` +} + func (p *PublicConfig) IsEmpty() bool { return p.IPv4.Nil() && p.IPv6.Nil() } diff --git a/pkg/network/networker.go b/pkg/network/networker.go index ccef4a6d0..1b86f3ba7 100644 --- a/pkg/network/networker.go +++ b/pkg/network/networker.go @@ -1139,6 +1139,24 @@ func (n *networker) GetPublicConfig() (pkg.PublicConfig, error) { return cfg, nil } +// Get the features of the network manager running on the node +func (n *networker) GetNodeFeatures() (pkg.NodeFeatures, error) { + feat := pkg.NodeFeatures{ + ZMountType: zos.ZMountType, + NetworkType: zos.NetworkType, + ZDBType: zos.ZDBType, + ZMachineType: zos.ZMachineType, + VolumeType: zos.VolumeType, + PublicIPv4Type: zos.PublicIPv4Type, + PublicIPType: zos.PublicIPType, + GatewayNameProxyType: zos.GatewayNameProxyType, + GatewayFQDNProxyType: zos.GatewayFQDNProxyType, + QuantumSafeFSType: zos.QuantumSafeFSType, + ZLogsType: zos.ZLogsType, + } + return feat, nil +} + func (n *networker) networkOf(id zos.NetID) (nr pkg.Network, err error) { path := filepath.Join(n.networkDir, string(id)) file, err := os.OpenFile(path, os.O_RDWR, 0660) diff --git a/pkg/stubs/network_stub.go b/pkg/stubs/network_stub.go index 9482e6f07..d49d45dc3 100644 --- a/pkg/stubs/network_stub.go +++ b/pkg/stubs/network_stub.go @@ -188,6 +188,23 @@ func (s *NetworkerStub) GetNet(ctx context.Context, arg0 zos.NetID) (ret0 net.IP return } +func (s *NetworkerStub) GetNodeFeatures(ctx context.Context) (ret0 pkg.NodeFeatures, 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 *NetworkerStub) GetPublicConfig(ctx context.Context) (ret0 pkg.PublicConfig, ret1 error) { args := []interface{}{} result, err := s.client.RequestContext(ctx, s.module, s.object, "GetPublicConfig", args...) diff --git a/pkg/zos_api/network.go b/pkg/zos_api/network.go index ecc524aa8..4ad9d57d8 100644 --- a/pkg/zos_api/network.go +++ b/pkg/zos_api/network.go @@ -13,9 +13,15 @@ import ( func (g *ZosAPI) networkListWGPortsHandler(ctx context.Context, payload []byte) (interface{}, error) { return g.networkerStub.WireguardPorts(ctx) } + func (g *ZosAPI) networkPublicConfigGetHandler(ctx context.Context, payload []byte) (interface{}, error) { return g.networkerStub.GetPublicConfig(ctx) } + +func (g *ZosAPI) networkNodeFeaturesGetHandler(ctx context.Context, payload []byte) (interface{}, error) { + return g.networkerStub.GetNodeFeatures(ctx) +} + func (g *ZosAPI) networkInterfacesHandler(ctx context.Context, payload []byte) (interface{}, error) { results := make(map[string][]net.IP) type q struct { @@ -42,11 +48,13 @@ func (g *ZosAPI) networkInterfacesHandler(ctx context.Context, payload []byte) ( return results, nil } + func (g *ZosAPI) networkHasIPv6Handler(ctx context.Context, payload []byte) (interface{}, error) { ipData, err := g.networkerStub.GetPublicIPv6Subnet(ctx) hasIP := ipData.IP != nil && err == nil return hasIP, err } + func (g *ZosAPI) networkListPublicIPsHandler(ctx context.Context, payload []byte) (interface{}, error) { return g.provisionStub.ListPublicIPs(ctx) } diff --git a/pkg/zos_api/routes.go b/pkg/zos_api/routes.go index 7fa70493a..f52820a21 100644 --- a/pkg/zos_api/routes.go +++ b/pkg/zos_api/routes.go @@ -5,7 +5,6 @@ import ( ) func (g *ZosAPI) SetupRoutes(router *peer.Router) { - root := router.SubRoute("zos") root.Use(g.log) system := root.SubRoute("system") @@ -27,6 +26,7 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) { network := root.SubRoute("network") network.WithHandler("list_wg_ports", g.networkListWGPortsHandler) network.WithHandler("public_config_get", g.networkPublicConfigGetHandler) + network.WithHandler("node_features_get", g.networkNodeFeaturesGetHandler) network.WithHandler("interfaces", g.networkInterfacesHandler) network.WithHandler("has_ipv6", g.networkHasIPv6Handler) network.WithHandler("list_public_ips", g.networkListPublicIPsHandler) From 98a467a9039a418f766abfc34271cae38eead05c Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Wed, 18 Sep 2024 13:43:10 +0300 Subject: [PATCH 2/5] move endpoint from network to system --- client/node.go | 4 ++-- docs/manual/api.md | 42 +++++++++++++++------------------------ pkg/network.go | 30 +++------------------------- pkg/network/networker.go | 26 ++++++++++++------------ pkg/stubs/network_stub.go | 2 +- pkg/zos_api/network.go | 4 ---- pkg/zos_api/routes.go | 2 +- pkg/zos_api/system.go | 4 ++++ 8 files changed, 40 insertions(+), 74 deletions(-) diff --git a/client/node.go b/client/node.go index 79ec62515..455f448fb 100644 --- a/client/node.go +++ b/client/node.go @@ -320,8 +320,8 @@ func (n *NodeClient) NetworkGetPublicConfig(ctx context.Context) (cfg pkg.Public return } -func (n *NodeClient) NetworkGetNodeFeatures(ctx context.Context) (feat pkg.NodeFeatures, err error) { - const cmd = "zos.network.node_features_get" +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 diff --git a/docs/manual/api.md b/docs/manual/api.md index 798fdbb86..250eb00f2 100644 --- a/docs/manual/api.md +++ b/docs/manual/api.md @@ -149,32 +149,6 @@ PublicConfig { returns the node public config or error if not set. If a node has public config it means it can act like an access node to user private networks -### Get node features - -| command |body| return| -|---|---|---| -| `zos.network.node_features_get` | - |`NodeFeatures` | - -Where - -```json -NodeFeatures { - "zmount_type": "string", - "network_type": "string", - "zdb_type": "string", - "zmachine_type": "string", - "volume_type": "string", - "public_ipv4_type": "string", - "public_ip_type": "string", - "gateway_name_proxy_type": "string", - "gateway_fqdn_proxy_type": "string", - "qantum_safe_fs_type": "string", - "zlog_type": "string", -} -``` - -returns the features of the network manager running on the node - ## Admin The next set of commands are ONLY possible to be called by the `farmer` only. @@ -243,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 diff --git a/pkg/network.go b/pkg/network.go index 7d3bbce66..103de5814 100644 --- a/pkg/network.go +++ b/pkg/network.go @@ -198,8 +198,8 @@ type Networker interface { // Get node public namespace config GetPublicConfig() (PublicConfig, error) - // Get the features of the network manager running on the node - GetNodeFeatures() (NodeFeatures, error) + // Get the types of workloads can be deployed depending on the network manager running on the node + GetNodeFeatures() ([]NodeFeature, error) // GetPublicExitDevice either return "singe" or "dual()" GetPublicExitDevice() (ExitDevice, error) @@ -260,31 +260,7 @@ type PublicConfig struct { Domain string `json:"domain"` } -type NodeFeatures struct { - // ZMountType type - ZMountType gridtypes.WorkloadType `json:"zmount_type"` - // NetworkType type - NetworkType gridtypes.WorkloadType `json:"network_type"` - // ZDBType type - ZDBType gridtypes.WorkloadType `json:"zdb_type"` - // ZMachineType type - ZMachineType gridtypes.WorkloadType `json:"zmachine_type"` - // VolumeType type - VolumeType gridtypes.WorkloadType `json:"volume_type"` - // PublicIPv4Type type [deprecated] - PublicIPv4Type gridtypes.WorkloadType `json:"public_ipv4_type"` - // PublicIPType type is the new way to assign public ips - // to a VM. this has flags (V4, and V6) that has to be set. - PublicIPType gridtypes.WorkloadType `json:"public_ip_type"` - // GatewayNameProxyType type - GatewayNameProxyType gridtypes.WorkloadType `json:"gateway_name_proxy_type"` - // GatewayFQDNProxyType type - GatewayFQDNProxyType gridtypes.WorkloadType `json:"gateway_fqdn_proxy_type"` - // QuantumSafeFSType type - QuantumSafeFSType gridtypes.WorkloadType `json:"qantum_safe_fs_type"` - // ZLogsType type - ZLogsType gridtypes.WorkloadType `json:"zlog_type"` -} +type NodeFeature string func (p *PublicConfig) IsEmpty() bool { return p.IPv4.Nil() && p.IPv6.Nil() diff --git a/pkg/network/networker.go b/pkg/network/networker.go index 1b86f3ba7..8fc6b2aff 100644 --- a/pkg/network/networker.go +++ b/pkg/network/networker.go @@ -1140,19 +1140,19 @@ func (n *networker) GetPublicConfig() (pkg.PublicConfig, error) { } // Get the features of the network manager running on the node -func (n *networker) GetNodeFeatures() (pkg.NodeFeatures, error) { - feat := pkg.NodeFeatures{ - ZMountType: zos.ZMountType, - NetworkType: zos.NetworkType, - ZDBType: zos.ZDBType, - ZMachineType: zos.ZMachineType, - VolumeType: zos.VolumeType, - PublicIPv4Type: zos.PublicIPv4Type, - PublicIPType: zos.PublicIPType, - GatewayNameProxyType: zos.GatewayNameProxyType, - GatewayFQDNProxyType: zos.GatewayFQDNProxyType, - QuantumSafeFSType: zos.QuantumSafeFSType, - ZLogsType: zos.ZLogsType, +func (n *networker) 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 } diff --git a/pkg/stubs/network_stub.go b/pkg/stubs/network_stub.go index d49d45dc3..86ca18fb1 100644 --- a/pkg/stubs/network_stub.go +++ b/pkg/stubs/network_stub.go @@ -188,7 +188,7 @@ func (s *NetworkerStub) GetNet(ctx context.Context, arg0 zos.NetID) (ret0 net.IP return } -func (s *NetworkerStub) GetNodeFeatures(ctx context.Context) (ret0 pkg.NodeFeatures, ret1 error) { +func (s *NetworkerStub) 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 { diff --git a/pkg/zos_api/network.go b/pkg/zos_api/network.go index 4ad9d57d8..78bb754ae 100644 --- a/pkg/zos_api/network.go +++ b/pkg/zos_api/network.go @@ -18,10 +18,6 @@ func (g *ZosAPI) networkPublicConfigGetHandler(ctx context.Context, payload []by return g.networkerStub.GetPublicConfig(ctx) } -func (g *ZosAPI) networkNodeFeaturesGetHandler(ctx context.Context, payload []byte) (interface{}, error) { - return g.networkerStub.GetNodeFeatures(ctx) -} - func (g *ZosAPI) networkInterfacesHandler(ctx context.Context, payload []byte) (interface{}, error) { results := make(map[string][]net.IP) type q struct { diff --git a/pkg/zos_api/routes.go b/pkg/zos_api/routes.go index f52820a21..a2af1064e 100644 --- a/pkg/zos_api/routes.go +++ b/pkg/zos_api/routes.go @@ -12,6 +12,7 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) { 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) @@ -26,7 +27,6 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) { network := root.SubRoute("network") network.WithHandler("list_wg_ports", g.networkListWGPortsHandler) network.WithHandler("public_config_get", g.networkPublicConfigGetHandler) - network.WithHandler("node_features_get", g.networkNodeFeaturesGetHandler) network.WithHandler("interfaces", g.networkInterfacesHandler) network.WithHandler("has_ipv6", g.networkHasIPv6Handler) network.WithHandler("list_public_ips", g.networkListPublicIPsHandler) diff --git a/pkg/zos_api/system.go b/pkg/zos_api/system.go index 7bae7beb6..e75a5fe43 100644 --- a/pkg/zos_api/system.go +++ b/pkg/zos_api/system.go @@ -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.networkerStub.GetNodeFeatures(ctx) +} From 62c75b85b08732a35b01c9a507fa25160c773086 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Wed, 18 Sep 2024 13:55:25 +0300 Subject: [PATCH 3/5] move GetNodeFeatures to system monitor --- pkg/monitor.go | 4 ++++ pkg/monitord/system.go | 23 ++++++++++++++++++++--- pkg/network.go | 5 ----- pkg/network/networker.go | 18 ------------------ pkg/zos_api/network.go | 4 ---- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/pkg/monitor.go b/pkg/monitor.go index 6e3f30199..c28b153f9 100644 --- a/pkg/monitor.go +++ b/pkg/monitor.go @@ -78,6 +78,9 @@ 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 @@ -85,6 +88,7 @@ type SystemMonitor interface { CPU(ctx context.Context) <-chan TimesStat Disks(ctx context.Context) <-chan DisksIOCountersStat Nics(ctx context.Context) <-chan NicsIOCounterStat + GetNodeFeatures() ([]NodeFeature, error) } // HostMonitor interface (provided by noded) diff --git a/pkg/monitord/system.go b/pkg/monitord/system.go index 0f3853a75..5e81a52d0 100644 --- a/pkg/monitord/system.go +++ b/pkg/monitord/system.go @@ -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 { @@ -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 +} diff --git a/pkg/network.go b/pkg/network.go index 103de5814..f373cd215 100644 --- a/pkg/network.go +++ b/pkg/network.go @@ -198,9 +198,6 @@ type Networker interface { // Get node public namespace config GetPublicConfig() (PublicConfig, error) - // Get the types of workloads can be deployed depending on the network manager running on the node - GetNodeFeatures() ([]NodeFeature, error) - // GetPublicExitDevice either return "singe" or "dual()" GetPublicExitDevice() (ExitDevice, error) @@ -260,8 +257,6 @@ type PublicConfig struct { Domain string `json:"domain"` } -type NodeFeature string - func (p *PublicConfig) IsEmpty() bool { return p.IPv4.Nil() && p.IPv6.Nil() } diff --git a/pkg/network/networker.go b/pkg/network/networker.go index 8fc6b2aff..ccef4a6d0 100644 --- a/pkg/network/networker.go +++ b/pkg/network/networker.go @@ -1139,24 +1139,6 @@ func (n *networker) GetPublicConfig() (pkg.PublicConfig, error) { return cfg, nil } -// Get the features of the network manager running on the node -func (n *networker) 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 -} - func (n *networker) networkOf(id zos.NetID) (nr pkg.Network, err error) { path := filepath.Join(n.networkDir, string(id)) file, err := os.OpenFile(path, os.O_RDWR, 0660) diff --git a/pkg/zos_api/network.go b/pkg/zos_api/network.go index 78bb754ae..ecc524aa8 100644 --- a/pkg/zos_api/network.go +++ b/pkg/zos_api/network.go @@ -13,11 +13,9 @@ import ( func (g *ZosAPI) networkListWGPortsHandler(ctx context.Context, payload []byte) (interface{}, error) { return g.networkerStub.WireguardPorts(ctx) } - func (g *ZosAPI) networkPublicConfigGetHandler(ctx context.Context, payload []byte) (interface{}, error) { return g.networkerStub.GetPublicConfig(ctx) } - func (g *ZosAPI) networkInterfacesHandler(ctx context.Context, payload []byte) (interface{}, error) { results := make(map[string][]net.IP) type q struct { @@ -44,13 +42,11 @@ func (g *ZosAPI) networkInterfacesHandler(ctx context.Context, payload []byte) ( return results, nil } - func (g *ZosAPI) networkHasIPv6Handler(ctx context.Context, payload []byte) (interface{}, error) { ipData, err := g.networkerStub.GetPublicIPv6Subnet(ctx) hasIP := ipData.IP != nil && err == nil return hasIP, err } - func (g *ZosAPI) networkListPublicIPsHandler(ctx context.Context, payload []byte) (interface{}, error) { return g.provisionStub.ListPublicIPs(ctx) } From 80305352a3e448ade9a3a28e135d63a583a4a3c5 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Wed, 18 Sep 2024 13:59:56 +0300 Subject: [PATCH 4/5] generate get node features function in system monitor stub --- pkg/stubs/network_stub.go | 17 ----------------- pkg/stubs/system_monitor_stub.go | 17 +++++++++++++++++ pkg/zos_api/system.go | 2 +- pkg/zos_api/zos_api.go | 2 ++ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pkg/stubs/network_stub.go b/pkg/stubs/network_stub.go index 86ca18fb1..9482e6f07 100644 --- a/pkg/stubs/network_stub.go +++ b/pkg/stubs/network_stub.go @@ -188,23 +188,6 @@ func (s *NetworkerStub) GetNet(ctx context.Context, arg0 zos.NetID) (ret0 net.IP return } -func (s *NetworkerStub) 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 *NetworkerStub) GetPublicConfig(ctx context.Context) (ret0 pkg.PublicConfig, ret1 error) { args := []interface{}{} result, err := s.client.RequestContext(ctx, s.module, s.object, "GetPublicConfig", args...) diff --git a/pkg/stubs/system_monitor_stub.go b/pkg/stubs/system_monitor_stub.go index b98bd9ae3..a313f7edc 100644 --- a/pkg/stubs/system_monitor_stub.go +++ b/pkg/stubs/system_monitor_stub.go @@ -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") diff --git a/pkg/zos_api/system.go b/pkg/zos_api/system.go index e75a5fe43..2fa1a0048 100644 --- a/pkg/zos_api/system.go +++ b/pkg/zos_api/system.go @@ -39,5 +39,5 @@ func (g *ZosAPI) systemDiagnosticsHandler(ctx context.Context, payload []byte) ( } func (g *ZosAPI) systemNodeFeaturesHandler(ctx context.Context, payload []byte) (interface{}, error) { - return g.networkerStub.GetNodeFeatures(ctx) + return g.systemMonitorStub.GetNodeFeatures(ctx) } diff --git a/pkg/zos_api/zos_api.go b/pkg/zos_api/zos_api.go index 3e21ef61b..e3661f706 100644 --- a/pkg/zos_api/zos_api.go +++ b/pkg/zos_api/zos_api.go @@ -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 @@ -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), From fa18ffdd4e4c0c7b277831d111de3ccad37e1cd2 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Wed, 18 Sep 2024 14:46:27 +0300 Subject: [PATCH 5/5] remove unnecessary error return from GetNodeFeatures --- pkg/monitor.go | 2 +- pkg/monitord/system.go | 4 ++-- pkg/stubs/system_monitor_stub.go | 3 +-- pkg/zos_api/routes.go | 2 +- pkg/zos_api/system.go | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/monitor.go b/pkg/monitor.go index c28b153f9..39a6de7da 100644 --- a/pkg/monitor.go +++ b/pkg/monitor.go @@ -88,7 +88,7 @@ type SystemMonitor interface { CPU(ctx context.Context) <-chan TimesStat Disks(ctx context.Context) <-chan DisksIOCountersStat Nics(ctx context.Context) <-chan NicsIOCounterStat - GetNodeFeatures() ([]NodeFeature, error) + GetNodeFeatures() []NodeFeature } // HostMonitor interface (provided by noded) diff --git a/pkg/monitord/system.go b/pkg/monitord/system.go index 5e81a52d0..05ac7f35c 100644 --- a/pkg/monitord/system.go +++ b/pkg/monitord/system.go @@ -200,7 +200,7 @@ func (m *systemMonitor) Nics(ctx context.Context) <-chan pkg.NicsIOCounterStat { } // Get the types of workloads can be deployed depending on the network manager running on the node -func (n *systemMonitor) GetNodeFeatures() ([]pkg.NodeFeature, error) { +func (n *systemMonitor) GetNodeFeatures() []pkg.NodeFeature { feat := []pkg.NodeFeature{ pkg.NodeFeature(zos.ZMountType), pkg.NodeFeature(zos.NetworkType), @@ -214,5 +214,5 @@ func (n *systemMonitor) GetNodeFeatures() ([]pkg.NodeFeature, error) { pkg.NodeFeature(zos.QuantumSafeFSType), pkg.NodeFeature(zos.ZLogsType), } - return feat, nil + return feat } diff --git a/pkg/stubs/system_monitor_stub.go b/pkg/stubs/system_monitor_stub.go index a313f7edc..2ffc04907 100644 --- a/pkg/stubs/system_monitor_stub.go +++ b/pkg/stubs/system_monitor_stub.go @@ -75,14 +75,13 @@ 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) { +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() - ret1 = result.CallError() loader := zbus.Loader{ &ret0, } diff --git a/pkg/zos_api/routes.go b/pkg/zos_api/routes.go index a2af1064e..8006f23b7 100644 --- a/pkg/zos_api/routes.go +++ b/pkg/zos_api/routes.go @@ -12,7 +12,7 @@ func (g *ZosAPI) SetupRoutes(router *peer.Router) { system.WithHandler("dmi", g.systemDMIHandler) system.WithHandler("hypervisor", g.systemHypervisorHandler) system.WithHandler("diagnostics", g.systemDiagnosticsHandler) - system.WithHandler("node_features", g.systemNodeFeaturesHandler) + system.WithHandler("node_features_get", g.systemNodeFeaturesHandler) perf := root.SubRoute("perf") perf.WithHandler("get", g.perfGetHandler) diff --git a/pkg/zos_api/system.go b/pkg/zos_api/system.go index 2fa1a0048..88b775177 100644 --- a/pkg/zos_api/system.go +++ b/pkg/zos_api/system.go @@ -39,5 +39,5 @@ func (g *ZosAPI) systemDiagnosticsHandler(ctx context.Context, payload []byte) ( } func (g *ZosAPI) systemNodeFeaturesHandler(ctx context.Context, payload []byte) (interface{}, error) { - return g.systemMonitorStub.GetNodeFeatures(ctx) + return g.systemMonitorStub.GetNodeFeatures(ctx), nil }