client

package
v0.0.0-...-d63b7b6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

ThreeFold Grid Node Registrar Client

A Go client for interacting with the ThreeFold Grid Node Registrar service. Facilitates node registration and management on the ThreeFold Grid.

Overview

The Node Registrar Client enables communication with the ThreeFold Grid's node registration service. It provides methods to:

  • Register nodes
  • Manage node metadata
  • Retrieve node information
  • Delete node registrations

Features

Version
  • Get Zos Version: Loads zos version for the current network
  • Set Zos Version: Set zos version to specific version (can only be done by the network admin)
Accounts
  • Create Account: Create new account on the registrar with uniqe key.
  • Update Account: Update the account configuration (relays & rmbEncKey).
  • Ensure Account: Ensures that an account is created with specific seed/mnemonic.
  • Get Account: Get an account using either its twin_id or its public_key.
Farms
  • Create Farm: Create new farm on the registrar with uniqe name.
  • update Farm: Update farm configuration (farm_id, dedicated).
  • Get Farm: Get a farm using its farm_id.
Node
  • Register Node: Register physical/virtual nodes with on TFGrid.
  • Update Node: Update node configuration (farm_id, interfaces, resources, location, secure_boot, virtualized).
  • Get Node: Fetch registered node details using (node_id, twin_id, farm_id).
  • Update Node Uptime: Update node Uptime.
API Methods
Version Operations
Method Description Parameters Returns
GetZosVersion Get current zos version None (ZosVersion, error)
SetZosVersion Update zos version (admin-only) version string, safeToUpgrade bool error
Account Management
Method Description Parameters Returns
CreateAccount Create new account relays []string, rmbEncKey string (Account, error)
EnsureAccount Create account if missing relays []string, rmbEncKey string (Account, error)
GetAccount Get account by twin ID twinID uint64 (Account, error)
GetAccountByPK Get account by public key publicKey string (Account, error)
UpdateAccount Modify account config ...UpdateOption error
Farm Operations
Method Description Parameters Returns
CreateFarm Register new farm name string, twinID uint64, dedicated bool (uint64, error)
UpdateFarm Modify farm properties farmID uint64, ...UpdateOption error
GetFarm Get farm by ID farmID uint64 (Farm, error)
ListFarms List farms ...ListOption ([]Farm, error)
Node Operations
Method Description Parameters Returns
RegisterNode Register new node farmID uint64, twinID uint64, interfaces []Interface, location Location, resources Resources, serial string, secureBoot bool, virtualized bool (uint64, error)
UpdateNode Modify node config ...UpdateOption error
GetNode Get node by node ID nodeID uint64 (Node, error)
GetNodeByTwinID Get node by twin ID twinID uint64 (Node, error)
ListNodes List nodes ...ListOption ([]Node, error)
ReportUptime Submit uptime metrics report UptimeReport error

Installation

go get github.com/threefoldtech/tfgrid4-sdk-go/node-registrar/client

Usage

Initialize Client
import (
  "github.com/threefoldtech/tfgrid4-sdk-go/node-registrar/client"
)

func main() {
  registrarURL := "https://registrar.dev4.grid.tf/v1"

 // Generate 128-bit entropy (12-word mnemonic)
 entropy, err := bip39.NewEntropy(128)
 if err != nil {
   panic(err)
 }

 // Generate mnemonic from entropy
 mnemonic, err = bip39.NewMnemonic(entropy)
 if err != nil {
   panic(err)
 }
  fmt.Println("New Mnemonic:", mnemonic)
  
  cli, err := client.NewRegistrarClient(registrarURL, mnemonic)
  if err != nil {
    panic(err)
  }
}
Get Zos Version
 version, err := c.GetZosVersion()
 if err != nil {
   log.Fatal().Err(err).Msg("failed to set registrar version")
 }

 log.Info().Msgf("%s version is: %+v", network, version)
Set Zos Version (ONLY for network admin)
 err := c.SetZosVersion("v0.1.8", true)
 if err != nil {
   log.Fatal().Err(err).Msg("failed to set registrar version")
 }

 log.Info().Msg("version is updated successfully")
Create Account
 account, err := c.CreateAccount(relays, rmbEncKey)
 if err != nil {
   log.Fatal().Err(err).Msg("failed to create new account on registrar")
 }

log.Info().Uint64("twinID", account.TwinID).Msg("account created successfully")

Get Account
Get Account By Public Key
 account, err := c.GetAccountByPK(pk)
 if err != nil {
   log.Fatal().Err(err).Msg("failed to get account from registrar")
 }
 log.Info().Any("account", account).Send()
Get Account By Twin ID
 account, err := c.GetAccount(id)
 if err != nil {
   log.Fatal().Err(err).Msg("failed to get account from registrar")
 }
 log.Info().Any("account", account).Send()

Update Account
 err := c.UpdateAccount(client.UpdateAccountWithRelays(relays), client.UpdateAccountWithRMBEncKey(rmbEncKey))
 if err != nil {
   log.Fatal().Err(err).Msg("failed to get account from registrar")
 }
 log.Info().Msg("account updated successfully")
