confparser

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 4 Imported by: 0

README

Network Device Configuration Parser (confparser)

Overview

This Network Device Configuration Parser library was written to fulfil the need to parse Cisco switch configuration files.

I've used it in a number of projects where I needed to grab information from these types of configuration files. It's very basic, but has saved me from having to repeatedly implement all of the regular expressions and logical multiple times.

At the moment, the library only supports Cisco IOS switch configuration files. It's been primarily tested with IOS 12.x files, but should work on any. But make sure you test and validate!

It may also work on Cisco IOS router configuration files. It's just geared towards information in Switch interfaces, as opposed to the IP interfaces, which are more common in routers.

Disclaimer

This is the standard, "Use at your own risk," disclaimer. You are very welcome to use the library, but if you do, then that's on you. 😉

See the LICENSE.md file for full details.

How To Use - The Basics

First, import the library as normal:

import (
	"github.com/tinyinput/confparser"
)

Then the easiest was to parse a configuration file is to first create a Client:

package main

import (
	"github.com/tinyinput/confparser"
)

func main() {
	// Create a Client
	client, err := confparser.NewClient("cisco")
	if err != nil {
		// Handle the error
	}
}

Next you can pass your configuration file to the Client, to return a Config Parser:

package main

import (
	"github.com/tinyinput/confparser"
)

var (
	confFile = `Some long multi-line confguration file text`
)

func main() {
	// Create a Client
	client, err := confparser.NewClient("cisco")
	if err != nil {
		// Handle the error
	}
	// Pass your configuration file to the Client to create a Config Parser
	myConfigParser := client.ConfigParser(confFile)
}

Then you can call various Methods on your Config Parser to extract elements from the configuration.

For example, if you wanted to hostname from the configuration, simply call that Method:

package main

import (
	"github.com/tinyinput/confparser"
	"fmt"
)

var (
	confFile = `Some long multi-line confguration file text`
)

func main() {
	// Create a Client
	client, err := confparser.NewClient("cisco")
	if err != nil {
		// Handle the error
	}
	// Pass your configuration file to the Client to create a Config Parser
	myConfigParser := client.ConfigParser(confFile)
	// Call the Hostname() Method to return the hostname from the configuration
	hostname := myConfigParser.Hostname()
	//
	fmt.Printf("Hostname from the Config: %s\n", hostname)
}

If you wanted to extract all of the interface configuration blocks, you could you the Method InterfaceBlocks(). The Methods can also be combined with the Config Parser creation, into a single line.

For example:

package main

import (
	"github.com/tinyinput/confparser"
	"fmt"
)

var (
	confFile = `Some long multi-line confguration file text`
)

func main() {
	// Create a Client
	client, err := confparser.NewClient("cisco")
	if err != nil {
		// Handle the error
	}
	// Pass your configuration file to the Client to create a Config Parser
	// and extract the interface configuration blacks
	myInterfaceConfigBlocks := client.ConfigParser(confFile).InterfaceBlocks()
	//
	fmt.Printf("Count of Interface Config Blocks from the Config: %v\n", len(myInterfaceConfigBlocks))
}

How To Use - Interface Configuration

The main use-case I had for the library was to extract interface configurations from Cisco switch configurations.

I then needed to parse out various elements from each interface.

  • What was the Access Vlan Number?
  • What was the Description
  • Was the interface a Trunk?
  • Was the interface Shutdown?

The library allows me to do this in a number of ways.

First, we need the interface configuration blocks:

package main

import (
	"github.com/tinyinput/confparser"
)

var (
	confFile = `Some long multi-line confguration file text`
)

func main() {
	// Create a Client
	client, err := confparser.NewClient("cisco")
	if err != nil {
		// Handle the error
	}
	// Pass your configuration file to the Client to create a Config Parser
	// and extract the interface configuration blacks
	myInterfaceConfigBlocks := client.ConfigParser(confFile).InterfaceBlocks()
}

We can then loop over each interface configuration block to extract the various logical elements we need. It's up to you as to exactly what you want, so below is just an example:

package main

import (
	"github.com/tinyinput/confparser"
)

var (
	confFile = `Some long multi-line confguration file text`
)

type myInterfaceType struct {
	name        string
	description string
	shutdown    bool
}

type myInterfacesType []myInterfaceType

