Skip to content

Commit 14c7353

Browse files
committed
formatted
1 parent 0cc6a98 commit 14c7353

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

asav/docker/launch.py

+32-24
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,34 @@
55
import os
66
import re
77
import signal
8-
import subprocess
98
import sys
10-
import telnetlib
119
import time
1210

1311
import vrnetlab
1412

13+
1514
def handle_SIGCHLD(signal, frame):
1615
os.waitpid(-1, os.WNOHANG)
1716

17+
1818
def handle_SIGTERM(signal, frame):
1919
sys.exit(0)
2020

21+
2122
signal.signal(signal.SIGINT, handle_SIGTERM)
2223
signal.signal(signal.SIGTERM, handle_SIGTERM)
2324
signal.signal(signal.SIGCHLD, handle_SIGCHLD)
2425

2526
TRACE_LEVEL_NUM = 9
2627
logging.addLevelName(TRACE_LEVEL_NUM, "TRACE")
28+
29+
2730
def trace(self, message, *args, **kws):
2831
# Yes, logger takes its '*args' as 'args'.
2932
if self.isEnabledFor(TRACE_LEVEL_NUM):
3033
self._log(TRACE_LEVEL_NUM, message, args, **kws)
34+
35+
3136
logging.Logger.trace = trace
3237

3338

@@ -37,15 +42,15 @@ def __init__(self, username, password, install_mode=False):
3742
if re.search(".qcow2$", e):
3843
disk_image = "/" + e
3944

40-
super(ASAv_vm, self).__init__(username, password, disk_image=disk_image, ram=2048)
45+
super(ASAv_vm, self).__init__(
46+
username, password, disk_image=disk_image, ram=2048
47+
)
4148
self.nic_type = "e1000"
4249
self.install_mode = install_mode
4350
self.num_nics = 8
4451

45-
4652
def bootstrap_spin(self):
47-
""" This function should be called periodically to do work.
48-
"""
53+
"""This function should be called periodically to do work."""
4954

5055
if self.spins > 300:
5156
# too many spins with no result -> give up
@@ -54,8 +59,8 @@ def bootstrap_spin(self):
5459
return
5560

5661
(ridx, match, res) = self.tn.expect([b"ciscoasa>"], 1)
57-
if match: # got a match!
58-
if ridx == 0: # login
62+
if match: # got a match!
63+
if ridx == 0: # login
5964
if self.install_mode:
6065
self.logger.debug("matched, ciscoasa>")
6166
self.wait_write("", wait=None)
@@ -80,7 +85,7 @@ def bootstrap_spin(self):
8085

8186
# no match, if we saw some output from the router it's probably
8287
# booting, so let's give it some more time
83-
if res != b'':
88+
if res != b"":
8489
self.logger.trace("OUTPUT: %s" % res.decode())
8590
# reset spins if we saw some output
8691
self.spins = 0
@@ -89,10 +94,8 @@ def bootstrap_spin(self):
8994

9095
return
9196

92-
9397
def bootstrap_config(self):
94-
""" Do the actual bootstrap config
95-
"""
98+
"""Do the actual bootstrap config"""
9699
self.logger.info("applying bootstrap configuration")
97100
self.wait_write("", None)
98101
self.wait_write("enable", wait="ciscoasa>")
@@ -104,15 +107,17 @@ def bootstrap_config(self):
104107
self.wait_write("", wait="(config)#")
105108
self.wait_write("aaa authentication ssh console LOCAL")
106109
self.wait_write("aaa authentication enable console LOCAL")
107-
self.wait_write("username %s password %s privilege 15" % (self.username, self.password))
110+
self.wait_write(
111+
"username %s password %s privilege 15" % (self.username, self.password)
112+
)
108113
self.wait_write("interface Management0/0")
109114
self.wait_write("nameif management")
110115
self.wait_write("ip address 10.0.0.15 255.255.255.0")
111116
self.wait_write("no shutdown")
112117
self.wait_write("ssh 0.0.0.0 0.0.0.0 management")
113118
self.wait_write("ssh version 2")
114119
self.wait_write("ssh key-exchange group dh-group14-sha256")
115-
self.wait_write("crypto key generate ecdsa")
120+
self.wait_write("crypto key generate ecdsa")
116121
self.wait_write("write")
117122
self.wait_write("end")
118123
self.wait_write("\r", None)
@@ -121,15 +126,15 @@ def bootstrap_config(self):
121126
class ASAv(vrnetlab.VR):
122127
def __init__(self, username, password):
123128
super(ASAv, self).__init__(username, password)
124-
self.vms = [ ASAv_vm(username, password) ]
129+
self.vms = [ASAv_vm(username, password)]
125130

126131

127132
class ASAv_installer(ASAv):
128-
""" ASAv installer
129-
"""
133+
"""ASAv installer"""
134+
130135
def __init__(self, username, password):
131136
super(ASAv, self).__init__(username, password)
132-
self.vms = [ ASAv_vm(username, password, install_mode=True) ]
137+
self.vms = [ASAv_vm(username, password, install_mode=True)]
133138

134139
def install(self):
135140
self.logger.info("Installing ASAv")
@@ -141,13 +146,16 @@ def install(self):
141146
self.logger.info("Installation complete")
142147

143148

144-
if __name__ == '__main__':
149+
if __name__ == "__main__":
145150
import argparse
146-
parser = argparse.ArgumentParser(description='')
147-
parser.add_argument('--trace', action='store_true', help='enable trace level logging')
148-
parser.add_argument('--username', default='vrnetlab', help='Username')
149-
parser.add_argument('--password', default='VR-netlab9', help='Password')
150-
parser.add_argument('--install', action='store_true', help='Install ASAv')
151+
152+
parser = argparse.ArgumentParser(description="")
153+
parser.add_argument(
154+
"--trace", action="store_true", help="enable trace level logging"
155+
)
156+
parser.add_argument("--username", default="vrnetlab", help="Username")
157+
parser.add_argument("--password", default="VR-netlab9", help="Password")
158+
parser.add_argument("--install", action="store_true", help="Install ASAv")
151159
args = parser.parse_args()
152160

153161
LOG_FORMAT = "%(asctime)s: %(module)-10s %(levelname)-8s %(message)s"

0 commit comments

Comments
 (0)