Documentation ¶
Overview ¶
Package utils provides utility functions used in agentctl commands.
Index ¶
- Constants
- func DeleteDataFromDb(db keyval.ProtoBroker, key string, labelFilter []string, typeFilter []string) (bool, error)
- func ExitWithError(code int, err error)
- func GetDbForAllAgents(endpoints []string) (keyval.ProtoBroker, error)
- func GetDbForOneAgent(endpoints []string, agentLabel string) (keyval.ProtoBroker, error)
- func GetInterfaceKeyAndValue(endpoints []string, label string, ifName string) (bool, string, *interfaces.Interface, keyval.ProtoBroker)
- func IsFlagPresent(flag string) bool
- func ParseKey(key string) (label string, dataType string, name string, plugStatCfgRev string)
- func UpdateIpv4Address(old []string, updates []string) []string
- func UpdateIpv6Address(old []string, updates []string) []string
- func ValidateIpv4Addr(ipv4Addr string) bool
- func ValidateIpv6Addr(ipv6Addr string) bool
- func ValidatePhyAddr(pAddr string)
- func WriteInterfaceToDb(db keyval.ProtoBroker, key string, ifc *interfaces.Interface)
- type BdConfigWithMD
- type BdStateWithMD
- type BdWithMD
- type BridgeDomainErrorWithMD
- type EtcdDump
- func (ed EtcdDump) CreateEmptyRecord(key string)
- func (ed EtcdDump) PrintDataAsJSON(filter []string) (*bytes.Buffer, error)
- func (ed EtcdDump) PrintDataAsTable(table *goterm.Table, filter []string, short bool, active bool) (*goterm.Table, error)
- func (ed EtcdDump) PrintDataAsText(showEtcd bool, printAsTree bool) (*bytes.Buffer, error)
- func (ed EtcdDump) ReadDataFromDb(db keyval.ProtoBroker, key string, labelFilter []string, typeFilter []string) (found bool, err error)
- type FibTableWithMD
- type IfConfigWithMD
- type IfStateWithMD
- type InterfaceErrorWithMD
- type InterfaceWithMD
- type PfxStack
- type PfxStackEntry
- type PrintLine
- type StaticRoutesWithMD
- type TableVppDataContext
- type TreeWriter
- type VppData
- type VppMetaData
- type VppStatusWithMD
- type XconnectWithMD
Constants ¶
const ( ExitSuccess = iota ExitError ExitBadConnection ExitInvalidInput ExitBadFeature ExitInterrupted ExitIO ExitBadArgs = 128 )
Common exit flags
const ( HostIfName = "host-if-name" MemifMaster = "master" MemifMode = "mode" MemifID = "id" MemifSktFileName = "sock-filename" MemifSecret = "secret" MemifRingSize = "ring-size" MemifBufferSize = "buffer-size" MemifRxQueues = "rx-queues" MemifTxQueues = "tx-queues" VxLanSrcAddr = "src-addr" VxLanDstAddr = "dst-addr" VxLanVni = "vni" )
Interface flag names
const ( // IfConfig labels used by json formatter IfConfig = "INTERFACE CONFIG" // IfState labels used by json formatter IfState = "INTERFACE STATE" // BdConfig labels used by json formatter BdConfig = "BRIDGE DOMAINS CONFIG" // BdState labels used by json formatter BdState = "BRIDGE DOMAINS State" // L2FibConfig labels used by json formatter L2FibConfig = "L2 FIB TABLE" // L3FibConfig labels used by json formatter L3FibConfig = "L3 FIB TABLE" )
const ( InPkt string = "IN-PKT" InBytes string = "IN-BYTES" InErrPkt string = "IN-ERR-PKT" InMissPkt string = "IN-MISS-PKT" InNoBuf string = "IN-NO-BUFF" OutPkt string = "OUT-PKT" OutBytes string = "OUT-BYTES" OutErrPkt string = "OUT-ERR-PKT" Drop string = "DROP" Punt string = "PUNT" Ipv4Pkt string = "IPV4-PKT" Ipv6Pkt string = "IPV6-PKT" NoData string = "Nothing to show, add some data or change the filter" NoSpace string = "There is not enough space to show the whole table. Use --short" )
Used as a header/info message
Variables ¶
This section is empty.
Functions ¶
func DeleteDataFromDb ¶
func DeleteDataFromDb(db keyval.ProtoBroker, key string, labelFilter []string, typeFilter []string) (bool, error)
DeleteDataFromDb deletes the specified Key from the database if the Key matches both the labelFilter and the dataFilter.
The function returns an error if the etcd client encountered an error. The function returns true if the specified item has been found and successfully deleted.
func ExitWithError ¶
ExitWithError is used by all commands to print out an error and exit.
func GetDbForAllAgents ¶
func GetDbForAllAgents(endpoints []string) (keyval.ProtoBroker, error)
GetDbForAllAgents opens a connection to etcd, specified in the command line or the "ETCD_ENDPOINTS" environment variable.
func GetDbForOneAgent ¶
func GetDbForOneAgent(endpoints []string, agentLabel string) (keyval.ProtoBroker, error)
GetDbForOneAgent opens a connection to etcd, specified in the command line or the "ETCD_ENDPOINTS" environment variable.
func GetInterfaceKeyAndValue ¶
func GetInterfaceKeyAndValue(endpoints []string, label string, ifName string) (bool, string, *interfaces.Interface, keyval.ProtoBroker)
GetInterfaceKeyAndValue returns true if an interface with the specified name was found together with the interface key, and data, and data broker.
func IsFlagPresent ¶
IsFlagPresent verifies flag presence in the OS args.
func ParseKey ¶
ParseKey parses the etcd Key for the microservice label and the data type encoded in the Key. The function returns the microservice label, the data type and the list of parameters, that contains path segments that follow the data path segment in the Key URL. The parameter list is empty if data path is the Last segment in the Key.
URI Examples: * /vnf-agent/{agent-label}/vpp/config/v1/interface/{interface-name} * /vnf-agent/{agent-label}/vpp/status/v1/interface/{interface-name} * /vnf-agent/{agent-label}/check/status/v1/agent
Explanation of the URI examples: * allAgntsPref label plugin stats ver dataType * ps[0] ps[1] ps[2]ps[3] ps[4]
Example for dataType ... "check/status/v1/"
func UpdateIpv4Address ¶
UpdateIpv4Address updates interface's IPv4 address.
func UpdateIpv6Address ¶
UpdateIpv6Address updates interface's IPv6 address.
func ValidateIpv4Addr ¶
ValidateIpv4Addr validates string representation of IPv4 address.
func ValidateIpv6Addr ¶
ValidateIpv6Addr validates string representation of IPv6 address.
func ValidatePhyAddr ¶
func ValidatePhyAddr(pAddr string)
ValidatePhyAddr validates string representation of MAC address.
func WriteInterfaceToDb ¶
func WriteInterfaceToDb(db keyval.ProtoBroker, key string, ifc *interfaces.Interface)
WriteInterfaceToDb validates and writes interface to the etcd.
Types ¶
type BdConfigWithMD ¶
type BdConfigWithMD struct { Metadata VppMetaData BridgeDomain *l2.BridgeDomain }
BdConfigWithMD contains a Bridge Domain config data record and its etcd metadata.
type BdStateWithMD ¶
type BdStateWithMD struct {
Metadata VppMetaData
}
BdStateWithMD contains a Bridge Domain state data record and its etcd metadata.
type BdWithMD ¶
type BdWithMD struct { Config *BdConfigWithMD State *BdStateWithMD }
BdWithMD contains a Bridge Domain data record and its etcd metadata.
type BridgeDomainErrorWithMD ¶
type BridgeDomainErrorWithMD struct { VppMetaData BdErrorList []*l2.BridgeDomain }
BridgeDomainErrorWithMD contains a data record for bridge domain errors and its etcd metadata.
type EtcdDump ¶
EtcdDump is a map of VppData records. It constitutes a temporary storage for data retrieved from etcd. "Temporary" means during the execution of an agentctl command. Every command reads data from etcd first, then processes it, and finally either outputs the processed data to the user or updates one or more data records in etcd.
func NewEtcdDump ¶
func NewEtcdDump() EtcdDump
NewEtcdDump returns a new instance of the temporary storage that will hold data retrieved from etcd.
func (EtcdDump) CreateEmptyRecord ¶
CreateEmptyRecord creates an empty placeholder record in the EtcdDump temporary storage.
func (EtcdDump) PrintDataAsJSON ¶
PrintDataAsJSON prints etcd data in JSON format.
func (EtcdDump) PrintDataAsTable ¶
func (ed EtcdDump) PrintDataAsTable(table *goterm.Table, filter []string, short bool, active bool) (*goterm.Table, error)
PrintDataAsTable receives the complete etcd data, applies all filters, flags and other restrictions, then prints table filled with interface statistics.
func (EtcdDump) PrintDataAsText ¶
PrintDataAsText prints data from an EtcdDump repo in the text format. If the tree option is chosen, output is printed with tree lines.
func (EtcdDump) ReadDataFromDb ¶
func (ed EtcdDump) ReadDataFromDb(db keyval.ProtoBroker, key string, labelFilter []string, typeFilter []string) (found bool, err error)
ReadDataFromDb reads a data record from etcd, parses it according to the expected record type and stores it in the EtcdDump temporary storage. A record is identified by a Key.
The function returns an error if the etcd client encountered an error. The function returns true if the specified item has been found.
type FibTableWithMD ¶
type FibTableWithMD struct { VppMetaData FibTable []*l2.FIBEntry }
FibTableWithMD contains an FIB table data record and its etcd metadata.
type IfConfigWithMD ¶
type IfConfigWithMD struct { Metadata VppMetaData Interface *interfaces.Interface }
IfConfigWithMD contains a data record for interface configuration and its etcd metadata.
type IfStateWithMD ¶
type IfStateWithMD struct { Metadata VppMetaData InterfaceState *interfaces.InterfaceState }
IfStateWithMD contains a data record for interface state and its etcd metadata.
type InterfaceErrorWithMD ¶
type InterfaceErrorWithMD struct {
VppMetaData
}
InterfaceErrorWithMD contains a data record for interface errors and its etcd metadata.
type InterfaceWithMD ¶
type InterfaceWithMD struct { Config *IfConfigWithMD State *IfStateWithMD }
InterfaceWithMD contains a data record for interface and its etcd metadata.
type PfxStack ¶
type PfxStack struct { Entries []PfxStackEntry Spaces int FirstDash string MiddleDash string LastDash string }
PfxStack is helper struct while creating tree output.
func (*PfxStack) GetPreamble ¶
GetPreamble creates the string for a prefix stack entry. The prefix itself is then created by joining all prefix Entries.
func (*PfxStack) Pop ¶
func (stack *PfxStack) Pop()
Pop increases the current prefix stack level (i.e. it make the prefix stack shorter). If the element at the top of the prefix stack is not the the Last element on a list after Pop, it's replaced with the list element (FirstDash) icon.
func (*PfxStack) Push ¶
func (stack *PfxStack) Push()
Push increases the current prefix stack level (i.e. it makes the prefix stack longer). If the list at the current level continues (i.e. the list element is not the Last element), the current prefix element is replaced with a vertical bar (MiddleDash) icon. If the current element is the Last element of a list, the current prefix element is replaced with a space (i.e. the vertical line in the tree will not continue).
type PfxStackEntry ¶
PfxStackEntry represents entry in prefix stack entry list.
type PrintLine ¶
type PrintLine struct {
// contains filtered or unexported fields
}
PrintLine represents one line in the tree output.
type StaticRoutesWithMD ¶
type StaticRoutesWithMD struct { VppMetaData Routes []*l3.Route }
StaticRoutesWithMD contains a static route data record and its etcd metadata.
type TableVppDataContext ¶
type TableVppDataContext struct {
// contains filtered or unexported fields
}
TableVppDataContext is the data context for one vpp (where number of interfaces == rows) with mandatory info: agent label (vpp name), list of interfaces used in table (without filtered items) and interfaceMap with statistics data.
type TreeWriter ¶
type TreeWriter struct {
// contains filtered or unexported fields
}
TreeWriter is an implementation of the TreePrinter interface.
func NewTreeWriter ¶
func NewTreeWriter(spaces int, first string, middle string, last string) *TreeWriter
NewTreeWriter returns a reference to a newly created TreeWriter instance. Parameters passed into this function determine the visual appearance of the tree in which the data is printed. A typical usage would be:
p := NewTreeWriter(1, "├─", "│ ", "└─")
func (*TreeWriter) FlushTree ¶
func (p *TreeWriter) FlushTree()
FlushTree takes the content of the finalized buffer, and formats it into a tree, and prints it out to stdout.
type VppData ¶
type VppData struct { Interfaces map[string]InterfaceWithMD InterfaceErrors map[string]InterfaceErrorWithMD BridgeDomains map[string]BdWithMD BridgeDomainErrors map[string]BridgeDomainErrorWithMD FibTableEntries FibTableWithMD XConnectPairs map[string]XconnectWithMD StaticRoutes StaticRoutesWithMD Status map[string]VppStatusWithMD ShowEtcd bool }
VppData defines a structure to hold all etcd data records (of all types) for one VPP.
type VppMetaData ¶
VppMetaData defines the etcd metadata.
type VppStatusWithMD ¶
type VppStatusWithMD struct { VppMetaData status.AgentStatus }
VppStatusWithMD contains a VPP Status data record and its etcd metadata.
type XconnectWithMD ¶
type XconnectWithMD struct { VppMetaData *l2.XConnectPair }
XconnectWithMD contains an l2 cross-Connect data record and its etcd metadata.