netpalmgo

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: MIT Imports: 9 Imported by: 0

README

netpalmgo

Codacy Badge PkgGoDev test codecov Go Report Card

Go package for netpalm API

netpalmgo support

I maintain a community on the networktocode slack channel

#netpalmgo on networktocode.slack.com

Examples

Queueing a get task
package main

import (
  "context"
  "go.bnck.me/netpalm"
  "go.bnck.me/netpalm/models"
)

func main() {
  nc := netpalmgo.New("https://netapi.mynet.net", "<apikey>")

  m := models.GetConfigRequest{
    Library: models.LibraryNetmiko,
    ConnectionArgs: models.ConnectionArgs{
      DeviceType: "cisco_ios",
      Host: "10.10.10.1",
      Username: "admin",
      Password: "abc123",
    },
    QueueStrategy: models.QueueStrategyFIFO,
    Command: []string{"show ip bgp sum"},
  }

  // send task
  d, err := nc.GetConfig().WithRequest(context.Background(), m)
  if err != nil {
    panic(err)
  }

  // wait blocking for task to finish
  d, err = nc.WaitForResult(context.Background(), d)
  if err != nil {
    panic(err)
  }
}
Queueing a set command
package main

import (
  "context"
  "go.bnck.me/netpalm"
  "go.bnck.me/netpalm/models"
)

func main() {
  nc := netpalmgo.New("https://netapi.mynet.net", "<apikey>")

  m := models.SetConfigRequest{
    Library: models.LibraryNetmiko,
    ConnectionArgs: models.ConnectionArgs{
      DeviceType: "cisco_ios",
      Host: "10.10.10.1",
      Username: "admin",
      Password: "abc123",
    },
    QueueStrategy: models.QueueStrategyFIFO,
    Config: []string{
      "set int tunnel tun0 remote-ip 192.168.2.1",
    },
  }

  // send set task
  d, err := nc.SetConfig().Set(context.Background(), false, m)
  if err != nil {
    panic(err)
  }

  // wait blocking for task to finish
  d, err = nc.WaitForResult(context.Background(), d)
  if err != nil {
    panic(err)
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the main client of netpalmgo

func New

func New(apiURL, apiKey string) *Client

New creates a new Client with APIUrl and APIKey

func NewWithClient

func NewWithClient(apiURL, apiKey string, httpClient *http.Client) *Client

NewWithClient creates a new Client with APIUrl and APIKey with a given http.Client

func (*Client) GetConfig

func (c *Client) GetConfig() getconfig.Client

GetConfig returns the client for the Endpoint /getconfig

func (*Client) SetConfig

func (c *Client) SetConfig() setconfig.Client

SetConfig returns the client for the Endpoint /setconfig

func (*Client) Task

func (c *Client) Task() task.Client

Task returns the client for the Endpoint /task

func (*Client) WaitForResult

func (c *Client) WaitForResult(ctx context.Context, response *models.Response) (*models.Response, error)

WaitForResult waits blocking for the result to finish (also fail).

Directories

Path Synopsis
apis
internal

Jump to

Keyboard shortcuts

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