Ensure Account
 account, err := c.EnsureAccount(relays, rmbEncKey)
 if err != nil {
  log.Fatal().Err(err).Msg("failed to ensure account account from registrar")
 }
 log.Info().Any("account", account).Send()
Create Farm
 id, err := c.CreateFarm(farmName, twinID, false)
 if err != nil {
  log.Fatal().Err(err).Msg("failed to create new farm on registrar")
 }

 log.Info().Uint64("farmID", id).Msg("farm created successfully")
Get Farm
 farm, err := c.GetFarm(id)
 if err != nil {
  log.Fatal().Err(err).Msg("failed to get farm from registrar")
 }
 log.Info().Any("farm", farm).Send()
List Farms
 farms, err := c.ListFarms(ListFarmWithName(name))
 if err != nil {
  log.Fatal().Err(err).Msg("failed to list farms from registrar")
 }
 log.Info().Any("farm", farms[0]).Send()
Update Farm
 err := c.UpdateFarm(farmID, client.UpdateFarmWithName(name))
 if err != nil {
  log.Fatal().Err(err).Msg("failed to get farm from registrar")
 }
 log.Info().Msg("farm updated successfully")
Register a Node
 id, err := c.RegisterNode(farmID, twinID, interfaces, location, resources, serialNumber, secureBoot, virtualized)
 if err != nil {
   log.Fatal().Err(err).Msg("failed to register a new node on registrar")
 }
 log.Info().Uint64("nodeID", id).Msg("node registered successfully")
Get Node
Get Node With Node ID
 node, err := c.GetNode(id)
 if err != nil {
  log.Fatal().Err(err).Msg("failed to get node from registrar")
 }
 log.Info().Any("node", node).Send()
Get Node With Twin ID
 node, err := c.GetNodeByTwinID(id)
 if err != nil {
  log.Fatal().Err(err).Msg("failed to get node from registrar")
 }
 log.Info().Any("node", node).Send()
List Nodes
 nodes, err := c.ListNodes(client.ListNodesWithFarmID(id))
 if err != nil {
  log.Fatal().Err(err).Msg("failed to list nodes from registrar")
 }
 log.Info().Any("node", node[0]).Send()
Update Node
 err := c.UpdateNode(client.UpdateNodesWithLocation(location))
 if err != nil {
  log.Fatal().Err(err).Msg("failed to update node location on the registrar")
 }
 log.Info().Msg("node updated successfully")
Update Node Uptime
 err := c.ReportUptime(report)
 if err != nil {
  log.Fatal().Err(err).Msg("failed to update node uptime in the registrar")
 }
 log.Info().Msg("node uptime is updated successfully")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorAccountNotFound = fmt.Errorf("failed to get requested account from node registrar")
View Source
var ErrorFarmNotFound = fmt.Errorf("failed to get requested farm from node registrar")
View Source
var ErrorNodeNotFound = fmt.Errorf("failed to get requested node from node registrar")

Functions

This section is empty.

Types

type Account

type Account struct {
	TwinID    uint64   `json:"twin_id"`
	Relays    []string `json:"relays"`      // Optional list of relay domains
	RMBEncKey string   `json:"rmb_enc_key"` // Optional base64 encoded public key for rmb communication
	PublicKey string   `json:"public_key"`
}

type Farm

type Farm struct {
	FarmID         uint64 `json:"farm_id"`
	FarmName       string `json:"farm_name"`
	TwinID         uint64 `json:"twin_id"`
	Dedicated      bool   `json:"dedicated"`
	StellarAddress string `json:"stellar_address"`
}

type FarmFilter

type FarmFilter struct {
	FarmID    *uint64
	FarmName  *string
	TwinID    *uint64
	Dedicated *bool
	Page      *uint32
	Size      *uint32
}

FarmFilter represents filtering options for listing farms

type FarmUpdate

type FarmUpdate struct {
	FarmName       *string
	StellarAddress *string
	Dedicated      *bool
}

FarmUpdate represents the data needed to update an existing farm

type Interface

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

type Location

type Location struct {
	Country   string `json:"country"`
	City      string `json:"city"`
	Longitude string `json:"longitude"`
	Latitude  string `json:"latitude"`
}

type Node

type Node struct {
	NodeID        uint64         `json:"node_id"`
	FarmID        uint64         `json:"farm_id"`
	TwinID        uint64         `json:"twin_id"`
	Location      Location       `json:"location"`
	Resources     Resources      `json:"resources"`
	Interfaces    []Interface    `json:"interfaces"`
	SecureBoot    bool           `json:"secure_boot"`
	Virtualized   bool           `json:"virtualized"`
	SerialNumber  string         `json:"serial_number"`
	UptimeReports []UptimeReport `json:"uptime"`
	LastSeen      *time.Time     `json:"last_seen"`
	Online        bool           `json:"online"`
	Approved      bool
}

type NodeFilter

type NodeFilter struct {
	NodeID   *uint64
	FarmID   *uint64
	TwinID   *uint64
	Status   *string
	Healthy  *bool
	Online   *bool
	LastSeen *int64
	Page     *uint32
	Size     *uint32
}

