Skip to content

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion huawei_vrp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ IMAGE_GLOB=*.qcow2
# match versions like:
# huawei_ne40e-<any version string>.qcow2
# huawei_ce12800-<any version string>.qcow2
VERSION=$(shell echo $(IMAGE) | sed -e 's/huawei_\(ne40e\|ce12800\)-\(.*\)\.qcow2/\1-\2/')
# huawei_ar1000v-<any version string>.qcow2
VERSION=$(shell echo $(IMAGE) | sed -e 's/huawei_\(ne40e\|ce12800\|ar1000v\)-\(.*\)\.qcow2/\1-\2/')

-include ../makefile-sanity.include
-include ../makefile.include
2 changes: 2 additions & 0 deletions huawei_vrp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Rename your qcow2 disk image to conform to the following pattern:
huawei_ne40e-<version>.qcow2
or
huawei_ce12800-<version>.qcow2
or
huawei_ar1000v-<version>.qcow2
```

Build the image with:
Expand Down
160 changes: 119 additions & 41 deletions huawei_vrp/docker/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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)

Expand All @@ -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)
Copy link

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.

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="]")
Expand All @@ -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="]")
Expand All @@ -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
Expand All @@ -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="]")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this commented out?


# Envia o comando commit inicialmente
Copy link

Choose a reason for hiding this comment

The 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...")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here about language. Also, don't print to stdout, but rather use the logger.

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":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the AR1000V not use commit?

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):
Expand Down