evengclient

package module
v0.0.0-...-860ec97 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: BSD-2-Clause Imports: 9 Imported by: 0

README

eve-ng-restapi-go-client

Go Report Card GitHub license GitHub code style GoDoc doc

Description

Golang package - client library for the Eve-NG REST API.

This client is an open-source library for communicating with Eve-NG Server applications that are written in php.

Code Style

This project was written according to the uber-go coding style.

Features

Full Eve-NG Support

This client allows you to create:

  • Folders

  • Labs

  • Nodes

  • Networks

  • Users

and also enables you to:

  • Move folders and labs

  • Edit existing labs, nodes, networks and users

  • Connect nodes to networks

  • Start / stop nodes (single or bulk operations)

  • Wipe / export node starting configurations

  • Check the system status

Requirements

Requires a running instance of Eve-NG.

Further information about Eve-NG can be found here

To check if your setup works, follow the steps provided in the 'Tests' section of this document.

Installation

go get github.com/inexio/eve-ng-restapi-go-client

or

git clone https://github.com/inexio/eve-ng-restapi-go-client.git

Setup

After installing the library you have to either declare a path to your config file or set certain environment variables for the client to work.

These can be set as follows:

Config File

In the client.go file, in the init() function you can see the following lines of code:

viper.AddConfigPath("config/")
viper.SetConfigType("yaml")
viper.SetConfigName("eve-ng-api")

ConfigPath is relativ to the package location. ConfigType and name can also be changed to match your desired type of config.

Environment Variables

Also in the client.go file, in the init() function you will find:

//Set env var prefix to only match certain vars
viper.SetEnvPrefix("eve_ng_api")

SetEnvPrefix can be changed to whatever prefix you prefer to have in your environment vars.

The needed environment vars can then be added as follows:

export EVE_NG_API_BASEURL="<your_base_url>"
export EVE_NG_API_USERNAME="<your_username>"
export EVE_NG_API_PASSWORD="<your_password>"

Usage

The following section will show you how to create a lab and do various operations in it.

baseUrl := "https://<your eve-ng server>"
username := <username>
password := <password>
eveNgClient, err := NewEveNgClient(baseUrl)
_ := eveNgClient.SetUsernameAndPassword(username, password)

_ = eveNgClient.Login()
defer func() {
  _ = eveNgClient.Logout()
}()

_ = eveNgClient.AddFolder("/", "TestFolder")

labFolder := "/TestFolder" //path to the desired folder
labName := "TestLaboratory" //name of the laboratory

_ = eveNgClient.AddLab(labFolder, labName, "1", "admin", "A test laboratory", "Test laboratory for unit and integration tests")

networkID, _ = eveNgClient.AddNetwork("/TestFolder/TestLaboratory.unl", "nat0", "TestNetwork", "69", "420", 1, 0)

nodeID, _ := eveNgClient.AddNode("/TestFolder/TestLaboratory.unl", "qemu", "veos", "0", 0, "AristaSW.png", "veos-4.16.14M", "vEOS", "420", "69", "512", "telnet", 1, "undefined", 4, "", "", "", "", 1)

_ = eveNgClient.ConnectNodeInterfaceToNetwork("/TestFolder/TestLaboratory.unl", nodeID, 1, networkID)

_ = eveNgClient.StartNode("/TestFolder/TestLaboratory.unl", nodeID)

labTopology, _ := eveNgClient.GetTopology("/TestFolder/TestLaboratory.unl")

_ = eveNgClient.StartNodes("/TestFolder/TestLaboratory.unl")

After running the code above, the lab you just created should look like this when viewed from the web-interface

Tests

The library comes with a few unit and integrations tests. To use these tests you have to either use a config file giving the client the correct base-url, username and password or set certain environment variables.

In order to run these test, run the follwing command inside root directory of this repository:

go test

If you want to check if your setup works, run:

go test -run TestEveNgClient_Nodes

Getting Help

If there are any problems or something does not work as intended, open an issue on GitHub.

Contribution

Contributions to the project are welcome.

We are looking forward to your bug reports, suggestions and fixes.