func main() {
	// Create a Client
	client, err := confparser.NewClient("cisco")
	if err != nil {
		// Handle the error
	}
	// Pass your configuration file to the Client to create a Config Parser
	// and extract the interface configuration blacks
	myInterfaceConfigBlocks := client.ConfigParser(confFile).InterfaceBlocks()
	// Create a variable to hold our all of our interface information
	var myInterfaces myInterfacesType
	// Start a loop over all of the interface configuration blocks
	for _, block := range myInterfaceConfigBlocks {
		// Create a temporary interface struct to hold our parsed information
		var myinterface myInterfaceType
		// Create an Interface Configuration Parser, populated with the interface configuration block
		myIntParser := client.ConfigIntParser(block)
		// Use the appropriate method to extract information and store it in our temporary interface struct
		myinterface.name = myIntParser.InterfaceNameFull()
		myinterface.description = myIntParser.Description()
		myinterface.shutdown = myIntParser.IsShutdown()
		// Append the temporary interface struct to our main variable we created earlier
		myInterfaces = append(myInterfaces, myinterface)
	}
	// Start a loop over all of our parsed interfaces
	for _, intf := range myInterfaces {
		// Print the information for each interface
		fmt.Printf("Interface: %s - Description: %s - Shutdown? %v\n", intf.name, intf.description, intf.shutdown)
	}
}

The Configuration Parser Interface

The following Methods are defined for the ConfParser interface type. It is the type which can be ued to extract various elments from the main configuration.

  • Set(s string)
    • This can be used to pass the configuration to the Parser
  • String()
    • The outputs the configuration set on the Parser
  • Hostname()
    • The Hostname defined in the configuration
  • InterfaceBlocks()
    • The Interface Blocks from the configuration
  • InterfaceBlocksEthernet()
    • Only the Ethernet Interface Blocks from the configuration
  • InterfaceBlocksVlan()
    • Only the Vlan Interface Blocks from the configuration
  • VlanBlocks()
    • The Vlan Blocks from the configuration

The Interface Configuration Parser Interface

