Skip to content

IOSXEDriver

Carl Montanari edited this page May 10, 2020 · 4 revisions

Table of Contents


Removing Users

In IOSXE devices, removing users causes the device to prompt for confirmation. This can be seen below in the output from manually removing a user:

csr1000v#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
csr1000v(config)#no username deleteme
This operation will remove all username related configurations with same name.Do you want to continue? [confirm]

scrapli has a method to handle exactly this type of scenario! It is the send_interactive method, which does what it sounds like it should do -- sends commands in an "interactive" fashion. This allows for dealing with prompts for user input or changing prompts that don't match the privilege level prompt patterns.

See the Handling Prompts section of the readme for some more generic details about this method/pattern.

To handle this particular challenge we need only to understand two "interact" events, the first is sending the command that "tiggers" the prompt from the router, in this case no username deleteme; this input prompts the router to respond This operation will remove all username related configurations with same name.Do you want to continue? [confirm]. The next input we would need to enter as a user would be a newline/enter, in scrapli we can pass an empty string or a newline character. Finally, we need to understand what the router will "respond" to our newline input with... in this case the router will be back at "normal" config mode prompts.

A simple way to handle this would be to create the interact_events input as follows:

interact_events = [
    ('no username deleteme', 'This operation will remove all username related configurations with same name.Do you want to continue? [confirm]'),
    ('', csr1000v(config)#,
]

The above interact_events can be passed to the send_interactive method with the extra privilege_level argument set to "configuration" so that scrapli executes this interactive event in config mode:

interactive_output = conn.send_interactive(interact_events=interact_events, privilege_level="configuration")

If you don't know the exact prompt for the device, you could dynamically get it by using the get_prompt method while in configuration mode prior to creating the interact_events:

conn.acquire_priv("configuration")
config_prompt = conn.get_prompt()

interact_events = [
    ('no username horseinthesky', '[confirm]'),
    ('', config_prompt),
]

interactive_output = conn.send_interactive(interact_events=interact_events, privilege_level="configuration")

NOTE There is no space between the "same name." and "Do you want" in the output from IOSXE devices I have tested against -- you may wish to simply match [confirm] instead of the entire prompt string in case this has been fixed on other versions of IOSXE!

Clone this wiki locally