If you want to make any contributions make sure your go report does match up with our projects score of A+.

When you contribute make sure your code is conform to the uber-go coding style.

Happy Coding!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicResponse

type BasicResponse struct {
	Code    interface{} `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
	Status  string      `json:"status"`
}

BasicResponse contains the data returned by the api in case of a get

type CPU

type CPU struct {
	IntValTemplateOption
}

CPU contains information about the templates cpu option

type Config

type Config struct {
	List StringArray `json:"list"`
	StringValTemplateOption
}

Config contains information about a template config

type Console

type Console struct {
	List List `json:"list"`
	StringValTemplateOption
}

Console contains information about the templates qonsole option

type Cpulimit

type Cpulimit struct {
	IntValTemplateOption
}

Cpulimit contains information about the templates Cpulimit option

type CreateResponse

type CreateResponse struct {
	ID int `json:"id"`
}

CreateResponse contains the data returned by the api in case of a create

type Delay

type Delay struct {
	IntValTemplateOption
}

Delay contains information about the templates delay option

type Endpoints

type Endpoints struct {
	Ethernet EthernetEndpoints `json:"ethernet"`
	Serial   SerialEndpoints   `json:"serial"`
}

Endpoints contains information about ethernet and serial endpoints

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Status  int    `json:"status"`
}

ErrorResponse - Contains error information.

type Ethernet

type Ethernet struct {
	IntValTemplateOption
}

Ethernet contains information about the templates ethernet option

type EthernetEndpoints

type EthernetEndpoints map[string]string

EthernetEndpoints contains information about EthernetEndpoints

type EthernetInterfaces

type EthernetInterfaces []Interface

EthernetInterfaces an array of EthernetInterfaces

type EveNgClient

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

EveNgClient is an implementation of the client specified for eve-ng

func NewEveNgClient

func NewEveNgClient(baseURL string) (*EveNgClient, error)

NewEveNgClient generates a new eve-ng api-client object which can be used to communicate with the eve-ng REST API

func (*EveNgClient) AddFolder

func (c *EveNgClient) AddFolder(path string, folderName string) error

AddFolder adds a new folder to the given directory

func (*EveNgClient) AddLab

func (c *EveNgClient) AddLab(path string, name string, version string, author string, description string, body string) error

AddLab adds a lab to

func (*EveNgClient) AddNetwork

func (c *EveNgClient) AddNetwork(labPath string, networkType string, networkName string, left int, top int, visibility int, postfix int) (int, error)

AddNetwork add a new network to a lab

func (*EveNgClient) AddNode

func (c *EveNgClient) AddNode(labPath string, nodeType string, template string, config string, delay int, icon string, image string, name string, left int, top int, ram int, console string, cpu int, cpuLimit string, ethernet int, firstMac string, rdpUser string, rdpPassword string, uuid string, count int) (int, error)

AddNode add a new node to a lab

func (*EveNgClient) AddUser

func (c *EveNgClient) AddUser(username string, name string, email string, password string, role string, expiration string, dateStart string, extAuth string, pod int, pexpiration string, cpu int, ram int) error

AddUser adds a new user

func (*EveNgClient) ConnectNodeInterfaceToNetwork

func (c *EveNgClient) ConnectNodeInterfaceToNetwork(labPath string, nodeID int, interfaceID int, networkID int) error

ConnectNodeInterfaceToNetwork connects the given node interface to a network

func (*EveNgClient) DisconnectNodeInterfaceFromNetwork

func (c *EveNgClient) DisconnectNodeInterfaceFromNetwork(labPath string, nodeID int, interfaceID int) error

DisconnectNodeInterfaceFromNetwork disconnects the given node interface to a network

func (*EveNgClient) EditLab

func (c *EveNgClient) EditLab(labPath string, name string, version string, author string, description string) error

EditLab edit an existing lab

func (*EveNgClient) EditUser

func (c *EveNgClient) EditUser(username string, name string, email string, password string, role string, expiration string, pod int, pexpiration string) error

EditUser edits an existing user

func (*EveNgClient) ExportNode

func (c *EveNgClient) ExportNode(labPath string, nodeID int) error

ExportNode exports a specific node in a lab

func (*EveNgClient) ExportNodes

func (c *EveNgClient) ExportNodes(labPath string) error

ExportNodes exports all nodes in a lab

func (*EveNgClient) GetFolders

func (c *EveNgClient) GetFolders(path string) (Folders, error)

GetFolders returns all folders in a given path

func (*EveNgClient) GetLab

func (c *EveNgClient) GetLab(labPath string) (Lab, error)

GetLab retrieves data for the given lab

func (*EveNgClient) GetLabFiles

func (c *EveNgClient) GetLabFiles(path string) (LabFiles, error)

GetLabFiles returns all lab files in a given path

func (*EveNgClient) GetNetwork

func (c *EveNgClient) GetNetwork(labPath string, networkID int) (Network, error)

GetNetwork returns data for given network id for lab

func (*EveNgClient) GetNetworkTypes

func (c *EveNgClient) GetNetworkTypes() (NetworkTypes, error)

GetNetworkTypes returns all available network types

func (*EveNgClient) GetNetworks

func (c *EveNgClient) GetNetworks(labPath string) (Networks, error)

GetNetworks returns a list of all networks configured in a lab

func (*EveNgClient) GetNode

func (c *EveNgClient) GetNode(labPath string, nodeID int) (Node, error)

GetNode - Returns data for a specific lab node

func (*EveNgClient) GetNodeInterfaces

func (c *EveNgClient) GetNodeInterfaces(labPath string, nodeID int) (Interfaces, error)

GetNodeInterfaces returns all interfaces for a specific lab node

func (*EveNgClient) GetNodeTemplate

func (c *EveNgClient) GetNodeTemplate(templateName string) (Template, error)

GetNodeTemplate returns data of a specific template

func (*EveNgClient) GetNodeTemplates

func (c *EveNgClient) GetNodeTemplates() (Templates, error)

GetNodeTemplates returns all node templates

func (*EveNgClient) GetNodes

func (c *EveNgClient) GetNodes(labPath string) (Nodes, error)

GetNodes returns all nodes in a lab

func (*EveNgClient) GetSystemStatus

func (c *EveNgClient) GetSystemStatus() (SystemStatus, error)

GetSystemStatus returns the system status of eve-ng

func (*EveNgClient) GetTopology

func (c *EveNgClient) GetTopology(labPath string) (TopologyPoints, error)

GetTopology retrieves topology for given lab

func (*EveNgClient) GetUser

func (c *EveNgClient) GetUser(username string) (User, error)

GetUser retreives data for given user

func (*EveNgClient) GetUserRoles

func (c *EveNgClient) GetUserRoles() (UserRoles, error)

GetUserRoles returns all available user roles

func (*EveNgClient) GetUsers

func (c *EveNgClient) GetUsers() (Users, error)

GetUsers retreives a list of all users

func (*EveNgClient) Login

func (c *EveNgClient) Login() error

Login performs a login via an eve-ng api-client

func (*EveNgClient) Logout

func (c *EveNgClient) Logout() error

Logout performs a logout via an eve-ng api-client

func (*EveNgClient) MoveFolder

func (c *EveNgClient) MoveFolder(oldPath string, newPath string) error

MoveFolder moves/renames an existing folder

func (*EveNgClient) MoveLab

func (c *EveNgClient) MoveLab(labPath string, newPath string) error

MoveLab moves a lab to an existing folder

func (*EveNgClient) RemoveFolder

func (c *EveNgClient) RemoveFolder(path string) error

RemoveFolder deletes an existing folder

func (*EveNgClient) RemoveLab

func (c *EveNgClient) RemoveLab(labPath string) error

RemoveLab remove an existing lab

func (*EveNgClient) RemoveNetwork

func (c *EveNgClient) RemoveNetwork(labPath string, networkID int) error

RemoveNetwork removes a given network

func (*EveNgClient) RemoveNode

func (c *EveNgClient) RemoveNode(labPath string, nodeID int) error

RemoveNode removes a node from a lab

func (*EveNgClient) RemoveUser

func (c *EveNgClient) RemoveUser(username string) error

RemoveUser removes an existing user

func (*EveNgClient) SetNodeStartupConfig

func (c *EveNgClient) SetNodeStartupConfig(labPath string, nodeID int, startupConfigFilePath string) error

SetNodeStartupConfig sets a startup config for a given node. The startup config is passed as a path to a local startup config file.

func (*EveNgClient) SetNodeStartupConfigString

func (c *EveNgClient) SetNodeStartupConfigString(labPath string, nodeID int, startupConfigString string) error

SetNodeStartupConfigString sets a startup config for a given node. The startup config is passed as a string.

func (*EveNgClient) SetUsernameAndPassword

func (c *EveNgClient) SetUsernameAndPassword(username, password string) error

SetUsernameAndPassword - Is used to set a username and password for https auth

func (*EveNgClient) StartNode

func (c *EveNgClient) StartNode(labPath string, nodeID int) error

StartNode starts a specific node in a lab

func (*EveNgClient) StartNodes

func (c *EveNgClient) StartNodes(labPath string) error

StartNodes starts all nodes in a lab

func (*EveNgClient) StopNode

func (c *EveNgClient) StopNode(labPath string, nodeID int) error

StopNode stops a specific node in a lab

func (*EveNgClient) StopNodes

func (c *EveNgClient) StopNodes(labPath string) error

StopNodes stops all nodes in a lab

func (*EveNgClient) WipeNode

func (c *EveNgClient) WipeNode(labPath string, nodeID int) error

WipeNode wipes a specific node in a lab

func (*EveNgClient) WipeNodes

func (c *EveNgClient) WipeNodes(labPath string) error

WipeNodes wipes all nodes in a lab

type Firstmac

type Firstmac struct {
	StringValTemplateOption
}

Firstmac contains information about the templates firstmac option

type Folder

type Folder struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

Folder contains information regarding a folder

type FolderContents

type FolderContents struct {
	Folders  Folders  `json:"folders"`
	LabFiles LabFiles `json:"labs"`
}

FolderContents is a list of folders and labs inside a folder

type Folders

type Folders []Folder

Folders is a list of folders

type HTTPError

type HTTPError struct {
	StatusCode int
	Status     string
	Body       *ErrorResponse
}

HTTPError - Represents an http error returned by the api.

func (HTTPError) Error

func (h HTTPError) Error() string

type Icon

type Icon struct {
	List List `json:"list"`
	StringValTemplateOption
}

Icon contains information about the templates icon option

type Image

type Image struct {
	List interface{} `json:"list"`
	StringValTemplateOption
}

Image contains information about the templates image option

type IntValTemplateOption

type IntValTemplateOption struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	Value int    `json:"value"`
}

IntValTemplateOption contains the standard fields of a templateOption

type Interface

type Interface struct {
	Name      string `json:"name"`
	NetworkID *int   `json:"network_id"`
}

Interface basic interface structure

type Interfaces

type Interfaces struct {
	Ethernet EthernetInterfaces `json:"ethernet"`
	Serial   SerialInterfaces   `json:"serial"`
}

Interfaces contains information about ethernet and serial interfaces

type Lab

type Lab struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Version     string `json:"version"`
	Author      string `json:"author"`
	Body        string `json:"body"`
	Description string `json:"description"`
	Filename    string `json:"filename"`
}

Lab contains information about a lab

type LabFile

type LabFile struct {
	File string `json:"file"`
	Path string `json:"path"`
}

LabFile contains information regarding a lab file

type LabFiles

type LabFiles []LabFile

LabFiles is a list of labfiles

type List

type List map[string]string

List resembles the field List of most stucts returned by the api

type Name

type Name struct {
	StringValTemplateOption
}

Name contains information about the templates name option

type Network

type Network struct {
	Count      int    `json:"count"`
	Name       string `json:"name"`
	Type       string `json:"type"`
	Top        int    `json:"top"`
	Left       int    `json:"left"`
	Style      string `json:"style"`
	Linkstyle  string `json:"linkstyle"`
	Color      string `json:"color"`
	Label      string `json:"label"`
	Visibility int    `json:"visibility"`
}

Network contains information about a network

type NetworkTypes

type NetworkTypes map[string]string

NetworkTypes is an array of network types

type NetworkWithID

type NetworkWithID struct {
	ID int `json:"id"`
	Network
}

NetworkWithID contains information about a network including its id

type Networks

type Networks map[string]NetworkWithID

Networks an array of Networks

type Node

type Node struct {
	UUID       string      `json:"uuid"`
	Name       string      `json:"name"`
	Type       string      `json:"type"`
	Status     int         `json:"status"`
	Template   string      `json:"template"`
	CPU        int         `json:"cpu"`
	RAM        int         `json:"ram"`
	Image      string      `json:"image"`
	Console    string      `json:"console"`
	Ethernet   int         `json:"ethernet"`
	Delay      int         `json:"delay"`
	Icon       string      `json:"icon"`
	URL        string      `json:"url"`
	Top        int         `json:"top"`
	Left       int         `json:"left"`
	Config     string      `json:"config"`
	Firstmac   string      `json:"firstmac"`
	Configlist interface{} `json:"configlist"`
}

Node contains information about a node

type NodeWithID

type NodeWithID struct {
	ID int `json:"id"`
	Node
}

NodeWithID contains information about a node including its id

type Nodes

type Nodes map[string]NodeWithID

Nodes an array of Nodes

type NotValidError

type NotValidError struct{}

NotValidError - Is returned when the client was not initialized properly

func (*NotValidError) Error

func (m *NotValidError) Error() string

type Nvram

type Nvram struct {
	IntValTemplateOption
}

Nvram contains information about the templates nvram option

type Options

type Options struct {
	Config      Config      `json:"config"`
	Delay       Delay       `json:"delay"`
	Ethernet    Ethernet    `json:"ethernet"`
	Icon        Icon        `json:"icon"`
	Image       Image       `json:"image"`
	Name        Name        `json:"name"`
	Nvram       Nvram       `json:"nvram"`
	RAM         RAM         `json:"ram"`
	Serial      Serial      `json:"serial"`
	UUID        UUID        `json:"uuid"`
	Cpulimit    Cpulimit    `json:"cpulimit"`
	CPU         CPU         `json:"cpu"`
	Firstmac    Firstmac    `json:"firstmac"`
	Qemuversion Qemuversion `json:"qemuversion"`
	Qemuarch    Qemuarch    `json:"qemuarch"`
	Qemunic     Qemunic     `json:"qemunic"`
	Qemuoptions Qemuoptions `json:"qemuoptions"`
	Console     Console     `json:"console"`
	Rdpuser     Rdpuser     `json:"rdpuser"`
	Rdppassword Rdppassword `json:"rdppassword"`
}

Options contains information about the templates options

type Picture

type Picture struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	Type   string `json:"type"`
	Map    string `json:"map"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

Picture contains information about a specific picture

type Pictures

type Pictures []Picture

Pictures an array containing pictures

type Qemu

type Qemu struct {
	Arch    string `json:"arch"`
	Nic     string `json:"nic"`
	Options string `json:"options"`
}

Qemu contains information about the templates qemu option

type Qemuarch

type Qemuarch struct {
	List List `json:"list"`
	StringValTemplateOption
}

Qemuarch contains information about the templates qemuarch option

type Qemunic

type Qemunic struct {
	List List `json:"list"`
	StringValTemplateOption
}

Qemunic contains information about the templates qemunic option

type Qemuoptions

type Qemuoptions struct {
	StringValTemplateOption
}

Qemuoptions contains information about the templates qemuoptions option

type Qemuversion

type Qemuversion struct {
	List List `json:"list"`
	StringValTemplateOption
}

Qemuversion contains information about the templates qemuversion option

type RAM

type RAM struct {
	IntValTemplateOption
}

RAM contains information about the templates ram option

type Rdppassword

type Rdppassword struct {
	StringValTemplateOption
}

Rdppassword contains information about the templates rdppassword option

type Rdpuser

type Rdpuser struct {
	StringValTemplateOption
}

Rdpuser contains information about the templates rdpuser option

type Serial

type Serial struct {
	IntValTemplateOption
}

Serial contains information about the templates Serial option

type SerialEndpoints

type SerialEndpoints map[string]string

SerialEndpoints contains information about SerialEndpoints

type SerialInterfaces

type SerialInterfaces []Interface

SerialInterfaces an array of SerialInterfaces

type StringArray

type StringArray []string

StringArray resembles the field List of some stucts returned by the api because they are different than the List struct

type StringValTemplateOption

type StringValTemplateOption struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	Value string `json:"value"`
}

StringValTemplateOption contains the standard fields of a templateOption

type SystemStatus

type SystemStatus struct {
	Cached      int    `json:"cached"`
	CPU         int    `json:"cpu"`
	Disk        int    `json:"disk"`
	Dynamips    int    `json:"dynamips"`
	Iol         int    `json:"iol"`
	Mem         int    `json:"mem"`
	Qemu        int    `json:"qemu"`
	Qemuversion string `json:"qemu_version"`
	Swap        int    `json:"swap"`
	Version     string `json:"version"`
}

SystemStatus contains information regarding the system status

type Template

type Template struct {
	Description string  `json:"description"`
	Options     Options `json:"options"`
	Type        string  `json:"type"`
	Qemu        Qemu    `json:"qemu"`
}

Template contains information about a specific template

type Templates

type Templates map[string]string

Templates contains information about all templates

type Topology

type Topology struct {
	Destination            string `json:"destination"`
	DestinationLabel       string `json:"destination_label"`
	DestinationType        string `json:"destination_type"`
	DestinationInterfaceID string `json:"destinationinterfaceid"`
	DestinationNodename    string `json:"destinationnodename"`
	DestinationSuspend     int    `json:"destinationsuspend"`
	DestinationDelay       int    `json:"destinationdelay"`
	DestinationLoss        int    `json:"destinationloss"`
	DestinationBandwidth   int    `json:"destinationbandwidth"`
	DestinationJitter      int    `json:"destinationjitter"`
	Source                 string `json:"source"`
	SourceLabel            string `json:"source_label"`
	SourceType             string `json:"source_type"`
	SourceNodename         string `json:"sourcenodename"`
	SourceInterfaceID      int    `json:"sourceinterface"`
	SourceSuspend          int    `json:"sourcesuspend"`
	SourceDelay            int    `json:"sourcedelay"`
	SourceLoss             int    `json:"sourceloss"`
	SourceBandwidth        int    `json:"sourcebandwidth"`
	SourceJitter           int    `json:"sourcejitter"`
	Type                   string `json:"type"`
	NetworkID              int    `json:"networkid"`
	Style                  string `json:"style"`
	Linkstyle              string `json:"linkstyle"`
	Label                  string `json:"label"`
	Color                  string `json:"color"`
}

Topology contains information about a network topology point

type TopologyPoints

type TopologyPoints []Topology

TopologyPoints an array of network topology points

type UUID

type UUID struct {
	StringValTemplateOption
}

UUID contains information about the templates UUID option

type User

type User struct {
	Username    string  `json:"username"`
	Email       string  `json:"email"`
	ExtAuth     string  `json:"ext_auth"`
	RAM         string  `json:"ram"`
	CPU         string  `json:"cpu"`
	Expiration  string  `json:"expiration"`
	Name        string  `json:"name"`
	Session     string  `json:"session"`
	Role        string  `json:"role"`
	Online      int     `json:"online"`
	IP          string  `json:"ip"`
	Folder      string  `json:"folder"`
	Lab         string  `json:"lab"`
	Pod         string  `json:"pod"`
	Pexpiration string  `json:"pexpiration"`
	DateStart   string  `json:"datestart"`
	DiskUsage   float64 `json:"diskusage"`
}

User contains information about a specific user

type UserRoles

type UserRoles map[string]string

UserRoles - contains information about user roles

type Users

type Users map[string]User

Users a list of all users in a lab

Jump to

Keyboard shortcuts

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