cmlclient

package module
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 21 Imported by: 0

README

Go Reference CodeQL Go Coverage Status Go Report Card

gocmlclient

A CML2 Client in Golang

(c) Ralph Schmieder 2022, 2023

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 New added in v0.0.14

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

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

func (*Client) ExtConnGet added in v0.0.22

func (c *Client) ExtConnGet(ctx context.Context, extConnID string) (*ExtConn, error)

ExtConnGet returns the external connector specified by the ID given

func (*Client) ExtConnectors added in v0.0.22

func (c *Client) ExtConnectors(ctx context.Context) ([]*ExtConn, error)

ExtConnectors returns all external connectors on the system

func (*Client) GroupByName added in v0.0.16

func (c *Client) GroupByName(ctx context.Context, name string) (*Group, error)

GroupByName tries to get the group with the provided `name`.

func (*Client) GroupCreate added in v0.0.16

func (c *Client) GroupCreate(ctx context.Context, group *Group) (*Group, error)

GroupCreate creates a new group on the controller based on the data provided in the passed group parameter.

func (*Client) GroupDestroy added in v0.0.16

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

GroupDestroy deletes the group identified by the `id` (a UUIDv4).

func (*Client) GroupGet added in v0.0.16

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

GroupGet retrieves the group with the provided `id` (a UUIDv4).

func (*Client) GroupUpdate added in v0.0.16

func (c *Client) GroupUpdate(ctx context.Context, group *Group) (*Group, error)

GroupUpdate updates the given group which must exist.

func (*Client) Groups added in v0.0.16

func (c *Client) Groups(ctx context.Context) (GroupList, error)

Groups retrieves the list of all groups which exist on the controller.

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) ImageDefinitions added in v0.0.16

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

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

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) NodeDefinitions added in v0.0.16

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

NodeDefinitions 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) 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) Ready added in v0.0.16

func (c *Client) Ready(ctx context.Context) error

Ready returns nil if the system is compatible and ready

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.

func (*Client) UserByName added in v0.0.16

func (c *Client) UserByName(ctx context.Context, name string) (*User, error)

UserByName returns the user with the given username `name`.

func (*Client) UserCreate added in v0.0.16

func (c *Client) UserCreate(ctx context.Context, user *User) (*User, error)

UserCreate creates a new user on the controller based on the data provided in the passed user parameter.

func (*Client) UserDestroy added in v0.0.16

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

UserDestroy deletes the user identified by the `id` (a UUIDv4).

func (*Client) UserGet added in v0.0.16

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

UserGet returns the user with the given `id`.

func (*Client) UserGroups added in v0.0.16

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

UserGroups retrieves the list of all groups the user belongs to.

func (*Client) UserUpdate added in v0.0.16

func (c *Client) UserUpdate(ctx context.Context, user *User) (*User, error)

UserUpdate updates the given user which must exist.

func (*Client) Users added in v0.0.16

func (c *Client) Users(ctx context.Context) (UserList, error)

Users retrieves the list of all users which exist on the controller.

func (*Client) Version added in v0.0.14

func (c *Client) Version() string

Version returns the CML controller version

type ExtConn added in v0.0.22

type ExtConn struct {
	ID          string   `json:"id"`
	DeviceName  string   `json:"device_name"`
	Label       string   `json:"label"`
	Protected   bool     `json:"protected"`
	Snooped     bool     `json:"snooped"`
	Tags        []string `json:"tags"`
	Operational opdata   `json:"operational"`
}

ExtConn defines the data structure for a CML external connector

type Group added in v0.0.2

type Group struct {
	ID          string     `json:"id,omitempty"`
	Description string     `json:"description"`
	Members     []string   `json:"members"`
	Name        string     `json:"name"`
	Labs        []GroupLab `json:"labs"`
}

type GroupLab added in v0.0.16

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

type GroupList added in v0.0.16

type GroupList []*Group

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      LabGroupList `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 LabGroup added in v0.0.16

type LabGroup struct {
	ID         string `json:"id"`
	Name       string `json:"name,omitempty"`
	Permission string `json:"permission"`
}

type LabGroupList added in v0.0.16

type LabGroupList []*LabGroup

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"`
	HideLinks       bool           `json:"hide_links"`
	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,omitempty"`
	Created      string   `json:"created,omitempty"`
	Modified     string   `json:"modified,omitempty"`
	Username     string   `json:"username"`
	Password     string   `json:"password"`
	Fullname     string   `json:"fullname"`
	Email        string   `json:"email"`
	Description  string   `json:"description"`
	IsAdmin      bool     `json:"admin"`
	DirectoryDN  string   `json:"directory_dn,omitempty"`
	Groups       []string `json:"groups,omitempty"`
	Labs         []string `json:"labs,omitempty"`
	OptIn        bool     `json:"opt_in"`                  // with 2.5.0
	ResourcePool *string  `json:"resource_pool,omitempty"` // with 2.5.0
}

type UserList added in v0.0.16

type UserList []*User

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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