client

package
v0.15.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package client provides a simple RMB interface to work with the node.

Package client for node client

Package client provides a simple RMB interface to work with the node.

Requirements

1. A msg bus instance must be running on the node. this client uses RMB (message bus) to send messages to nodes, and get the responses. 2. A valid ed25519 key pair. this key is used to sign deployments and MUST be the same key used to configure the local twin on substrate.

Simple deployment

create an instance from the default rmb client. ``` cl, err := rmb.Default()

if err != nil {
	panic(err)
}

``` then create an instance of the node client ``` node := client.NewNodeClient(NodeTwinID, cl) ``` define your deployment object ```

dl := gridtypes.Deployment{
	Version: Version,
	twinID:  Twin, //LocalTwin,
	// this contract id must match the one on substrate
	Workloads: []gridtypes.Workload{
		network(), // network workload definition
		zmount(), // zmount workload definition
		publicip(), // public ip definition
		zmachine(), // zmachine definition
	},
	SignatureRequirement: gridtypes.SignatureRequirement{
		WeightRequired: 1,
		Requests: []gridtypes.SignatureRequest{
			{
				twinID: Twin,
				Weight: 1,
			},
		},
	},
}

``` compute hash ``` hash, err := dl.ChallengeHash()

if err != nil {
	panic("failed to create hash")
}

``` create the contract and ge the contract id then “ dl.ContractID = 11 // from substrate ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() err = node.DeploymentDeploy(ctx, dl)

if err != nil {
	panic(err)
}

