The client
package provides a simple RMB interface to work with nodes.
- Message Bus (msgbusd): A
msgbusd
instance must be running on the node. This client uses RMB to send messages and receive responses. - ED25519 Key Pair: A valid ed25519 key pair is required. This key is used to sign deployments and must match the key configured for the local twin on substrate.
cl, err := rmb.Default()
if err != nil {
panic(err)
}
node := client.NewNodeClient(NodeTwinID, cl)
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,
},
},
},
}
hash, err := dl.ChallengeHash()
if err != nil {
panic("failed to create hash")
}
fmt.Printf("Hash: %x\n", hash)
dl.ContractID = 11 // Contract ID from substrate
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err = node.DeploymentDeploy(ctx, dl)
if err != nil {
panic(err)
}
Sends the deployment to the node for processing.
func (n *NodeClient) DeploymentDeploy(ctx context.Context, dl gridtypes.Deployment) error
Updates a given deployment.
Deployment must be a valid update for a deployment that has been already created via DeploymentDeploy
func (n *NodeClient) DeploymentUpdate(ctx context.Context, dl gridtypes.Deployment) error
Gets a deployment via contract ID
func (n *NodeClient) DeploymentGet(ctx context.Context, contractID uint64) (gridtypes.Deployment, error)
List all deployments on the node for a twin.
func (n *NodeClient) DeploymentList(ctx context.Context) ([]gridtypes.Deployment, error)
Get changes to a deployment by contract ID.
func (n *NodeClient) DeploymentChanges(ctx context.Context, contractID uint64) ([]gridtypes.Workload, error)
Delete a deployment.
func (n *NodeClient) DeploymentDelete(ctx context.Context, contractID uint64) error
Gets node statistics, including total and available cpu, memory, storage, etc...
func (n *NodeClient) Counters(ctx context.Context) (Counters, error)
Returns the statistics of separate pools
func (n *NodeClient) Pools(ctx context.Context) ([]pkg.PoolMetrics, error)
Gets a list of GPUs on the node.
func (n *NodeClient) GPUs(ctx context.Context) ([]GPU, error)
List return a list of all "taken" ports on the node.
func (n *NodeClient) NetworkListWGPorts(ctx context.Context) ([]uint16, error)
Check if the node has a public IP of version 6 address.
func (n *NodeClient) HasPublicIPv6(ctx context.Context) (bool, error)
Retrieve all interfaces on the node.
func (n *NodeClient) NetworkListInterfaces(ctx context.Context) (map[string][]net.IP, error)
List taken public IPs on the node
func (n *NodeClient) NetworkListPublicIPs(ctx context.Context) ([]string, error)
Retrieve all private IPs reserved for a network.
func (n *NodeClient) NetworkListPrivateIPs(ctx context.Context, networkName string) ([]string, error)
Retuns the current public network configuration for the node.
func (n *NodeClient) NetworkGetPublicConfig(ctx context.Context) (pkg.PublicConfig, error)
Returns the system version.
func (n *NodeClient) SystemVersion(ctx context.Context) (Version, error)
Gets features of the node (This can be used to indicate if the node is of version 3 or 4).
func (n *NodeClient) SystemGetNodeFeatures(ctx context.Context) ([]pkg.NodeFeature, error)
Returns DMI information for the node.
func (n *NodeClient) SystemDMI(ctx context.Context) (dmi.DMI, error)
Gets the name of the hypervisor used on the node
func (n *NodeClient) SystemHypervisor(ctx context.Context) (string, error)
Runs diagnostics on the system.
func (n *NodeClient) SystemDiagnostics(ctx context.Context) (diagnostics.Diagnostics, error)
List all physical devices on a node
func (n *NodeClient) NetworkListAllInterfaces(ctx context.Context) (map[string]Interface, error)
Set which physical interface to use as the exit device.
func (n *NodeClient) NetworkSetPublicExitDevice(ctx context.Context, iface string) error
Get the current dual NIC setup of the node.
func (n *NodeClient) NetworkGetPublicExitDevice(ctx context.Context) (ExitDevice, error)
Represents the node client.
type NodeClient struct {
nodeTwin uint32
bus rmb.Client
}
Represents system version information.
type Version struct {
ZOS string `json:"zos"`
ZInit string `json:"zinit"`
}
Represents network interface information.
type Interface struct {
IPs []string `json:"ips"`
Mac string `json:"mac"`
}
Represents exit device configuration.
type ExitDevice struct {
IsSingle bool `json:"is_single"`
IsDual bool `json:"is_dual"`
AsDualInterface string `json:"dual_interface"`
}
Represents node statistics.
type Counters struct {
Total gridtypes.Capacity `json:"total"`
Used gridtypes.Capacity `json:"used"`
System gridtypes.Capacity `json:"system"`
Users UsersCounters `json:"users"`
}
Represents deployment and workload statistics.
type UsersCounters struct {
Deployments int `json:"deployments"`
Workloads int `json:"workloads"`
}
Represents GPU information.
type GPU struct {
ID string `json:"id"`
Vendor string `json:"vendor"`
Device string `json:"device"`
Contract uint64 `json:"contract"`
}