diff --git a/huawei_vrp/Makefile b/huawei_vrp/Makefile index d9de8e38..f2ade9af 100644 --- a/huawei_vrp/Makefile +++ b/huawei_vrp/Makefile @@ -6,7 +6,8 @@ IMAGE_GLOB=*.qcow2 # match versions like: # huawei_ne40e-.qcow2 # huawei_ce12800-.qcow2 -VERSION=$(shell echo $(IMAGE) | sed -e 's/huawei_\(ne40e\|ce12800\)-\(.*\)\.qcow2/\1-\2/') +# huawei_ar1000v-.qcow2 +VERSION=$(shell echo $(IMAGE) | sed -e 's/huawei_\(ne40e\|ce12800\|ar1000v\)-\(.*\)\.qcow2/\1-\2/') -include ../makefile-sanity.include -include ../makefile.include diff --git a/huawei_vrp/README.md b/huawei_vrp/README.md index 0a0b4799..2b73841c 100644 --- a/huawei_vrp/README.md +++ b/huawei_vrp/README.md @@ -6,6 +6,8 @@ Rename your qcow2 disk image to conform to the following pattern: huawei_ne40e-.qcow2 or huawei_ce12800-.qcow2 +or +huawei_ar1000v-.qcow2 ``` Build the image with: diff --git a/huawei_vrp/docker/launch.py b/huawei_vrp/docker/launch.py index d71f9242..80abe1f0 100755 --- a/huawei_vrp/docker/launch.py +++ b/huawei_vrp/docker/launch.py @@ -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""], 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"", #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""], 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="]") + + # Envia o comando commit inicialmente + 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...") + 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": + 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):