|
NAMENet::CLI::Interact::Phrasebook - Load command phrasebooks from a LibraryDESCRIPTIONA command phrasebook is where you store the repeatable sequences of commands which can be sent to connected network devices. An example would be a command to show the configuration of a device: storing this in a phrasebook (sometimes known as a dictionary) saves time and effort.This module implements the loading and preparing of phrasebooks from an on-disk file-based hierarchical library, and makes them available to the application as smart objects for use in Net::CLI::Interact sessions. Entries in the phrasebook will be one of the following types:
The named regular expressions used in Prompts and Macros are known as Match statements. The command statements in Macros which are sent to the device are known as Send statements. That is, Prompts and Macros are built from one or more Match and Send statements. Each Send or Match statement becomes an instance of the Net::CLI::Interact::Action class. These are built up into Prompts and Macros, which become instances of the Net::CLI::Interact::ActionSet class. USAGEA phrasebook is a plain text file containing named Prompts or Macros. Each file exists in a directory hierarchy, such that files "deeper" in the hierarchy have their entries override the similarly named entries higher up. For example:/dir1/file1 /dir1/file2 /dir1/dir2/file3 Entries in "file3" sharing a name with any entries from "file1" or "file2" will take precedence. Those in "file2" will also override entries in "file1", because asciibetical sorting places the files in that order, and later definitions with the same name and type override earlier ones. When this module is loaded, a personality key is required. This locates a directory on disk, and then the files in that directory and all its ancestors in the hierarchy are loaded. The directories to search are specified by two Library options (see below). All phrasebooks matching the given personality are loaded, allowing a user to override or augment the default, shipped phrasebooks. INTERFACEnew( \%options )This takes the following options, and returns a loaded phrasebook object:
prompt( $name )Returns the Prompt associated to the given $name, or throws an exception if no such prompt can be found. The returned object is an instance of Net::CLI::Interact::ActionSet.has_prompt( $name )Returns true if a prompt of the given $name exists in the loaded phrasebooks.prompt_namesReturns a list of the names of the current loaded Prompts.macro( $name )Returns the Macro associated to the given $name, or throws an exception if no such macro can be found. The returned object is an instance of Net::CLI::Interact::ActionSet.has_macro( $name )Returns true if a macro of the given $name exists in the loaded phrasebooks.macro_namesReturns a list of the names of the current loaded Macros.PHRASEBOOK FORMATPromptA Prompt is a named regular expression which matches the content of a single line of text. Here is an example:prompt configure match /\(config[^)]*\)# ?$/ On the first line is the keyword "prompt" followed by the name of the Prompt, which must be a valid Perl identifier (letters, numbers, underscores only). On the immediately following line is the keyword "match" followed by a regular expression, enclosed in two forward-slash characters. Currently, no alternate bookend characters are supported, nor are regular expression modifiers (such as "xism") outside of the match, but you can of course include them within. The Prompt is used to find out when the connected CLI has emitted all of the response to a command. Try to make the Prompt as specific as possible, including line-end anchors. Remember that it will be matched against one line of text, only. MacroIn general, Macros are alternating sequences of commands to send to the connected CLI, and regular expressions to match the end of the returned response. Macros are useful for issuing commands which have intermediate prompts, or confirmation steps. They also support the slurping of additional output when the connected CLI has split the response into pages.At its simplest a Macro can be just one command: macro show_int_br send show ip int br match /> ?$/ On the first line is the keyword "macro" followed by the name of the Macro, which must be a valid Perl identifier (letters, numbers, underscores only). On the immediately following line is the keyword "send" followed by a space and then any text up until the end of the line, and if you want to include whitespace at the beginning or end of the command, use quotes. This text is sent to the connected CLI as a single command statement. The next line contains the keyword "match" followed by the Prompt (regular expression) which will terminate gathering of returned output from the sent command. Macros support the following features:
Visit the GSP FreeBSD Man Page Interface. |