cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3705
Views
0
Helpful
2
Replies

Executing CLI Commands With Additional Prompts Through NSO

jmaruschak
Level 1
Level 1

When executing commands on the device CLI through NSO, is there a way to handle additional prompts or questions from the device? Our use case is upgrading the IOS software on all of our ASR920 devices. We upgrade the IOS software using a copy command, then configure the boot system flash command, and finally write and reload the device. Updating the config and running the write and reload commands should be straightforward, but we need to handle additional prompts following the copy command in order to automate the sequence. Is this something that NSO is capable of?

 

Command sequence:

#copy tftp:<filename> flash:

Address or name of remote host [<default tftp server>]?

Source filename [<filename>]?

Destination filename [<filename>]?

(config)#boot system flash bootflash:<filename>

(config)#end

#write

#reload

 

In the above sequence, following each ? symbol the device is waiting for user interaction. For our devices, the default option is fine, so manually we would simply press enter for each prompt. 

1 Accepted Solution

Accepted Solutions

joepak
Cisco Employee
Cisco Employee
Hi, take a look within the cisco-ios NED README and let me know if this is what you are looking for:

Generally the command output parsing halts when the NED detects
an operational or config prompt, however sometimes the command
requests additional input, 'answer(s)' to questions.

To respond to device question(s) there are 3 different methods,
checked in the listed order below:

[1] the action auto-prompts list, passed in the action
[2] the ned-settings cisco-ios live-status auto-prompts list
[3] the command line args "| prompts" option

IMPORTANT: [3] can be used to override an answer in auto-prompts.

Read on for details on each method:

[1] action auto-prompts list

The auto-prompts list is used to pass answers to questions, to
exit parsing, reset timeout or ignore output which triggered the
the built-in question handling. Each list entry contains a question
(regex format) and an optional answer (text or built-in keyword).

The following built-in answers are supported:

<exit> Halt parsing and return output
<prompt> Retrieve the answer from "| prompts" argument(s)
<timeout> Reset the read timeout, useful for slow commands
<ignore> (or IGNORE) Ignore the output and continue parsing
<enter> (or ENTER) Send a newline and continue parsing

Any other answer value is sent to the device followed by a newline,
unless the answer is a single letter answer in case which only the
single character is sent.

Note: not configuring an answer is the same as setting it to <ignore>

Here is an example of a command which needs to ignore some output
which would normally be interpreted as a question due to the colon:

exec auto-prompts { question "Certificate Request follows[:]" answer
"<ignore>" } "crypto pki enroll LENNART-TP | prompts yes no"

Also note the use of method 3, answering yes and no to the remaining
device questions.


[2] ned-settings cisco-ios live-status auto-prompts list

The auto-prompts list works exactly as [1] except that it is
configured and used for all device commands, i.e. not only for
this specific action.

Here are some examples of auto-prompts ned-settings:

devices global-settings ned-settings cisco-ios live-status auto-prompts Q1 question "System configuration has been modified" answer "no"
devices global-settings ned-settings cisco-ios live-status auto-prompts Q2 question "Do you really want to remove these keys" answer "yes"
devices global-settings ned-settings cisco-ios live-status auto-prompts Q3 question "Press RETURN to continue" answer ENTER

NOTE: Due to backwards compatibility, ned-setting auto-prompts
questions get ".*" appended to their regex unless ending with
"$". However, for option [1] the auto-prompt list passed in the
action, you must add ".*" yourself if this matching behaviour is
desired.


[3] "| prompts"

"| prompts" is passed in the command args string and is used to
submit answer(s) to the device without a matching question pattern.
IMPORTANT: It can also be used to override answer(s) configured in
auto-prompts list, unless the auto-prompts contains <exit> or
<timeout>, which are always handled first.

One or more answers can be submitted following this syntax:

| prompts <answer 1> .. [answer N]

For example:

devices device iosdev live-status exec any "reload | prompts no yes"

The following output of the device triggers the NED to look for the
answer in | prompts arguments:

":\\s*$"
"\\][\\?]?\\s*$"

In other words, the above two patterns (questions) have a built-in
<prompt> for an answer.

Additional patterns triggering | prompts may be configured by use
of auto-lists and setting the answer to <prompt>. This will force
the user to specify the answer in | prompts.

The <ignore> or IGNORE keywords can be used to ignore device output
matching the above and continue parsing. If all output should be
ignored, i.e. for a show command, '| noprompts' should be used.

