-
Notifications
You must be signed in to change notification settings - Fork 121
Support Huawei AR1000V #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9af936e
51d1ae7
856fdec
250e609
f0b3888
796d338
bfe2c3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,23 +47,34 @@ def __init__(self, username, password, hostname, conn_mode): | |
disk_image = "/" + e | ||
if "huawei_ne40e" in e: | ||
self.vm_type = "NE40E" | ||
ram=2048, | ||
smp="2", | ||
if "huawei_ce12800" in e: | ||
self.vm_type = "CE12800" | ||
ram=2048, | ||
smp="2", | ||
if "huawei_ar1000v" in e: | ||
self.vm_type = "AR1000V" | ||
ram=2048, | ||
smp="1", | ||
|
||
super(VRP_vm, self).__init__( | ||
username, | ||
password, | ||
disk_image=disk_image, | ||
ram=2048, | ||
smp="2", | ||
driveif="virtio", | ||
) | ||
|
||
self.hostname = hostname | ||
self.conn_mode = conn_mode | ||
self.num_nics = 14 | ||
self.nic_type = "virtio-net-pci" | ||
|
||
if self.vm_type == "AR1000V": | ||
self.num_nics = 6 | ||
else: | ||
self.num_nics = 14 | ||
|
||
|
||
def bootstrap_spin(self): | ||
"""This function should be called periodically to do work.""" | ||
|
||
|
@@ -73,22 +84,52 @@ def bootstrap_spin(self): | |
self.start() | ||
return | ||
|
||
(ridx, match, res) = self.tn.expect([b"<HUAWEI>"], 1) | ||
|
||
if match and ridx == 0: # got a match! | ||
# run main config! | ||
self.logger.info("Running bootstrap_config()") | ||
self.startup_config() | ||
self.bootstrap_config() | ||
time.sleep(1) | ||
# close telnet connection | ||
self.tn.close() | ||
# startup time? | ||
startup_time = datetime.datetime.now() - self.start_time | ||
self.logger.info("Startup complete in: %s" % startup_time) | ||
# mark as running | ||
self.running = True | ||
return | ||
if self.vm_type == "AR1000V": | ||
(ridx, match, res) = self.tn.expect([ | ||
b"Press any key to get started", #0 | ||
b"Username:", #1 | ||
b"Password:", #2 | ||
#b"<HUAWEI>", #3 | ||
], 5) | ||
|
||
if match: | ||
if ridx == 0: #Press any key to get started | ||
self.wait_write(cmd="", wait=None) | ||
elif ridx == 1: #Username: | ||
self.wait_write(cmd="super", wait=None) | ||
elif ridx == 2: #Password: | ||
self.wait_write(cmd="super", wait=None) | ||
self.logger.info("Running bootstrap_config()") | ||
self.startup_config() | ||
self.bootstrap_config() | ||
time.sleep(1) | ||
# close telnet connection | ||
self.tn.close() | ||
# startup time? | ||
startup_time = datetime.datetime.now() - self.start_time | ||
self.logger.info("Startup complete in: %s" % startup_time) | ||
# mark as running | ||
self.running = True | ||
return | ||
|
||
else: | ||
|
||
(ridx, match, res) = self.tn.expect([b"<HUAWEI>"], 1) | ||
|
||
if match and ridx == 0: # got a match! | ||
# run main config! | ||
self.logger.info("Running bootstrap_config()") | ||
self.startup_config() | ||
self.bootstrap_config() | ||
time.sleep(1) | ||
# close telnet connection | ||
self.tn.close() | ||
# startup time? | ||
startup_time = datetime.datetime.now() - self.start_time | ||
self.logger.info("Startup complete in: %s" % startup_time) | ||
# mark as running | ||
self.running = True | ||
return | ||
|
||
time.sleep(5) | ||
|
||
|
@@ -98,13 +139,14 @@ def bootstrap_spin(self): | |
self.logger.trace("OUTPUT: %s" % res.decode()) | ||
# reset spins if we saw some output | ||
self.spins = 0 | ||
|
||
self.spins += 1 | ||
|
||
return | ||
|
||
def bootstrap_mgmt_interface(self): | ||
self.wait_write(cmd="mmi-mode enable", wait=None) | ||
#self.wait_write(cmd="mmi-mode enable", wait=None) | ||
self.wait_write(cmd="screen-length 0", wait=None) | ||
self.wait_write(cmd="undo terminal monitor", wait=">") | ||
self.wait_write(cmd="system-view", wait=">") | ||
self.wait_write(cmd="ip vpn-instance __MGMT_VPN__", wait="]") | ||
self.wait_write(cmd="ipv4-family", wait="]") | ||
|
@@ -114,15 +156,18 @@ def bootstrap_mgmt_interface(self): | |
mgmt_interface = "MEth" | ||
if self.vm_type == "NE40E": | ||
mgmt_interface = "GigabitEthernet" | ||
if self.vm_type == "AR1000V": | ||
mgmt_interface = "GigabitEthernet" | ||
self.wait_write(cmd=f"interface {mgmt_interface} 0/0/0", wait="]") | ||
# Error: The system is busy in building configuration. Please wait for a moment... | ||
while True: | ||
self.wait_write(cmd="clear configuration this", wait=None) | ||
(idx, match, res) = self.tn.expect([rb"Error"], 1) | ||
if match and idx == 0: | ||
time.sleep(5) | ||
else: | ||
break | ||
if self.vm_type != "AR1000V": | ||
while True: | ||
self.wait_write(cmd="clear configuration this", wait=None) | ||
(idx, match, res) = self.tn.expect([rb"Error"], 1) | ||
if match and idx == 0: | ||
time.sleep(5) | ||
else: | ||
break | ||
self.wait_write(cmd="undo shutdown", wait=None) | ||
self.wait_write(cmd="ip binding vpn-instance __MGMT_VPN__", wait="]") | ||
self.wait_write(cmd="ip address 10.0.0.15 24", wait="]") | ||
|
@@ -144,15 +189,24 @@ def bootstrap_config(self): | |
self.wait_write(cmd="undo user-security-policy enable", wait="]") | ||
|
||
self.wait_write(cmd="aaa", wait="]") | ||
if self.vm_type == "AR1000V": | ||
self.wait_write(cmd="undo user-password complexity-check", wait="]") | ||
self.wait_write(cmd="undo local-aaa-user password policy administrator", wait="]") | ||
self.wait_write(cmd=f"undo local-user {self.username}", wait="]") | ||
self.wait_write( | ||
cmd=f"local-user {self.username} password irreversible-cipher {self.password}", | ||
wait="]", | ||
) | ||
self.wait_write(cmd=f"local-user {self.username} service-type ssh", wait="]") | ||
self.wait_write( | ||
cmd=f"local-user {self.username} user-group manage-ug", wait="]" | ||
) | ||
if self.vm_type == "AR1000V": | ||
self.wait_write( | ||
cmd=f"local-user {self.username} privilege level 15", wait="]" | ||
) | ||
self.wait_write(cmd=f"y", wait="]") | ||
else: | ||
self.wait_write( | ||
cmd=f"local-user {self.username} user-group manage-ug", wait="]" | ||
) | ||
self.wait_write(cmd="quit", wait="]") | ||
|
||
# SSH | ||
|
@@ -164,19 +218,43 @@ def bootstrap_config(self): | |
self.wait_write( | ||
cmd=f"ssh user {self.username} authentication-type password ", wait="]" | ||
) | ||
self.wait_write(cmd=f"ssh user {self.username} service-type all ", wait="]") | ||
if self.vm_type != "AR1000V": | ||
self.wait_write(cmd=f"ssh user {self.username} service-type all ", wait="]") | ||
self.wait_write(cmd="stelnet server enable", wait="]") | ||
|
||
# NETCONF | ||
self.wait_write(cmd="snetconf server enable", wait="]") | ||
self.wait_write(cmd="netconf", wait="]") | ||
self.wait_write(cmd="protocol inbound ssh port 830", wait="]") | ||
self.wait_write(cmd="quit", wait="]") | ||
|
||
self.wait_write(cmd="commit", wait="]") | ||
self.wait_write(cmd="return", wait="]") | ||
self.wait_write(cmd="save", wait=">") | ||
self.wait_write(cmd="undo mmi-mode enable", wait=">") | ||
if self.vm_type != "AR1000V": | ||
self.wait_write(cmd="snetconf server enable", wait="]") | ||
self.wait_write(cmd="netconf", wait="]") | ||
self.wait_write(cmd="protocol inbound ssh port 830", wait="]") | ||
#self.wait_write(cmd="quit", wait="]") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this commented out? |
||
|
||
# Envia o comando commit inicialmente | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please change these comments to be in English? |
||
self.wait_write(cmd="commit", wait="]") | ||
|
||
while True: | ||
(ridx, match, res) = self.tn.expect([ | ||
b"Error: The system is busy in building system configurations. Please wait a moment and then try again.", # 3 | ||
], timeout=1) | ||
|
||
if match: | ||
if ridx == 0: # Mensagem de erro ao tentar commit | ||
print("Sistema ocupado, aguardando 5 segundos para tentar novamente...") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here about language. Also, don't |
||
time.sleep(5) | ||
self.wait_write(cmd="commit", wait=None) | ||
else: | ||
break # Sai do loop caso não haja mais mensagens relevantes | ||
else: | ||
break # Sai do loop se nenhum match ocorrer dentro do timeout | ||
|
||
self.wait_write(cmd="return", wait="]") | ||
self.wait_write(cmd="save", wait=">") | ||
self.wait_write(cmd="undo mmi-mode enable", wait=">") | ||
|
||
if self.vm_type == "AR1000V": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the AR1000V not use |
||
self.wait_write(cmd="quit", wait="]") | ||
self.wait_write(cmd="save", wait=">") | ||
self.wait_write(cmd="y", wait=">") | ||
|
||
def startup_config(self): | ||
if not os.path.exists(STARTUP_CONFIG_FILE): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this not break the other Huawei VMs' configuration?
As far as I can tell, this disables the verification prompts for certain configuration commands.
Later, the code also undoes this, so I'm not sure where this would be set.