vyos

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethodNotSupported = errors.New("method not supported")
	ErrContextNil         = errors.New("context must be non-nil")
	ErrInterfaceNil       = errors.New("can not unmarshal into nil interface")
	ErrEmptyPath          = errors.New("path cannot be empty")
)
View Source
var (
	ErrMustLoadFromFile = errors.New("file must not be empty or nil")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL   string // Base URL for API requests.
	UserAgent string // User agent used when communicating with the API.

	Token string // Token used for authentication.

	// Services used for talking to different parts of the VyOS API.
	Show       *ShowService
	Conf       *ConfigService
	Gen        *GenerateService
	Reset      *ResetService
	Power      *PowerService
	Image      *ImageService
	ConfigFile *ConfigService
	// contains filtered or unexported fields
}

Vyos represents a VyOS API client.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient creates a new VyOS API client. If no HTTP client is provided, a new one is created.

func (*Client) Client

func (c *Client) Client() *http.Client

Client returns a copy of the http.Client used by the VyOS API client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response.

func (*Client) Insecure

func (c *Client) Insecure() *Client

Insecure sets the InsecureSkipVerify field of the TLS configuration to true.

func (*Client) NewRequest

func (c *Client) NewRequest(urlStr string, request interface{}) (*http.Request, error)

NewRequest creates a new HTTP request for the VyOS API.

func (*Client) PowerOff

func (s *Client) PowerOff(ctx context.Context) (*PowerResponse, *Response, error)

PowerOff is a helper function to power off the VyOS instance from the client struct.

func (*Client) Reboot

func (s *Client) Reboot(ctx context.Context) (*PowerResponse, *Response, error)

Reboot is a helper function to reboot the VyOS instance from the client struct.

func (*Client) Save

func (c *Client) Save(ctx context.Context)

func (*Client) WithToken

func (c *Client) WithToken(token string) *Client

WithToken sets the token for the VyOS API client.

func (*Client) WithURL

func (c *Client) WithURL(url string) *Client

WithURL sets the base URL for the VyOS API client.

type ConfigRequest

type ConfigRequest struct {
	OPMode OPMode `json:"op,omitempty"`
	File   string `json:"file,omitempty"`
}

type ConfigResponse

type ConfigResponse struct {
	*RawResponse
}

ShowResponse represents a response from the VyOS API.

type ConfigService

type ConfigService service

Response represents a response from the VyOS API.

func (*ConfigService) Comment

func (s *ConfigService) Comment(ctx context.Context, path string) (*ConfigResponse, *Response, error)

func (*ConfigService) Delete

func (s *ConfigService) Delete(ctx context.Context, path string) (*ConfigResponse, *Response, error)

Delete deletes a configuration path in the VyOS API.

func (*ConfigService) Exists

func (s *ConfigService) Exists(ctx context.Context, path string) (*ConfigResponse, *Response, error)

Exists checks if a configuration path exists in the VyOS API. Handles: - op: exists, path: []string{}

func (*ConfigService) Get

func (s *ConfigService) Get(ctx context.Context, path string, options *RetrieveOptions) (*ConfigResponse, *Response, error)

Get retrives the configuration from the VyOS API. If path is empty, it will return the entire configuration. Handles: - op: showConfig, path: "" - op: showConfig, path: []string{} - op: returnValues, path: []string{} &ShowOptions{multivalue: true}

func (*ConfigService) Load

func (s *ConfigService) Load(ctx context.Context, file string) (*ConfigResponse, *Response, error)

Add adds a new image from a url

func (*ConfigService) Save

func (s *ConfigService) Save(ctx context.Context, file string) (*ConfigResponse, *Response, error)

Add adds a new image from a url

func (*ConfigService) Set

func (s *ConfigService) Set(ctx context.Context, path ...string) (*ConfigResponse, *Response, error)

Set sets a configuration path in the VyOS API. NOTE: This does not send multiple requests to the API. It sends a single request with multiple paths.

type GenerateResponse

type GenerateResponse struct {
	*RawResponse
}

type GenerateService

type GenerateService service

func (*GenerateService) Do

Do sends a request to the VyOS API and returns the response.

type ImageAddRequest

type ImageAddRequest struct {
	OPMode OPMode `json:"op,omitempty"`
	URL    string `json:"url,omitempty"`
}

type ImageDeleteRequest

type ImageDeleteRequest struct {
	OPMode OPMode `json:"op,omitempty"`
	Name   string `json:"name,omitempty"`
}

type ImageResponse

type ImageResponse struct {
	*RawResponse
}

ShowResponse represents a response from the VyOS API.

type ImageService

type ImageService service

Response represents a response from the VyOS API.

func (*ImageService) Add

Add adds a new image from a url

func (*ImageService) Delete

func (s *ImageService) Delete(ctx context.Context, name string) (*ImageResponse, *Response, error)

Delete deletes an existing image

type OPMode

type OPMode string // OPMode is a type for the different operational modes of the VyOS API.
const (

	// OPMode constants
	OPModeShow      OPMode = "show"      // OPModeShow is the show operational mode.
	OPModeSet       OPMode = "set"       // OPModeSet is the set operational mode.
	OPModeComment   OPMode = "comment"   // OPModeComment is the comment operational mode.
	OPModeGenerate  OPMode = "generate"  // OPModeGenerate is the generate operational mode.
	OPModeConfigure OPMode = "configure" // OPModeConfigure is the configure operational mode.
)

type Path

type Path []string // Path is a type for the different paths of the VyOS API.

type PowerResponse

type PowerResponse struct {
	*RawResponse
}

ShowResponse represents a response from the VyOS API.

type PowerService

type PowerService service

Response represents a response from the VyOS API.

func (*PowerService) PowerOff

func (s *PowerService) PowerOff(ctx context.Context) (*PowerResponse, *Response, error)

PowerOff sends a request to the VyOS API to power off the system.

func (*PowerService) Reboot

func (s *PowerService) Reboot(ctx context.Context) (*PowerResponse, *Response, error)

Reboot sends a request to the VyOS API to reboot the system.

type RawResponse

type RawResponse struct {
	Success bool        `json:"success,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

RawResponse represents a raw response from the VyOS API.

type Request

type Request struct {
	OPMode OPMode `json:"op,omitempty"`
	Path   Path   `json:"path,omitempty"`
}

Request represents a request to the VyOS API.

type ResetResponse

type ResetResponse struct {
	*RawResponse
}

type ResetService

type ResetService service

func (*ResetService) Do

Do sends a request to the VyOS API and returns the response.

type Response

type Response struct {
	*http.Response
}

Request represents a request to the VyOS API.

type RetrieveOptions

type RetrieveOptions struct {
	MultiValue bool
}

type ShowResponse

type ShowResponse struct {
	*RawResponse
}

ShowResponse represents a response from the VyOS API.

type ShowService

type ShowService service

Response represents a response from the VyOS API.

func (*ShowService) Do

func (s *ShowService) Do(ctx context.Context, path string) (*ShowResponse, *Response, error)

Do sends a request to the VyOS API and returns the response.

Jump to

Keyboard shortcuts

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