configmodel

package module
v0.0.0-...-47685d5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InterfaceDefinition

type InterfaceDefinition struct {
	Nodes []*Node `xml:"node", json:"Node"`
}

InterfaceDefinition is the top-level definition of an config setting in VyOS's XML spec. It should really be called `ConfigDefinition` or similar, but the XML tag that they use is `InterfaceDefinition` so I'm sticking with that.

func (*InterfaceDefinition) VyOSConfig

func (id *InterfaceDefinition) VyOSConfig() *VyOSConfigNode

type LeafNode

type LeafNode struct {
	Name       string          `xml:"name,attr" json:"name"`
	Owner      string          `xml:"owner,attr" json:"-"`
	Properties *NodeProperties `xml:"properties" json:"-"`
	ValueType  string          `json:"valuetype"`
}

LeafNode models the `<leafNode>` tag in VyOS's XML config spec. A leafNode is a terminal node with no children and optionally a single parameter or list of parameters.

func (*LeafNode) VyOSConfigNode

func (ln *LeafNode) VyOSConfigNode() *VyOSConfigNode

type Node

type Node struct {
	Name       string          `xml:"name,attr" json:"name"`
	Owner      string          `xml:"owner,attr" json:"-"`
	Properties *NodeProperties `xml:"properties" json:"-"`
	Children   *NodeChildren   `xml:"children" json:"children"`
}

Node models the `<node>` tag in VyOS's XML config spec. A node is basically a fixed string with no value in the middle of a config line. So, with `interface ethernet eth0 address dhcp` the first `interface` is a Node, while `ethernet eth0` is a TagNode (with a parameter after the node name) and `address dhcp` is a LeafNode (with no children and an optional parameter).

func (*Node) VyOSConfigNode

func (n *Node) VyOSConfigNode() *VyOSConfigNode

type NodeChildren

type NodeChildren struct {
	LeafNodes []*LeafNode `xml:"leafNode" json:"LeafNodes,omitempty"`
	Nodes     []*Node     `xml:"node" json:"Nodes,omitempty"`
	TagNodes  []*TagNode  `xml:"tagNode" json:"TagNodes,omitempty"`
}

NodeChildren models the `<children>` tag inside of the various node types in VyOS's XML config spec. There are three types of nodes, each contained in their own list.

func (*NodeChildren) VyOSConfigNode

func (nc *NodeChildren) VyOSConfigNode() []*VyOSConfigNode

type NodeProperties

type NodeProperties struct {
	DefaultValue   string                    `xml:"defaultValue" json:"-"`
	Help           []*PropertyHelp           `xml:"help" json:"-"`
	CompletionHelp []*PropertyCompletionHelp `xml:"completionHelp" json:"-"`
	ValueHelp      []*PropertyValueHelp      `xml:"valueHelp" json:"-"`
	Constraint     []*PropertyConstraint     `xml:"constraint" json:"-"`
	//ConstraintErrorMessage string `xml:"constraintErrorMessage,chardata"`
	Multi     *bool `xml:"multi" json:"multi,omitempty"`
	Valueless *bool `xml:"valueless" json:"valueless,omitempty"`
}

NodeProperties model the `<properties>` tag in VyOS's XML config spec. This includes help text, validation options, and a number of other things that we don't actually care about at the moment. It also contains two booleans, `Multi` and `Valueless` that tell us when a Node (or generally a LeafNode) take either multiple values or no values at all.

type PropertyCompletionHelp

type PropertyCompletionHelp struct {
	InnerXML string `xml:",innerxml"` // Just collect for now.
}

type PropertyConstraint

type PropertyConstraint struct {
	InnerXML string `xml:",innerxml"` // Just collect for now.
}

type PropertyHelp

type PropertyHelp struct {
	Text string `xml:",chardata"`
}

type PropertyValueHelp

type PropertyValueHelp struct {
	InnerXML string `xml:",innerxml"` // Just collect for now.
}

type TagNode

type TagNode struct {
	Name       string          `xml:"name,attr" json:"name"`
	Owner      string          `xml:"owner,attr" json:"-"`
	Properties *NodeProperties `xml:"properties" json:"-"`
	Children   *NodeChildren   `xml:"children" json:"children"`
}

TagNode models the `<tagNode>` tag in VyOS's XML config spec. A tagNode is a node in the middle of the config space that takes a value; in `interface ethernet eth0 address dhcp`, the `ethernet eth0` is a tagNode, with a value of `eth0`.

func (*TagNode) VyOSConfigNode

func (tn *TagNode) VyOSConfigNode() *VyOSConfigNode

type VyOSConfigNode

type VyOSConfigNode struct {
	Type     string            `json:"type,omitempty"`
	Name     string            `json:"name"`
	Children []*VyOSConfigNode `json:"children,omitempty"`
	Multi    *bool             `json:"multi,omitempty"`
	HasValue *bool             `json:"has_value,omitempty"`
}

func LoadJSONFile

func LoadJSONFile(filename string) (*VyOSConfigNode, error)

Read ConfigModel from a JSON file

func (*VyOSConfigNode) FindNodeByName

func (vcn *VyOSConfigNode) FindNodeByName(name string) *VyOSConfigNode

func (*VyOSConfigNode) Merge

func (vcn *VyOSConfigNode) Merge(b *VyOSConfigNode)

Merge the children of 2 nodes together

func (*VyOSConfigNode) WriteJSONFile

func (vcn *VyOSConfigNode) WriteJSONFile(filename string, umask fs.FileMode) error

Write ConfigModel to JSON file

Jump to

Keyboard shortcuts

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