Some final notes on the 'answer' leaf:

- "ENTER" or <enter> means a carriage return + line feed is sent.

- "IGNORE", "<ignore>" or unset means the prompt was not a
question, the device output is ignored and parsing continues.

- A single letter answer is sent without carriage return + line,
i.e. "N" will be sent as N only, with no return. If you want a
return, set "NO" as the answer instead.

=======

let me know if this is an acceptable solution to your question :)

View solution in original post

2 Replies 2

joepak
Cisco Employee
Cisco Employee
Hi, take a look within the cisco-ios NED README and let me know if this is what you are looking for:

Generally the command output parsing halts when the NED detects
an operational or config prompt, however sometimes the command
requests additional input, 'answer(s)' to questions.

To respond to device question(s) there are 3 different methods,
checked in the listed order below:

[1] the action auto-prompts list, passed in the action
[2] the ned-settings cisco-ios live-status auto-prompts list
[3] the command line args "| prompts" option

IMPORTANT: [3] can be used to override an answer in auto-prompts.

Read on for details on each method:

[1] action auto-prompts list

The auto-prompts list is used to pass answers to questions, to
exit parsing, reset timeout or ignore output which triggered the
the built-in question handling. Each list entry contains a question
(regex format) and an optional answer (text or built-in keyword).

The following built-in answers are supported:

<exit> Halt parsing and return output
<prompt> Retrieve the answer from "| prompts" argument(s)
<timeout> Reset the read timeout, useful for slow commands
<ignore> (or IGNORE) Ignore the output and continue parsing
<enter> (or ENTER) Send a newline and continue parsing

Any other answer value is sent to the device followed by a newline,
unless the answer is a single letter answer in case which only the
single character is sent.

Note: not configuring an answer is the same as setting it to <ignore>

Here is an example of a command which needs to ignore some output
which would normally be interpreted as a question due to the colon:

exec auto-prompts { question "Certificate Request follows[:]" answer
"<ignore>" } "crypto pki enroll LENNART-TP | prompts yes no"

Also note the use of method 3, answering yes and no to the remaining
device questions.


[2] ned-settings cisco-ios live-status auto-prompts list

The auto-prompts list works exactly as [1] except that it is
configured and used for all device commands, i.e. not only for
this specific action.

Here are some examples of auto-prompts ned-settings:

devices global-settings ned-settings cisco-ios live-status auto-prompts Q1 question "System configuration has been modified" answer "no"
devices global-settings ned-settings cisco-ios live-status auto-prompts Q2 question "Do you really want to remove these keys" answer "yes"
devices global-settings ned-settings cisco-ios live-status auto-prompts Q3 question "Press RETURN to continue" answer ENTER

NOTE: Due to backwards compatibility, ned-setting auto-prompts
questions get ".*" appended to their regex unless ending with
"$". However, for option [1] the auto-prompt list passed in the
action, you must add ".*" yourself if this matching behaviour is
desired.


[3] "| prompts"

"| prompts" is passed in the command args string and is used to
submit answer(s) to the device without a matching question pattern.
IMPORTANT: It can also be used to override answer(s) configured in
auto-prompts list, unless the auto-prompts contains <exit> or
<timeout>, which are always handled first.

One or more answers can be submitted following this syntax:

| prompts <answer 1> .. [answer N]

For example:

devices device iosdev live-status exec any "reload | prompts no yes"

The following output of the device triggers the NED to look for the
answer in | prompts arguments:

":\\s*$"
"\\][\\?]?\\s*$"

In other words, the above two patterns (questions) have a built-in
<prompt> for an answer.

Additional patterns triggering | prompts may be configured by use
of auto-lists and setting the answer to <prompt>. This will force
the user to specify the answer in | prompts.

The <ignore> or IGNORE keywords can be used to ignore device output
matching the above and continue parsing. If all output should be
ignored, i.e. for a show command, '| noprompts' should be used.

Some final notes on the 'answer' leaf:

- "ENTER" or <enter> means a carriage return + line feed is sent.

- "IGNORE", "<ignore>" or unset means the prompt was not a
question, the device output is ignored and parsing continues.

- A single letter answer is sent without carriage return + line,
i.e. "N" will be sent as N only, with no return. If you want a
return, set "NO" as the answer instead.

=======

let me know if this is an acceptable solution to your question :)

I think this covers our use case. We were able to test this on a physical device and we did get it to work after a few iterations. Thanks for the quick reply!

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: