cmlclient

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 20 Imported by: 0

README

Go Reference CodeQL Go Coverage Status Go Report Card

gocmlclient

A CML2 Client in Golang

(c) Ralph Schmieder 2022

Documentation

Index

Constants

View Source
const (
	IfaceStateDefined = "DEFINED_ON_CORE"
	IfaceStateStopped = "STOPPED"
	IfaceStateStarted = "STARTED"

	IfaceTypePhysical = "physical"
	IfaceTypeLoopback = "loopback"
)
View Source
const (
	LabStateDefined = "DEFINED_ON_CORE"
	LabStateStopped = "STOPPED"
	LabStateStarted = "STARTED"
	LabStateBooted  = "BOOTED"
)
View Source
const (
	LinkStateDefined = "DEFINED_ON_CORE"
	LinkStateStopped = "STOPPED"
	LinkStateStarted = "STARTED"
)
View Source
const (
	NodeStateDefined = "DEFINED_ON_CORE"
	NodeStateStopped = "STOPPED"
	NodeStateStarted = "STARTED"
	NodeStateBooted  = "BOOTED"
)

Variables

View Source
var (
	ErrSystemNotReady  = errors.New("system not ready")
	ErrElementNotFound = errors.New("element not found")
)

Functions

This section is empty.

Types

type Auth

type Auth struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Token    string `json:"token"`
	Admin    bool   `json:"admin"`
}

type Client

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

func NewClient

func NewClient(host string, insecure, useCache bool) *Client

