Skip to content

Commit

Permalink
add new endpoint to featch node features
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Sep 17, 2024
1 parent dbae7a5 commit 19566ef
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 3 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) 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"

Expand Down
26 changes: 26 additions & 0 deletions docs/manual/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions pkg/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(<nic>)"
GetPublicExitDevice() (ExitDevice, error)

Expand Down Expand Up @@ -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()
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/network/networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions pkg/stubs/network_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
8 changes: 8 additions & 0 deletions pkg/zos_api/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
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,7 +5,6 @@ import (
)

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

root := router.SubRoute("zos")
root.Use(g.log)
system := root.SubRoute("system")
Expand All @@ -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)
Expand Down

0 comments on commit 19566ef

Please sign in to comment.