ciscoutils

package module
v0.0.0-...-8d0ba72 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: MIT Imports: 7 Imported by: 0

README

ciscoutils

Various code fragments to make the life easier as a Cisco stack developer in Go. The idea is here to collect small snippets of Cisco related code that is used to work with Cisco devices in many ways.

There are no external dependencies in this code. Only Go builtin libraries. Please note that some of the subpackages may have other external dependencies.

To use this library just download it like this:

go get github.com/helgeolav/ciscoutils

And then add it into your program

package main

import (
 "github.com/helgeolav/ciscoutils"
 "fmt"
)

func main() {
  vlans := ciscoutils.ReadVlanCsv("vlan_test.csv", ';')
  fmt.Println(vlans)
}

Functions

The list below are the functions that are provided for you. There are some others, they are mostly used for testing and development.

func GetRangeFromString(input string) (low, high int, err error)

The inputstring is a numbered list "from-to", and in return you get either an error or the two numbers in the list.

low, high := GetRangefromString("3-10")

Will give you low = 3 and high = 10.

func GetVLANString(input string) (vlans []int, err error)

input a list of vlans in Cisco format and in return you get either a panic, an error or the list of vlan numbers in an array.

vlans, _ := GetVLANString("1,10-12,15,20-40,43")

Do not add white spaces into the input string.

func FindVlan(ID int, AllVlans []Vlan) *Vlan

When you have an array of Vlan (see below) you can then search through them to find a VLAN.

vlans := MakeTestVlans()
vlan := FindVlan(1, vlans)

If the given VLAN ID does not exist in the array, nil is returned.

func ReadVlanCsv(inputFile string, separator rune) (vlans []Vlan, err error)

Reads an input file and returns either an error or an array of []Vlan that you can work on.

vlans, _ := ReadVlanCsv("vlan_test.csv", ';')

Types that are exposed

The Vlan struct is used when you need to work with vlans.

	ID     int
	Name   string
	Tenant string
	VRF    string
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAppName

func GetAppName(vlan *Vlan, defaultname string) string

GetAppName Return the name of the application

func GetEPGName

func GetEPGName(vlan *Vlan) string

GetEPGName Return the name of the EPG

func GetRangeFromString

func GetRangeFromString(input string) (low, high int, err error)

GetRangeFromString parses a string with the syntax #-# and returns the two numbers.

func GetVLANString

func GetVLANString(input string) (vlans []int, err error)

GetVLANString parses a line of comma-separated VLAN's in Cisco format 1,10,12-15,20 TODO: add support for whitespace in string

func GetVRFName

func GetVRFName(vlan *Vlan) string

GetVRFName Return the name of the VRF

func IntArrayEquals

func IntArrayEquals(a []int, b []int) bool

IntArrayEquals support func to verify arrays source: https://stackoverflow.com/questions/18561219/comparing-arrays-in-go-language

func SaveJsonToFile

func SaveJsonToFile(fn string, o interface{}) error

SaveJsonToFile save a struct to file as JSON with readable formatting. Returned is the error, if any.

Types

type Vlan

type Vlan struct {
	ID     int    // VLAN ID
	Name   string // name of VLAN
	Tenant string // tenant name
	VRF    string // name of VRF
	Domain string // physical domain
	App    string // Application associated with Vlan
	EPG    string // EPG associated with Vlan
}

Vlan is a struct that you can use to keep some information about a VLAN.

func FindVlan

func FindVlan(ID int, AllVlans []Vlan) *Vlan

FindVlan Look through an array of VLANs and find first VLAN with an ID, return nil if not found

func FindVlanDomain

func FindVlanDomain(ID int, AllVlans *[]Vlan, domain string) *Vlan

FindVlanDomain Look through an array of Vlans to find a VLAN inside a domain

func MakeTestVlans

func MakeTestVlans() []Vlan

MakeTestVlans this func just returns a list of VLANs that is used for testing code

func NewVlan

func NewVlan() *Vlan

NewVlan return a new Vlan with optional default values

func ReadVlanCsv

func ReadVlanCsv(inputFile string, separator rune, domain string) (vlans []Vlan, err error)

ReadVlanCsv This func reads a CSV file in the format "vlan,name,tenant,vrf,application,EPG"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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