NewClient returns a new CML client instance. The host must be a valid URL including scheme (https://).

func (*Client) GetImageDefs

func (c *Client) GetImageDefs(ctx context.Context) ([]ImageDefinition, error)

GetImageDefs returns a list of image definitions known to the controller.

func (*Client) GetNodeDefs

func (c *Client) GetNodeDefs(ctx context.Context) (NodeDefinitionMap, error)

GetNodeDefs returns the list of node definitions available on the CML controller. The key of the map is the definition type name (e.g. "alpine" or "ios"). The node def data structure is incomplete, only essential fields are populated.

func (*Client) HasLabConverged

func (c *Client) HasLabConverged(ctx context.Context, id string) (bool, error)

HasLabConverged checks if all nodes of the lab identified by the `id` (a UUIDv4) have converged e.g. are in state "BOOTED".

func (*Client) InterfaceCreate added in v0.0.2

func (c *Client) InterfaceCreate(ctx context.Context, labID, nodeID string, slot int) (*Interface, error)

InterfaceCreate creates an interface in the given lab and node. If the slot is >= 0, the request creates all unallocated slots up to and including that slot. Conversely, if the slot is < 0 (e.g. -1), the next free slot is used.

func (*Client) InterfaceGet added in v0.0.2

func (c *Client) InterfaceGet(ctx context.Context, iface *Interface) (*Interface, error)

InterfaceGet returns the interface identified by its `ID` (iface.ID).

func (*Client) LabCreate added in v0.0.2

func (c *Client) LabCreate(ctx context.Context, lab Lab) (*Lab, error)

LabCreate creates a new lab on the controller.

func (*Client) LabDestroy

func (c *Client) LabDestroy(ctx context.Context, id string) error

LabDestroy deletes the lab identified by the `id` (a UUIDv4).

func (*Client) LabGet

func (c *Client) LabGet(ctx context.Context, id string, deep bool) (*Lab, error)

LabGet returns the lab identified by `id` (a UUIDv4). If `deep` is provided, then the nodes, their interfaces and links are also fetched from the controller. Also, with `deep`, the L3 IP address info is fetched for the given lab.

func (*Client) LabGetByTitle added in v0.0.2

func (c *Client) LabGetByTitle(ctx context.Context, title string, deep bool) (*Lab, error)

LabGetByTitle returns the lab identified by its `title`. For the use of `deep` see LabGet().

func (*Client) LabImport

func (c *Client) LabImport(ctx context.Context, topo string) (*Lab, error)

LabImport imports a lab topology into the controller. This is expected to be in CML YAML topology file format.

func (*Client) LabStart

func (c *Client) LabStart(ctx context.Context, id string) error

LabStart starts all nodes of the lab identified by the `id` (a UUIDv4).

func (*Client) LabStop

func (c *Client) LabStop(ctx context.Context, id string) error

LabStop stops all nodes of the lab identified by the `id` (a UUIDv4).

func (*Client) LabUpdate added in v0.0.2

func (c *Client) LabUpdate(ctx context.Context, lab Lab) (*Lab, error)

LabUpdate updates specific fields of a lab (title, description and notes).

func (*Client) LabWipe

func (c *Client) LabWipe(ctx context.Context, id string) error

LabWipe wipes the lab identified by the `id` (a UUIDv4).

func (*Client) LinkCreate added in v0.0.2

func (c *Client) LinkCreate(ctx context.Context, link *Link) (*Link, error)

LinkCreate creates a link based on the the data passed in `link`. Required fields are the `LabID` and either a pair of interfaces `SrcID` / `DstID` or a pair of nodes `SrcNode` / `DstNode`. With nodes it's also possible to provide specific slots in `SrcSlot` / `DstSlot` where the link should be created. If one or both of the provided slots aren't available, then new interfaces will be craeted. If interface creation fails or the provided Interface IDs can't be found, the API returns an error, otherwise the returned Link variable has the updated link data. Node: -1 for a slot means: use next free slot. Specific slots run from 0 to the maximum slot number -1 per the node definition of the node type.

func (*Client) LinkGet added in v0.0.2

func (c *Client) LinkGet(ctx context.Context, labID, linkID string, deep bool) (*Link, error)

LinkGet returns the link data for the given `labID` and `linkID`. If `deep` is set to `true` then bot interface and node data for the given link are also fetched from the controller.

func (*Client) NodeCreate added in v0.0.2

func (c *Client) NodeCreate(ctx context.Context, node *Node) (*Node, error)

NodeCreate creates a new node on the controller based on the data provided in `node`. Label, node definition and image definition must be provided.

func (*Client) NodeDestroy added in v0.0.2

func (c *Client) NodeDestroy(ctx context.Context, node *Node) error

NodeDestroy deletes the node from the controller.

func (*Client) NodeGet added in v0.0.2

func (c *Client) NodeGet(ctx context.Context, node *Node, nocache bool) (*Node, error)

NodeGet returns the node identified by its `ID` and `LabID` in the provided node.

func (*Client) NodeSetConfig

func (c *Client) NodeSetConfig(ctx context.Context, node *Node, configuration string) error

NodeSetConfig sets a configuration for the specified node. At least the `ID` of the node and the `labID` must be provided in `node`. The `node` instance will be updated with the current values for the node as provided by the controller.

func (*Client) NodeStart

func (c *Client) NodeStart(ctx context.Context, node *Node) error

NodeStart starts the given node.

func (*Client) NodeStop

func (c *Client) NodeStop(ctx context.Context, node *Node) error

NodeStop stops the given node.

func (*Client) NodeUpdate added in v0.0.2

func (c *Client) NodeUpdate(ctx context.Context, node *Node) (*Node, error)

NodeUpdate updates the node specified by data in `node` (e.g. ID and LabID) with the other data provided. It returns the udpated node.

func (*Client) NodeWipe added in v0.0.2

func (c *Client) NodeWipe(ctx context.Context, node *Node) error

NodeWipe removes all runtime data from a node on the controller/compute. E.g. it will remove the actual VM and its associated disks.

func (*Client) SetCACert

func (c *Client) SetCACert(cert []byte) error

SetCACert sets a specific X.509 CA certificate to use with the client. If no cert is set, the system trust anchors are used for cert verification.

func (*Client) SetToken

func (c *Client) SetToken(token string)

SetToken sets a specific API token to be used. A token takes precedence over a username/password. However, if the token expires, the username/password are used to authorize the client again. An error is raised if no token and no username/password are provided or if the token expires when no username/password are set.

func (*Client) SetUsernamePassword

func (c *Client) SetUsernamePassword(username, password string)

SetUsernamePassword sets the username and the password to be used with the client for all authentications.

type Group added in v0.0.2

type Group struct {
	ID         string `json:"id"`
	Permission string `json:"permission"`
}

type IDlist

type IDlist []string

type ImageDefinition

type ImageDefinition struct {
	ID            string `json:"id"`
	SchemaVersion string `json:"schema_version"`
	NodeDefID     string `json:"node_definition_id"`
	Description   string `json:"description"`
	Label         string `json:"label"`
	DiskImage1    string `json:"disk_image"`
	DiskImage2    string `json:"disk_image_2"`
	DiskImage3    string `json:"disk_image_3"`
	ReadOnly      bool   `json:"read_only"`
	DiskSubfolder string `json:"disk_subfolder"`
	RAM           *int   `json:"ram"`
	CPUs          *int   `json:"cpus"`
	CPUlimit      *int   `json:"cpu_limit"`
	DataVolume    *int   `json:"data_volume"`
	BootDiskSize  *int   `json:"boot_disk_size"`
}

type Interface

type Interface struct {
	ID          string `json:"id"`
	LabID       string `json:"lab_id"`
	Node        string `json:"node"`
	Label       string `json:"label"`
	Slot        int    `json:"slot"`
	Type        string `json:"type"`
	DeviceName  string `json:"device_name"`
	SrcUDPport  int    `json:"src_udp_port"`
	DstUDPport  int    `json:"dst_udp_port"`
	MACaddress  string `json:"mac_address"`
	IsConnected bool   `json:"is_connected"`
	State       string `json:"state"`

	// extra
	IP4 []string `json:"ip4"`
	IP6 []string `json:"ip6"`
	// contains filtered or unexported fields
}

func (Interface) Exists

func (iface Interface) Exists() bool

func (Interface) IsPhysical added in v0.0.2

func (iface Interface) IsPhysical() bool

func (Interface) Runs

func (iface Interface) Runs() bool

type InterfaceList added in v0.0.2

type InterfaceList []*Interface

type Lab

type Lab struct {
	ID          string    `json:"id"`
	State       string    `json:"state"`
	Created     string    `json:"created"`
	Modified    string    `json:"modified"`
	Title       string    `json:"lab_title"`
	Description string    `json:"lab_description"`
	Notes       string    `json:"lab_notes"`
	Owner       *User     `json:"owner"`
	NodeCount   int       `json:"node_count"`
	LinkCount   int       `json:"link_count"`
	Nodes       NodeMap   `json:"nodes"`
	Links       linkList  `json:"links"`
	Groups      groupList `json:"groups"`
}

func (*Lab) Booted

func (l *Lab) Booted() bool

Booted returns `true` if all nodes in the lab are in booted state.

func (*Lab) CanBeWiped

func (l *Lab) CanBeWiped() bool

CanBeWiped returns `true` when all nodes in the lab are wiped.

func (*Lab) NodeByLabel

func (l *Lab) NodeByLabel(ctx context.Context, label string) (*Node, error)

NodeByLabel returns the node of a lab identified by its `label“ or an error if not found.

func (*Lab) Running

func (l *Lab) Running() bool

Running returns `true` if at least one node is running (started or booted).

type LabImport

type LabImport struct {
	ID       string   `json:"id"`
	Warnings []string `json:"warnings"`
}
type Link struct {
	ID      string `json:"id"`
	LabID   string `json:"lab_id"`
	State   string `json:"state"`
	Label   string `json:"label"`
	PCAPkey string `json:"link_capture_key"`
	SrcID   string `json:"interface_a"`
	DstID   string `json:"interface_b"`
	SrcNode string `json:"node_a"`
	DstNode string `json:"node_b"`
	SrcSlot int    `json:"slot_a"`
	DstSlot int    `json:"slot_b"`
	// contains filtered or unexported fields
}

Link defines the data structure for a CML link between nodes.

type Node

type Node struct {
	ID              string         `json:"id"`
	LabID           string         `json:"lab_id"`
	Label           string         `json:"label"`
	X               int            `json:"x"`
	Y               int            `json:"y"`
	NodeDefinition  string         `json:"node_definition"`
	ImageDefinition string         `json:"image_definition"`
	Configuration   string         `json:"configuration"`
	CPUs            int            `json:"cpus"`
	CPUlimit        int            `json:"cpu_limit"`
	RAM             int            `json:"ram"`
	State           string         `json:"state"`
	DataVolume      int            `json:"data_volume"`
	BootDiskSize    int            `json:"boot_disk_size"`
	Interfaces      InterfaceList  `json:"interfaces,omitempty"`
	Tags            []string       `json:"tags"`
	VNCkey          string         `json:"vnc_key"`
	SerialDevices   []SerialDevice `json:"serial_devices"`
	ComputeID       string         `json:"compute_id"`
	// contains filtered or unexported fields
}

type NodeDefinition

type NodeDefinition struct {
	ID            definitionID   `json:"id"`
	Configuration map[string]any `json:"configuration"`
	Device        deviceData     `json:"device"`
	Inherited     map[string]any `json:"inherited"`
	SchemaVersion string         `json:"schema_version"`
	Sim           simData        `json:"sim"`
	Boot          map[string]any `json:"boot"`
	PyATS         map[string]any `json:"pyats"`
	General       map[string]any `json:"general"`
	UI            map[string]any `json:"ui"`
}

type NodeDefinitionMap added in v0.0.5

type NodeDefinitionMap map[definitionID]NodeDefinition

type NodeMap

type NodeMap map[string]*Node

func (NodeMap) MarshalJSON

func (nmap NodeMap) MarshalJSON() ([]byte, error)

type SerialDevice added in v0.0.2

type SerialDevice struct {
	ConsoleKey   string `json:"console_key"`
	DeviceNumber int    `json:"device_number"`
}

type User

type User struct {
	ID          string `json:"id"`
	Created     string `json:"created"`
	Modified    string `json:"modified"`
	Username    string `json:"username"`
	Fullname    string `json:"fullname"`
	Email       string `json:"email"`
	Description string `json:"lab_description"`
	IsAdmin     bool   `json:"admin"`
	DirectoryDN string `json:"directory_dn"`
}

Directories

Path Synopsis
cmd
ctest command

Jump to

Keyboard shortcuts

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