parser

package
v0.0.0-...-fd06c70 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeTypeRoot = iota
	NodeTypeNode
	NodeTypeLeaf
	NodeTypeTag
)

Variables

This section is empty.

Functions

func WriteConfigBootFormat

func WriteConfigBootFormat(ast *VyOSConfigAST) (string, error)

func WriteSetFormat

func WriteSetFormat(ast *VyOSConfigAST) (string, error)

WriteSetFormat returns a string that contains the `set` format of the specified config AST. That is, it writes out a bunch of `set ...` command lines that can be copied into VyOS to tell it to configure itself a specific way.

func WriteShowFormat

func WriteShowFormat(ast *VyOSConfigAST) (string, error)

Types

type Node

type Node struct {
	ContextNode *configmodel.VyOSConfigNode
	Type        string
	Value       *string
	Children    []*Node
}

func (*Node) Sort

func (n *Node) Sort()

func (*Node) TreeSize

func (n *Node) TreeSize() int

type VyOSConfigAST

type VyOSConfigAST struct {
	Child *Node
}

func ParseConfigBootFormat

func ParseConfigBootFormat(config string, configModel *configmodel.VyOSConfigNode) (*VyOSConfigAST, error)

ParseConfigBootFormat takes a VyOS text configuration in `config.boot` format and returns a VyOSConfigAST and/or an error.

func ParseSetFormat

func ParseSetFormat(config string, configModel *configmodel.VyOSConfigNode) (*VyOSConfigAST, error)

ParseSetFormat takes a VyOS text configuration in `set` format and returns a VyOSConfigAST and/or an error.

Note that VyOS's config outputter (`show | commands`) isn't very consistent about quoting. Examples, from VyOS 1.5 202501xxx:

set firewall ipv4 forward filter default-action 'accept'
set protocols static route 16.0.0.0/8 next-hop 10.250.0.1
set service ntp allow-client address '0.0.0.0/0'
set service ntp server 10.1.0.238
set service ssh port '22'
set system name-server '8.8.8.8'

For my sample config, I never see TagNodes with quoted names, but LeafNodes *sometimes* are quoted and sometimes not. Compare the `set service ntp server` and `set system name-server` lines -- they both contain an IP address here, but one is quoted and one isn't.

func ParseShowFormat

func ParseShowFormat(config string, configModel *configmodel.VyOSConfigNode) (*VyOSConfigAST, error)

ParseShowFormat takes a VyOS text configuration in the format returned by 'show' from config mode and returns a VyOSConfigAST and/or an error.

func (*VyOSConfigAST) Sort

func (vca *VyOSConfigAST) Sort()

func (*VyOSConfigAST) TreeSize

func (vca *VyOSConfigAST) TreeSize() int

Jump to

Keyboard shortcuts

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