(Yes... It's a confusing heading...)

The following Methods are defined for the ConfIntParser interface type. It is the type which can be used to extract various information and logical state from individual blocks of interface configuration.

  • Set(s string)
    • This can be used to pass the interface configuration to the Parser
  • String()
    • The outputs the interface configuration set on the Parser
  • InterfaceNameFull()
    • The Full interface name
  • InterfaceNameShort()
    • The Shortened interface name
  • Description()
    • The interface Description
  • VlanAccess()
    • The configured Access Vlan number on the interface
  • VlanVoice()
    • The configured Voice Vlan number on the interface
  • VlanTrunkNative()
    • The configured Trunk Native Vlan number on the interface
  • VlansTrunkAllowed()
    • The configured Allowed Vlan numbers on the Trunk for the interface
  • IpAddressAndMask()
    • The IP Address and Subnet Mask configured on the interface
  • IpAddress()
    • The IP Address configured on the interface
  • IpMask()
    • The Subnet Mask configured on the interface
  • IsShutdown()
    • Is the interface configured to be Shutdown?
  • IsSwAccess()
    • Is the interface configured to be an Access switch port?
  • IsSwTrunk()
    • Is the interface configured to be a Trunk switch port?
  • IsPoeDisabled()
    • Is Power over Ethernet disabled on the interface?
    • Note: A false result doesn't guarantee that PoE is Enabled. You can only use this check to see is configuration exists to manually Disabled PoE.
  • IsEthernet()
    • Is the interface an Ethernet interface?
  • IsEthernetFast()
    • Is the interface a Fast Ethernet interface?
  • IsEthernetGigabit()
    • Is the interface a Gigabit Ethernet interface?
  • IsEthernetTenGigabit()
    • Is the interface a Ten Gigabit Ethernet interface?
  • IsVlan()
    • Is the interface a Vlan interface?

For more details about return types and caveats, see the comments for the specific parser Methods in the code.

General Notes on Errors

One thing to note is that the Functions and Methods in the library will return empty strings or slices in preference to errors. The theory being, that in most cases, if a configuration item isn't found, it's not an error; it's just not in the config!

Extras - How to Read a Configuration File

It's outside the scope of this library to discuss all of the ways in which Golang can read files. But in the interests of getting people started, the following works for me:

package main

import (
	"github.com/tinyinput/confparser"
	"fmt"
	"os"
)

func main() {
	// Use the ReadFile() function from the os library
	data, err := os.ReadFile("/user/home/me/data/configFile")
	if err != nil {
		// Handle the error
	}
	// Create a Client
	client, err := confparser.NewClient("cisco")
	if err != nil {
		// Handdle the error
	}
	// Pass your configuration file to the Client, as a string, to create a Config Parser,
	// then call the `Hostname()` method
	myConfigParser := client.ConfigParser(string(data)).Hostname()
	// Print the hostname from the configuration file
	fmt.Printf("Hostname from the Config: %s\n", hostname)
}

This uses the Function ReadFile() from the os library here: https://pkg.go.dev/os#ReadFile

Extras - Adding a new Configuration "Make"

As explained above, this library was written primarily to parse Cisco switch configuration files. But at the same time, it was written so that you can add your own logic for a new type (or Make) of configuration file.

If you're a seasoned Gopher, then it should be pretty clear as to how this is done.

There are basically 3 steps:

  1. Create 3 Type definitions similar to: CiscoConf, CiscoConfVlan and CiscoConfInt
  2. Create Methods for each of your new Types that fulfil the Interfaces: ConfParser, ConfVlanParser and ConfIntParser
  3. Create a new global variable for your make of Type ParserClient. See ciscoParserClient as an example
  4. Update these Functions with a new case statement: NewClient(), NewConfigParser(), NewConfigVlanParser() and NewConfigIntParser()

Then in the code which uses the updated library, you should be to call NewClient("your custom make") to create a Parser Client that supports your custom configuration file.

Documentation

Overview

The package confparser is used to extract element and logical configuration state from network device configuration files.

It was written for a small personal project, but feel free to use or fork as required.

At the time of writing, only Cisco IOS configurations are supported. But the library was written with the intention of being extensible at a later date.

Creating a Client

The eaiest way to use the package is to create a client for the make of networking device configuration you want to parse.

For example:

package main

import (
	"fmt"
	".../parser"
)

func main() {
	// Create the Parser Client
	client, err := parser.NewClient(parser.PARSER_CISCO)
	if err != nil {
		// Handle the error
	}
	// Check the Parser Client make
	fmt.Printf("This Parser Client is for \"%v\" Configuration Files\n", client.Make)
}

You then have the choice to parse either:

- The whole configuration file - A single block of vlan configuration - A single block of Interface configuration

Parsing an Interface Configuration Block

The most common use-case for me was the need to parse Interface configuration blocks and extract the relavent elements.

For example:

package main

import (
	"fmt"
	".../confparser"
)

const (
	myInterfaceConfig = `interface GigabitEthernet1/0/1
 description STANDARD ACCESS INTERFACE
 switchport access vlan 101
 switchport mode access
 power inline never`
)

func main() {
	// Create the Conf Parser Client
	client, err := confparser.NewClient(confparser.PARSER_CISCO)
	if err != nil {
		// Handle the error
	}

	// Create a Config Interface Parser and Set the Interface Configuration:
	confIntParser := client.NewConfigIntParser()
	Set(myInterfaceConfig)

	// Evaluate aspects of the Interface Configuration
	fmt.Printf("Full Name for Interface: %v\n", confIntParser.InterfaceNameFull())
	fmt.Printf("Short Name for Interface: %v\n", confIntParser.InterfaceNameShort())
	fmt.Printf("Access Vlan for Interface: %v\n", confIntParser.VlanAccess())
}

See the code and testing packages for me details.

Index

Constants

View Source
const (
	CommandsCiscoShowConfig     = "show run,show running-config"
	CommandsCiscoShowInterfaces = "show interfaces"
	CommandsCiscoShowVersion    = "show version"
)
View Source
const (
	PrefixCiscoConfInterface = "interface"
	PrefixCiscoConfVlan      = "vlan"
)
View Source
const (
	RegexCiscoConfMainHostname              = `^\s*hostname (.+)$`
	RegexCiscoConfVlan                      = `^\s*vlan \d+$`
	RegexCiscoConfVlanNumber                = `^\s*vlan (\d+)$`
	RegexCiscoConfVlanName                  = `^\s*name (.+)$`
	RegexCiscoConfInterface                 = `^\s*interface .+$`
	RegexCiscoConfIntNameFull               = `^\s*interface (.+)$`
	RegexCiscoConfIntNameShort              = `^\s*interface (.{2})[^\d]+(.+)$`
	RegexCiscoConfIntDescription            = `^\s*description\s(.+)$`
	RegexCiscoConfIntShutdown               = `^\s*shutdown\s*$`
	RegexCiscoConfIntNoShutdown             = `^\s*no\sshutdown\s*$`
	RegexCiscoConfIntSwitchPortModeAccess   = `^\s*switchport mode access\s*$`
	RegexCiscoConfIntSwitchPortModeTrunk    = `^\s*switchport mode trunk\s*$`
	RegexCiscoConfIntAccessVlan             = `^\s*switchport access vlan (\d+)\s*$`
	RegexCiscoConfIntVoiceVlan              = `^\s*switchport voice vlan (\d+)\s*$`
	RegexCiscoConfIntTrunkNativeVlan        = `^\s*switchport trunk native vlan (\d+)\s*$`
	RegexCiscoConfIntTrunkAllowedVlans      = `^\s*switchport trunk allowed vlan ([\d,]+)\s*$`
	RegexCiscoConfIntPowerInlineNever       = `^\s*power inline never\s*$`
	RegexCiscoConfIntNoIpV4Address          = `^\s*no ip address\s*$`
	RegexCiscoConfIntIpV4AddressAndMask     = `^\s*ip address (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*$`
	RegexCiscoConfIntPowerInlineConsumption = `^\s*power inline consumption (\d+)\s*$`
	RegexCiscoConfIntTypeEthernet           = `^\s*interface .+Ethernet\d+`
	RegexCiscoConfIntTypeVlan               = `^\s*interface Vlan\d+`
	RegexCiscoConfIntTypeEthernetFast       = `^\s*interface FastEthernet\d+`
	RegexCiscoConfIntTypeEthernetGigabit    = `^\s*interface GigabitEthernet\d+`
	RegexCiscoConfIntTypeEthernetTenGigabit = `^\s*interface TenGigabitEthernet\d+`
)
View Source
const (
	// Supprted Parser Makes
	PARSER_CISCO = "cisco"
	PARSER_HP    = "hp"
)

Variables

This section is empty.

Functions

func GetBlocksByPrefixString added in v0.2.0

func GetBlocksByPrefixString(s, p string) []string

GetBlocksByPrefixString can be used to extract any block from the configuration by using a Prefix string as a delimiter.

It also works just as well on single lines which have a defined prefix, such as "aaa" or "snmp-server".

TODO: Needs Test

func GetBlocksByRegexString added in v0.2.0

func GetBlocksByRegexString(s, r string) []string

GetBlocksByRegexString can be used to extract any block from the configuration by using a Prefix regex string as a delimiter. The regex should be passed as a string, so that the calling module does not need to import the regexp package. If the regex string fails to compile, a nil slice will be returned.

It also works just as well on single lines which have a defined prefix, such as "aaa" or "snmp-server".

TODO: Needs Test

func GetCiscoConfIntAccessVlan

func GetCiscoConfIntAccessVlan(s string) string

func GetCiscoConfIntDescription

func GetCiscoConfIntDescription(s string) string

func GetCiscoConfIntIpV4Address

func GetCiscoConfIntIpV4Address(s string) string

func GetCiscoConfIntIpV4AddressAndMask

func GetCiscoConfIntIpV4AddressAndMask(s string) string

func GetCiscoConfIntIpV4Mask

func GetCiscoConfIntIpV4Mask(s string) string

func GetCiscoConfIntNameFull

func GetCiscoConfIntNameFull(s string) string

func GetCiscoConfIntNameShort

func GetCiscoConfIntNameShort(s string) string

func GetCiscoConfIntPowerInlineConsumption

func GetCiscoConfIntPowerInlineConsumption(s string) string

func GetCiscoConfIntTrunkAllowedVlans

func GetCiscoConfIntTrunkAllowedVlans(s string) string

func GetCiscoConfIntTrunkAllowedVlansSlice

func GetCiscoConfIntTrunkAllowedVlansSlice(s string) []string

func GetCiscoConfIntTrunkNativeVlan

func GetCiscoConfIntTrunkNativeVlan(s string) string

func GetCiscoConfIntVoiceVlan

func GetCiscoConfIntVoiceVlan(s string) string

func GetCiscoConfMainHostname

func GetCiscoConfMainHostname(s string) string

func GetCiscoConfVlanName

func GetCiscoConfVlanName(s string) string

func GetCiscoConfVlanNumber

func GetCiscoConfVlanNumber(s string) string

func GetInterfaceBlocks

func GetInterfaceBlocks(s string) []string

func GetInterfaceBlocksByType

func GetInterfaceBlocksByType(s, t string) []string

func GetInterfaceBlocksEthernet

func GetInterfaceBlocksEthernet(s string) []string

func GetInterfaceBlocksVlan

func GetInterfaceBlocksVlan(s string) []string

func GetVlanBlocks

func GetVlanBlocks(s string) []string

func IsCiscoConfIntEthernet added in v0.2.0

func IsCiscoConfIntEthernet(s string) bool

func IsCiscoConfIntEthernetFast added in v0.2.0

func IsCiscoConfIntEthernetFast(s string) bool

func IsCiscoConfIntEthernetGigabit added in v0.2.0

func IsCiscoConfIntEthernetGigabit(s string) bool

func IsCiscoConfIntEthernetTenGigabit added in v0.2.0

func IsCiscoConfIntEthernetTenGigabit(s string) bool

func IsCiscoConfIntIpV4Int

func IsCiscoConfIntIpV4Int(s string) bool

func IsCiscoConfIntPowerInlineConsumption

func IsCiscoConfIntPowerInlineConsumption(s string) bool

func IsCiscoConfIntPowerInlineNever

func IsCiscoConfIntPowerInlineNever(s string) bool

IsCiscoConfIntPowerInlineNever will return true if the interface configuration contains "power inline never". NOTE: This indicates that PoE is disabled. I.e. `true` indicates NO PoE on the interface.

func IsCiscoConfIntShutdown

func IsCiscoConfIntShutdown(s string) bool

func IsCiscoConfIntSwitchPortModeAccess

func IsCiscoConfIntSwitchPortModeAccess(s string) bool

func IsCiscoConfIntSwitchPortModeTrunk

func IsCiscoConfIntSwitchPortModeTrunk(s string) bool

func IsCiscoConfIntVlan added in v0.2.0

func IsCiscoConfIntVlan(s string) bool

Types

type CiscoConf

type CiscoConf string

CiscoConf is the full configuration for a Cisco device from the `show running-config` command output.

func (CiscoConf) Hostname

func (c CiscoConf) Hostname() string

Hostname returns the hostname from the configuration, as a string.

func (CiscoConf) InterfaceBlocks

func (c CiscoConf) InterfaceBlocks() []string

InterfaceBlocks returns all of the "interface xxx" sections from the configuration, as a slice of string. Any errors in the extraction will not be reported and a nil slice will be returned.

func (CiscoConf) InterfaceBlocksEthernet

func (c CiscoConf) InterfaceBlocksEthernet() []string

InterfaceBlocksEthernet returns all of the "interface xxx" sections from the configuration, where the interface is an "Ethernet" type, as a slice of string. Any errors in the extraction will not be reported and a nil slice will be returned.

func (CiscoConf) InterfaceBlocksVlan

func (c CiscoConf) InterfaceBlocksVlan() []string

InterfaceBlocksEthernet returns all of the "interface xxx" sections from the configuration, where the interface is a "Vlan" type, as a slice of string. Any errors in the extraction will not be reported and a nil slice will be returned.

func (*CiscoConf) Set

func (c *CiscoConf) Set(s string)

Set is used to pass a configuration to the CiscoConf type.

func (CiscoConf) String

func (c CiscoConf) String() string

String is used to output the CiscoConf type as a string. It fulfills the Stringer interface.

func (CiscoConf) VlanBlocks

func (c CiscoConf) VlanBlocks() []string

InterfaceBlocks returns all of the "interface xxx" sections from the configuration, as a slice of string. Any errors in the extraction will not be reported and a nil slice will be returned.

type CiscoConfInt

type CiscoConfInt string

CiscoConfInt is the interface configuration block for a Cisco device from the `show running-config` command output. For example:

interface GigabitEthernet1/0/22
  description [A-001]
  switchport access vlan 101
  switchport mode access
  power inline never

A block can be extracted from the main configuration using the `CiscoConf.IntrfacBlocks()` method.

func (CiscoConfInt) Description

func (c CiscoConfInt) Description() string

Description returns the `description xxx` from the interface configuration block, as a string.

func (CiscoConfInt) InterfaceNameFull

func (c CiscoConfInt) InterfaceNameFull() string

InterfaceNameFull returns the full intrface name from the interface configuration block, as a string.

func (CiscoConfInt) InterfaceNameShort

func (c CiscoConfInt) InterfaceNameShort() string

InterfaceNameShort returns the shortened interface name from the interface configuration block, as a string. For example, `GigabitEthernet1/0/22`, would be shortened to, `Gi1/0/22`.

func (CiscoConfInt) IpAddress

func (c CiscoConfInt) IpAddress() string

IpAddress - To Be Documented

func (CiscoConfInt) IpAddressAndMask

func (c CiscoConfInt) IpAddressAndMask() string

IpAddressAndMask - To Be Documented

func (CiscoConfInt) IpMask

func (c CiscoConfInt) IpMask() string

IpMask - To Be Documented

func (CiscoConfInt) IpV4Address

func (c CiscoConfInt) IpV4Address() string

IpV4Address - To Be Documented

func (CiscoConfInt) IpV4AddressAndMask

func (c CiscoConfInt) IpV4AddressAndMask() string

IpV4AddressAndMask - To Be Documented

func (CiscoConfInt) IpV4Mask

func (c CiscoConfInt) IpV4Mask() string

IpV4Mask - To Be Documented

func (CiscoConfInt) IsEthernet added in v0.2.0

func (c CiscoConfInt) IsEthernet() bool

IsEthernetInt - To Be Documented

func (CiscoConfInt) IsEthernetFast added in v0.2.0

func (c CiscoConfInt) IsEthernetFast() bool

IsEthernetInt - To Be Documented

func (CiscoConfInt) IsEthernetGigabit added in v0.2.0

func (c CiscoConfInt) IsEthernetGigabit() bool

IsEthernetInt - To Be Documented

func (CiscoConfInt) IsEthernetTenGigabit added in v0.2.0

func (c CiscoConfInt) IsEthernetTenGigabit() bool

IsEthernetInt - To Be Documented

func (CiscoConfInt) IsIpInt

func (c CiscoConfInt) IsIpInt() bool

IsIpInt - To Be Documented

func (CiscoConfInt) IsIpV4Int

func (c CiscoConfInt) IsIpV4Int() bool

IsIpV4Int - To Be Documented

func (CiscoConfInt) IsPoeDisabled

func (c CiscoConfInt) IsPoeDisabled() bool

IsPoeDisabled tests to see if PoE is disabled on the interface. By default, PoE is enabled in auto mode, but there would be no configuration line for this.

So it's better to test for the negative (I.e. Is PoE disabled?), as this is an explicit configuration entry.

func (CiscoConfInt) IsPoeStatic

func (c CiscoConfInt) IsPoeStatic() bool

IsPoeStatic - To Be Documented

func (CiscoConfInt) IsShutdown

func (c CiscoConfInt) IsShutdown() bool

IsShutdown returns the configured interface shutdown state from the interface configuration block, as a bool. If the interface is shutdown/disabled, then IsShutdown will return true.

func (CiscoConfInt) IsSwAccess

func (c CiscoConfInt) IsSwAccess() bool

IsSwAccess returns the configured switchport access state from the interface configuration block, as a bool. If the interface as the config, `switchport mode access`, then IsSwAccess will return true.

func (CiscoConfInt) IsSwTrunk

func (c CiscoConfInt) IsSwTrunk() bool

IsSwTrunk returns the configured switchport trunk state from the interface configuration block, as a bool. If the interface as the config, `switchport mode trunk`, then IsSwTrunk will return true.

func (CiscoConfInt) IsVlan added in v0.2.0

func (c CiscoConfInt) IsVlan() bool

IsVlanInt - To Be Documented

func (CiscoConfInt) PoeConsumption

func (c CiscoConfInt) PoeConsumption() string

PoeConsumption - To Be Documented

func (*CiscoConfInt) Set

func (c *CiscoConfInt) Set(s string)

Set is used to pass an interfacee configuration block to the CiscoConfInt type.

func (CiscoConfInt) String

func (c CiscoConfInt) String() string

String is used to output the CiscoConfInt type as a string. It fulfills the Stringer interface.

func (CiscoConfInt) VlanAccess

func (c CiscoConfInt) VlanAccess() string

VlanAccess returns the `switchport access vlan xxx` number from the interface configuration block, as a string.

func (CiscoConfInt) VlanTrunkNative

func (c CiscoConfInt) VlanTrunkNative() string

VlanTrunkNative returns the `switchport trunk native vlan xxx` number from the interface configuration block, as a string.

func (CiscoConfInt) VlanVoice

func (c CiscoConfInt) VlanVoice() string

VlanVoice returns the `switchport voice vlan xxx` number from the interface configuration block, as a string.

func (CiscoConfInt) VlansTrunkAllowed

func (c CiscoConfInt) VlansTrunkAllowed() string

VlansTrunkAllowed returns the `switchport trunk allowed vlan xxx` list from the interface configuration block, as a comma separated string. For example, `switchport trunk allowed vlan 100,200,300`, would return the string, `100,200,300`.

func (CiscoConfInt) VlansTrunkAllowedSlice

func (c CiscoConfInt) VlansTrunkAllowedSlice() []string

VlansTrunkAllowedSlice returns the `switchport trunk allowed vlan xxx` list from the interface configuration block, as a slice of strings.

type CiscoConfVlan

type CiscoConfVlan string

CiscoConfVlan is a single vlan configuration block for a Cisco device from the `show running-config` command output. For example:

vlan 101
  name Internet

A block can be extracted from the main configuration using the `CiscoConf.VlanBlocks()` method.

func (*CiscoConfVlan) Set

func (c *CiscoConfVlan) Set(s string)

Set is used to pass a vlan configuration block to the CiscoConfVlan type.

func (CiscoConfVlan) String

func (c CiscoConfVlan) String() string

String is used to output the CiscoConfVlan type as a string. It fulfills the Stringer interface.

func (CiscoConfVlan) VlanName

func (c CiscoConfVlan) VlanName() string

VlanName returns the vlan name from the vlan configuration block, as a string.

func (CiscoConfVlan) VlanNumber

func (c CiscoConfVlan) VlanNumber() string

VlanNumber returns the vlan number from the vlan configuration block, as a string.

type ConfIntParser

type ConfIntParser interface {
	Set(s string)
	String() string
	InterfaceNameFull() string
	InterfaceNameShort() string
	Description() string
	VlanAccess() string
	VlanVoice() string
	VlanTrunkNative() string
	VlansTrunkAllowed() string
	//	VlansTrunkAllowedSlice() []string // Not implemented yet
	IpAddressAndMask() string
	IpAddress() string
	IpMask() string
	IsShutdown() bool
	IsSwAccess() bool
	IsSwTrunk() bool
	IsPoeDisabled() bool
	IsEthernet() bool
	IsEthernetFast() bool
	IsEthernetGigabit() bool
	IsEthernetTenGigabit() bool
	IsVlan() bool
}

ConfIntParser is an interface which all device interface configuration parsers should fulfill.

type ConfParser

type ConfParser interface {
	Set(s string)
	String() string
	Hostname() string
	InterfaceBlocks() []string
	InterfaceBlocksEthernet() []string
	InterfaceBlocksVlan() []string
	VlanBlocks() []string
}

ConfParser is an interface which all device configuration parsers should fulfill.

type ConfVlanParser

type ConfVlanParser interface {
	Set(s string)
	String() string
	VlanNumber() string
	VlanName() string
}

VlanParser is an interface which all device vlan configuration parsers should fulfill.

type ParserClient

type ParserClient struct {
	Make             string `json:"make"`
	ConfigParser     confParserFunc
	ConfigVlanParser confVlanParserFunc
	ConfigIntParser  confIntParserFunc
}

TBD

func NewClient

func NewClient(make string) (*ParserClient, error)

func

func (*ParserClient) NewConfigIntParser

func (p *ParserClient) NewConfigIntParser() ConfIntParser

TBD

func (*ParserClient) NewConfigParser

func (p *ParserClient) NewConfigParser() ConfParser

TBD

func (*ParserClient) NewConfigVlanParser

func (p *ParserClient) NewConfigVlanParser() ConfVlanParser

TBD

type ShowCommands

type ShowCommands interface {
	IsConfigCommand() bool
	IsVersionCommand() bool
}

TBD

Jump to

Keyboard shortcuts

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