Skip to content

jpbede/netpalmgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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