Got it

Save configuration with Netmiko

Created: Jan 19, 2021 09:19:01Latest reply: Jan 20, 2021 10:07:15 3135 32 1 0 0
  Rewarded HiCoins: 0 (problem resolved)

Hi all

I configured some swithes with python using netmiko

but comand (Save) for save configuration doesnt work

any help ?

All Answers
Posted by aboyasir at 2021-01-19 10:58 I want to know how to add save command
What is the error message?
View more
  • x
  • convention:

from netmiko import ConnectHandler

import time

import datetime


IP_List = open('IP.txt')

for IP in IP_List:

    SWS = {

    'device_type': 'huawei',

    'ip': IP,

    'username': 'test',

    'password': 'test',

    }


    print ('\n ##### connection to device' + IP.strip() + '##### \n')

    net_connect = ConnectHandler(**SWS)

   

    config_commands = [ 'int loop 1',

                        'ip add 1.1.1.1 255.255.255.0'

                        'return'

                        'save']

    output = net_connect.send_config_set(config_commands)


View more
  • x
  • convention:

print(output)

View more
  • x
  • convention:

system-view

Enter system view, return user view with Ctrl+Z.

[BLD2-1ST-B2]int loop 1

[BLD2-1ST-B2-LoopBack1]ip add 1.1.1.1 255.255.255.0returnsave

                                      ^

Error: Wrong parameter found at '^' position.

[BLD2-1ST-B2-LoopBack1]return

<BLD2-1ST-B2>


this th error message


View more
  • x
  • convention:

Posted by aboyasir at 2021-01-20 05:39 system-viewEnter system view, return user view with Ctrl+Z.int loop 1ip add 1.1.1.1 255.255.255.0ret ...
Hi,
You just missed the commas in the scripts config_commands. Please modify it as below and test again:
config_commands = [ 'int loop 1',
'ip add 1.1.1.1 255.255.255.0',
'return',
'save',]
View more
  • x
  • convention:

after add commas

Traceback (most recent call last):
File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko-2.7.2-py3.9.egg\paramiko\channel.py", line 699, in recv
out = self.in_buffer.read(nbytes, self.timeout)
File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko-2.7.2-py3.9.egg\paramiko\buffered_pipe.py", line 164, in read
raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 569, in _read_channel_expect
File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko-2.7.2-py3.9.egg\paramiko\channel.py", line 701, in recv
raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\aeahmed\Desktop\Multi-con.py", line 21, in <module>
output = net_connect.send_config_set(config_commands)
File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 1884, in send_config_set
File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 646, in read_until_pattern
File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 579, in _read_channel_expect
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.
View more
  • x
  • convention:

Posted by aboyasir at 2021-01-20 06:13 after add commasTraceback (most recent call last): File "C:\Users\aeahmed\AppData\Local\Programs\Py ...
Well, when you type the save on the device, it will require you to enter Y or N to confirm the operating. I'm not sure if the netmiko supports pause a second after executing some command and then send other commands to the device. If yes, you can try adding extra config_commands below after pause the program for about one second.
config_commands = [ 'y',]

If not, please try to modify the config_commands as below:
config_commands = [ 'int loop 1',
'ip add 1.1.1.1 255.255.255.0',
'return',
'save',
'y',]
View more
  • x
  • convention:

config_commands = [ 'y',]

 ##### connection to device x.x.x.x #####


system-view

Enter system view, return user view with Ctrl+Z.

[BLD2-1ST-B2]y

             ^

Error: Unrecognized command found at '^' position.

[BLD2-1ST-B2]return

<BLD2-1ST-B2>



View more
  • x
  • convention:

If not, please try to modify the config_commands as below:



Traceback (most recent call last):

  File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko-2.7.2-py3.9.egg\paramiko\channel.py", line 699, in recv

    out = self.in_buffer.read(nbytes, self.timeout)

  File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko-2.7.2-py3.9.egg\paramiko\buffered_pipe.py", line 164, in read

    raise PipeTimeout()

paramiko.buffered_pipe.PipeTimeout


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 569, in _read_channel_expect

  File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko-2.7.2-py3.9.egg\paramiko\channel.py", line 701, in recv

    raise socket.timeout()

socket.timeout


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "C:\Users\aeahmed\Desktop\Multi-con.py", line 22, in <module>

    output = net_connect.send_config_set(config_commands)

  File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 1884, in send_config_set

  File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 646, in read_until_pattern

  File "C:\Users\aeahmed\AppData\Local\Programs\Python\Python39\lib\site-packages\netmiko-3.3.3rc0.dev0-py3.9.egg\netmiko\base_connection.py", line 579, in _read_channel_expect

netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.



View more
  • x
  • convention:

Posted by aboyasir at 2021-01-20 06:31 config_commands = [ 'y',] ##### connection to device x.x.x.x #####system-viewEnter system view, ret ...

No, the command 'y' should be typed after the command 'save'. I'm not sure whether a comma should be followed 'save'. Maybe, you can refer to the output of the device as below:

netmiko huawei


View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.