Got it

Display inventory for Huawei devices using python

Created: Jan 3, 2022 22:37:04Latest reply: Jan 12, 2022 22:32:24 568 9 1 0 1
  Rewarded HiCoins: 0 (problem resolved)

Dears; 

how to use python script for cllecting all inforamation about huawei devices such 

- inventory board and shassis with BarCode

- all IP for a network more than 400 NE 

Thank you

Featured Answers

Hello there!


If you'd like to collect the data of all NEs in your network, you first need to know at least their login IP addresses and the login accounts. It is much easier if all NEs have the same account, such as the same SSH account. So you can use a loop statement to log in to each device in turn to collect information.


Script example:


# -*- coding:utf-8 -*-
import paramiko
import time
ssh = paramiko.SSHClient()
key = paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(key)

def execute(addr):
   
ssh.connect(addr, 22, 'test', '123456', timeout=200)  # The Username/Password of the SSH account.
   
ssh_shell = ssh.invoke_shell()
   
output =[]
   
for script in scripts:
       
ssh_shell.send(script)
       
output.append(ssh_shell.recv(2024).decode('utf-8'))
       
time.sleep(0.1)
   
return output

if __name__ == '__main__':

   
# Devices to execute scripts in batches
   
devices = ['10.1.1.1', '10.1.1.2', '10.1.1.3']

   
# Scripts to be executed in batches
   # scripts = ['sys\n', 'sys sw\n', 'q\n', 'save\n', 'Y\n']
   
scripts = ['display esn', 'display ip interface brief']
   
# The display esn command displays the Equipment Serial Number (ESN) of a device.
   # The display ip interface brief command displays brief information about interface IP addresses.
   
for device in devices:
       
res = execute(device)
       
print(res) # Here you've got the commands output. You can save the output to a file or use the re module to extract the information you want.
View more
  • x
  • convention:

smileymind
smileymind Created Jan 4, 2022 12:11:26 (0) (0)
 

Recommended answer

stephen.xu
Admin Created Jan 4, 2022 01:28:47

Hello dear and Happy New Year!

Thank you for your patience.

There is no such Python script, sorry about that!

If you want to get such a script, you can contact HUAWEI Support.

View more
  • x
  • convention:

user_4495775
user_4495775 Created Jan 4, 2022 12:10:15 (0) (0)
 
All Answers
Hello! Thank you for contacting us.
We are working on an answer for you.
View more
  • x
  • convention:

Hello dear and Happy New Year!

Thank you for your patience.

There is no such Python script, sorry about that!

If you want to get such a script, you can contact HUAWEI Support.

View more
  • x
  • convention:

user_4495775
user_4495775 Created Jan 4, 2022 12:10:15 (0) (0)
 

Hello there!


If you'd like to collect the data of all NEs in your network, you first need to know at least their login IP addresses and the login accounts. It is much easier if all NEs have the same account, such as the same SSH account. So you can use a loop statement to log in to each device in turn to collect information.


Script example:


# -*- coding:utf-8 -*-
import paramiko
import time
ssh = paramiko.SSHClient()
key = paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(key)

def execute(addr):
   
ssh.connect(addr, 22, 'test', '123456', timeout=200)  # The Username/Password of the SSH account.
   
ssh_shell = ssh.invoke_shell()
   
output =[]
   
for script in scripts:
       
ssh_shell.send(script)
       
output.append(ssh_shell.recv(2024).decode('utf-8'))
       
time.sleep(0.1)
   
return output

if __name__ == '__main__':

   
# Devices to execute scripts in batches
   
devices = ['10.1.1.1', '10.1.1.2', '10.1.1.3']

   
# Scripts to be executed in batches
   # scripts = ['sys\n', 'sys sw\n', 'q\n', 'save\n', 'Y\n']
   
scripts = ['display esn', 'display ip interface brief']
   
# The display esn command displays the Equipment Serial Number (ESN) of a device.
   # The display ip interface brief command displays brief information about interface IP addresses.
   
for device in devices:
       
res = execute(device)
       
print(res) # Here you've got the commands output. You can save the output to a file or use the re module to extract the information you want.
View more
  • x
  • convention:

smileymind
smileymind Created Jan 4, 2022 12:11:26 (0) (0)
 
Good
View more
  • x
  • convention:

GOOD THX
View more
  • x
  • convention:

Good day. Automation are very good.
View more
  • x
  • convention:

thank you
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.