```

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAccessibleInterfaceFound = errors.Errorf("could not find a publicly accessible ipv4 or ipv6")

ErrNoAccessibleInterfaceFound no accessible interface found

Functions

func AreNodesUp

func AreNodesUp(ctx context.Context, sub subi.SubstrateExt, nodes []uint32, nc NodeClientGetter) error

AreNodesUp checks if nodes are up

func TryDecodeBase64OrElse

func TryDecodeBase64OrElse(possiblyEncoded string) []byte

TryDecodeBase64OrElse tries to decode a possibly base64 encoded string into a byte array or returns the string as a byte array assuming it was decoded already

Types

type ExitDevice

type ExitDevice struct {
	// IsSingle is set to true if br-pub
	// is connected to zos bridge
	IsSingle bool `json:"is_single"`
	// IsDual is set to true if br-pub is
	// connected to a physical nic
	IsDual bool `json:"is_dual"`
	// AsDualInterface is set to the physical
	// interface name if IsDual is true
	AsDualInterface string `json:"dual_interface"`
}

ExitDevice stores the dual nic setup of a node.

type GPU

type GPU struct {
	ID       string `json:"id"`
	Vendor   string `json:"vendor"`
	Device   string `json:"device"`
	Contract uint64 `json:"contract"`
}

type IfaceType

type IfaceType string

IfaceType define the different public interface supported

type Interface

type Interface struct {
	IPs []string `json:"ips"`
	Mac string   `json:"mac"`
}

Interface stores physical network interface information

type NodeClient

type NodeClient struct {
	// contains filtered or unexported fields
}

NodeClient struct

func NewNodeClient

func NewNodeClient(nodeTwin uint32, bus rmb.Client, timeout time.Duration) *NodeClient

NewNodeClient creates a new node RMB client. This client then can be used to communicate with the node over RMB.

func (*NodeClient) DeploymentChanges

func (n *NodeClient) DeploymentChanges(ctx context.Context, contractID uint64) (changes []gridtypes.Workload, err error)

DeploymentChanges return changes of a deployment via contract ID

func (*NodeClient) DeploymentDelete

func (n *NodeClient) DeploymentDelete(ctx context.Context, contractID uint64) error

DeploymentDelete deletes a deployment, the node will make sure to decomission all deployments and set all workloads to deleted. A call to Get after delete is valid

func (*NodeClient) DeploymentDeploy

func (n *NodeClient) DeploymentDeploy(ctx context.Context, dl gridtypes.Deployment) error

DeploymentDeploy sends the deployment to the node for processing.

func (*NodeClient) DeploymentGet

func (n *NodeClient) DeploymentGet(ctx context.Context, contractID uint64) (dl gridtypes.Deployment, err error)

DeploymentGet gets a deployment via contract ID

func (*NodeClient) DeploymentList added in v0.14.13

func (n *NodeClient) DeploymentList(ctx context.Context) (dls []gridtypes.Deployment, err error)

DeploymentList gets all deployments for a twin

func (*NodeClient) DeploymentUpdate

func (n *NodeClient) DeploymentUpdate(ctx context.Context, dl gridtypes.Deployment) error

DeploymentUpdate update the given deployment. deployment must be a valid update for a deployment that has been already created via DeploymentDeploy

func (*NodeClient) GPUs

func (n *NodeClient) GPUs(ctx context.Context) (gpus []GPU, err error)

GPUs returns a list of gpus

func (*NodeClient) GetNodeEndpoint

func (n *NodeClient) GetNodeEndpoint(ctx context.Context) (net.IP, error)

GetNodeEndpoint gets node end point network ip

func (*NodeClient) GetNodeFreeWGPort

func (n *NodeClient) GetNodeFreeWGPort(ctx context.Context, nodeID uint32, usedPorts []uint16) (int, error)

GetNodeFreeWGPort returns node free wireguard port

func (*NodeClient) GetPerfTestResult added in v0.11.5

func (n *NodeClient) GetPerfTestResult(ctx context.Context, testName string) (result TaskResult, err error)

GetPerfTestResult get a single perf test result

func (*NodeClient) GetPerfTestResults added in v0.15.1

func (n *NodeClient) GetPerfTestResults(ctx context.Context) (result []TaskResult, err error)

GetPerfTestsResults get all perf tests results

func (*NodeClient) HasPublicIPv6

func (n *NodeClient) HasPublicIPv6(ctx context.Context) (bool, error)

HasPublicIPv6 returns true if the node has a public ip6 configuration

func (*NodeClient) IsNodeUp

func (n *NodeClient) IsNodeUp(ctx context.Context) error

IsNodeUp checks if the node is up

func (*NodeClient) NetworkGetPublicConfig

func (n *NodeClient) NetworkGetPublicConfig(ctx context.Context) (cfg PublicConfig, err error)

NetworkGetPublicConfig returns the current public node network configuration. A node with a public config can be used as an access node for wireguard.

func (*NodeClient) NetworkGetPublicExitDevice

func (n *NodeClient) NetworkGetPublicExitDevice(ctx context.Context) (exit ExitDevice, err error)

NetworkGetPublicExitDevice gets the current dual nic setup of the node.

func (*NodeClient) NetworkListAllInterfaces

func (n *NodeClient) NetworkListAllInterfaces(ctx context.Context) (result map[string]Interface, err error)

NetworkListAllInterfaces return all physical devices on a node

func (*NodeClient) NetworkListIPs

func (n *NodeClient) NetworkListIPs(ctx context.Context) ([]string, error)

NetworkListIPs list taken public IPs on the node

func (*NodeClient) NetworkListInterfaces

func (n *NodeClient) NetworkListInterfaces(ctx context.Context) (map[string][]net.IP, error)

NetworkListInterfaces return a map of all interfaces and their ips

func (*NodeClient) NetworkListPrivateIPs added in v0.14.13

func (n *NodeClient) NetworkListPrivateIPs(ctx context.Context, networkName string) ([]string, error)

NetworkListPrivateIPs list private ips reserved for a network

func (*NodeClient) NetworkListWGPorts

func (n *NodeClient) NetworkListWGPorts(ctx context.Context) ([]uint16, error)

NetworkListWGPorts return a list of all "taken" ports on the node. A new deployment should be careful to use a free port for its network setup.

func (*NodeClient) NetworkSetPublicConfig

func (n *NodeClient) NetworkSetPublicConfig(ctx context.Context, cfg PublicConfig) error

NetworkSetPublicConfig sets the current public node network configuration. A node with a public config can be used as an access node for wireguard.

func (*NodeClient) NetworkSetPublicExitDevice

func (n *NodeClient) NetworkSetPublicExitDevice(ctx context.Context, iface string) error

NetworkSetPublicExitDevice select which physical interface to use as an exit device setting `iface` to `zos` will then make node run in a single nic setup.

func (*NodeClient) Pools

func (n *NodeClient) Pools(ctx context.Context) (pools []PoolMetrics, err error)

Pools returns statistics of separate pools

func (*NodeClient) Statistics

func (n *NodeClient) Statistics(ctx context.Context) (total gridtypes.Capacity, used gridtypes.Capacity, err error)

Statistics returns some node statistics. Including total and available cpu, memory, storage, etc...

func (*NodeClient) SystemDMI

func (n *NodeClient) SystemDMI(ctx context.Context) (result dmi.DMI, err error)

SystemDMI executes dmidecode to get dmidecode output

func (*NodeClient) SystemHypervisor

func (n *NodeClient) SystemHypervisor(ctx context.Context) (result string, err error)

SystemHypervisor executes hypervisor cmd

func (*NodeClient) SystemVersion

func (n *NodeClient) SystemVersion(ctx context.Context) (ver Version, err error)

SystemVersion executes system version cmd

type NodeClientGetter

type NodeClientGetter interface {
	GetNodeClient(sub subi.SubstrateExt, nodeID uint32) (*NodeClient, error)
}

NodeClientGetter is an interface for node client

type NodeClientPool

type NodeClientPool struct {
	// contains filtered or unexported fields
}

NodeClientPool is a pool for node clients and rmb

func NewNodeClientPool

func NewNodeClientPool(rmb rmb.Client, timeout time.Duration) *NodeClientPool

NewNodeClientPool generates a new client pool

func (*NodeClientPool) GetNodeClient

func (p *NodeClientPool) GetNodeClient(sub subi.SubstrateExt, nodeID uint32) (*NodeClient, error)

GetNodeClient gets the node client according to node ID

type PoolMetrics

type PoolMetrics struct {
	Name string         `json:"name"`
	Type zos.DeviceType `json:"type"`
	Size gridtypes.Unit `json:"size"`
	Used gridtypes.Unit `json:"used"`
}

PoolMetrics stores storage pool metrics

type PublicConfig

type PublicConfig struct {
	// Type define if we need to use
	// the Vlan field or the MacVlan
	Type IfaceType `json:"type"`

	IPv4 gridtypes.IPNet `json:"ipv4"`
	IPv6 gridtypes.IPNet `json:"ipv6"`

	GW4 net.IP `json:"gw4"`
	GW6 net.IP `json:"gw6"`

	// Domain is the node domain name like gent01.devnet.grid.tf
	// or similar
	Domain string `json:"domain"`
}

PublicConfig is the configuration of the interface that is connected to the public internet

type TaskResult added in v0.15.1

type TaskResult struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Timestamp   uint64      `json:"timestamp"`
	Result      interface{} `json:"result"`
}

TaskResult holds the perf test result

type Version

type Version struct {
	ZOS   string `json:"zos"`
	ZInit string `json:"zinit"`
}

Version is ZOS version

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL