ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.63k stars 1.31k forks source link

Save config on Maipu switch #3396

Closed brancott closed 8 months ago

brancott commented 8 months ago

Hi guys! What is the ringt way to save running config on Maipu? 'net_connect.save_config()' doesn't do the trick. I managed to save config this way:

    output = net_connect.send_command_timing(
        "wr",
        strip_prompt=False,
        strip_command=False
    )
    if 'Are you sure to overwrite /flash/startup (Yes|No)?' in output:
        output += net_connect.send_command_timing(
            command_string="y",
            strip_prompt=False,
            strip_command=False
        )

But is there an easier way?

ktbyers commented 8 months ago

Here is the current Maipu save_config() method:

https://github.com/ktbyers/netmiko/blob/develop/netmiko/maipu/maipu.py#L17-L23

Is this prompting typing or does it only occur in special cases?

Are you sure to overwrite /flash/startup (Yes|No)
ktbyers commented 8 months ago

You can probably also do:

net_connect.save_config(cmd="write", confirm=False, confirm_response="y")
brancott commented 8 months ago

Hi @ktbyers, it always asks 'Are you sure to overwrite /flash/startup (Yes|No)', and output from 'net_connect.save_config(cmd="write", confirm=False, confirm_response="y")' gives same result as just 'net_connect.save_config()':

wr

yearcode commented 8 months ago

ktbyers means you could exec save_config method and input your args

output = net_connect.send_command_timing(
        "wr",
        strip_prompt=False,
        strip_command=False
    )
    if 'Are you sure to overwrite /flash/startup (Yes|No)?' in output:
        output += net_connect.send_command_timing(
            command_string="y",
            strip_prompt=False,
            strip_command=False
        )

=>

output = net_connect.save_config(cmd="write", confirm=False, confirm_response="y")
brancott commented 8 months ago

Works with net_connect.save_config(cmd="write", confirm=True, confirm_response="y")