Skip to content

Latest commit

 

History

History
98 lines (79 loc) · 2.4 KB

README.md

File metadata and controls

98 lines (79 loc) · 2.4 KB

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)
  }
}