NodeFilter represents filtering options for listing nodes

type NodeUpdate

type NodeUpdate struct {
	FarmID       *uint64
	Location     *Location
	Resources    *Resources
	Interfaces   []Interface
	SecureBoot   *bool
	Virtualized  *bool
	SerialNumber *string
	Status       *string
	Healthy      *bool
	Approved     *bool
}

NodeUpdate represents update options for a node

type RegistrarClient

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

func NewRegistrarClient

func NewRegistrarClient(baseURL string, mnemonicOrSeed ...string) (cli RegistrarClient, err error)

NewRegistrarClient creates a new client with optional seed or mnemonic

func (*RegistrarClient) CreateAccount

func (c *RegistrarClient) CreateAccount(relays []string, rmbEncKey string) (account Account, mnemonic string, err error)

CreateAccount create new account on the registrar with uniqe mnemonic.

func (*RegistrarClient) CreateFarm

func (c *RegistrarClient) CreateFarm(farmName, stellarAddr string, dedicated bool) (farmID uint64, err error)

CreateFarm create new farm on the registrar with uniqe name.

func (*RegistrarClient) EnsureAccount

func (c *RegistrarClient) EnsureAccount(relays []string, rmbEncKey string) (account Account, err error)

EnsureAccount ensures that an account is created with specific seed/mnemonic.

func (*RegistrarClient) GetAccount

func (c *RegistrarClient) GetAccount(twinID uint64) (account Account, err error)

GetAccount get an account using either its twinID

func (*RegistrarClient) GetAccountByPK

func (c *RegistrarClient) GetAccountByPK(publicKey []byte) (account Account, err error)

GetAccountByPK get an account using either its its publicKey.

func (*RegistrarClient) GetFarm

func (c *RegistrarClient) GetFarm(farmID uint64) (farm Farm, err error)

GetFarm get a farm using its farmID

func (*RegistrarClient) GetNode

func (c *RegistrarClient) GetNode(id uint64) (node Node, err error)

GetNode gets registered node details using nodeID

func (*RegistrarClient) GetNodeByTwinID

func (c *RegistrarClient) GetNodeByTwinID(id uint64) (node Node, err error)

GetNodeByTwinID gets registered node details using twinID

func (*RegistrarClient) GetZosVersion

func (c *RegistrarClient) GetZosVersion() (version ZosVersion, err error)

GetZosVersion gets zos version for specific network

func (*RegistrarClient) ListFarms

func (c *RegistrarClient) ListFarms(filter FarmFilter) (farms []Farm, err error)

ListFarms gets a list of farms using filter options

func (*RegistrarClient) ListNodes

func (c *RegistrarClient) ListNodes(opts NodeFilter) (nodes []Node, err error)

ListNodes lists registered nodes details using (nodeID, twinID, farmID).

func (*RegistrarClient) Mnemonic

func (c *RegistrarClient) Mnemonic() string

func (*RegistrarClient) RegisterNode

func (c *RegistrarClient) RegisterNode(node Node) (nodeID uint64, err error)

RegisterNode register physical/virtual nodes with on TFGrid.

func (*RegistrarClient) ReportUptime

func (c *RegistrarClient) ReportUptime(report UptimeReport) (err error)

ReportUptime update node Uptime.

func (*RegistrarClient) SetZosVersion

func (c *RegistrarClient) SetZosVersion(v string, safeToUpgrade bool) (err error)

SetZosVersion sets zos version for specific network only valid for network admin

func (*RegistrarClient) UpdateAccount

func (c *RegistrarClient) UpdateAccount(opts ...UpdateAccountOpts) (err error)

UpdateAccount update the account configuration (relays or rmbEncKey).

func (*RegistrarClient) UpdateFarm

func (c *RegistrarClient) UpdateFarm(farmID uint64, update FarmUpdate) (err error)

UpdateFarm updates an existing farm's configuration

func (*RegistrarClient) UpdateNode

func (c *RegistrarClient) UpdateNode(updateOpts NodeUpdate) (err error)

UpdateNode update node configuration (farmID, interfaces, resources, location, secureBoot, virtualized).

type Resources

type Resources struct {
	HRU uint64 `json:"hru"`
	SRU uint64 `json:"sru"`
	CRU uint64 `json:"cru"`
	MRU uint64 `json:"mru"`
}

type UpdateAccountOpts

type UpdateAccountOpts func(*accountCfg)

func UpdateAccountWithRMBEncKey

func UpdateAccountWithRMBEncKey(rmbEncKey string) UpdateAccountOpts

UpdateAccountWithRMBEncKey update the account rmb encryption key

func UpdateAccountWithRelays

func UpdateAccountWithRelays(relays []string) UpdateAccountOpts

UpdateAccountWithRelays update the account relays

type UptimeReport

type UptimeReport struct {
	Uptime    uint64 `json:"uptime"`    // in seconds
	Timestamp int64  `json:"timestamp"` // in seconds since epoch
}

type ZosVersion

type ZosVersion struct {
	Version       string `json:"version"`
	SafeToUpgrade bool   `json:"safe_to_upgrade"`
}

Jump to

Keyboard shortcuts

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