@@ -29,13 +29,17 @@ def trace(self, message, *args, **kws):
29
29
logging .Logger .trace = trace
30
30
31
31
class OpenWRT_vm (vrnetlab .VM ):
32
- def __init__ (self , username , password ):
32
+ def __init__ (self , username , password , conn_mode , hostname , lan_ip , lan_netmask ):
33
33
for e in os .listdir ("/" ):
34
34
if re .search (".img$" , e ):
35
35
disk_image = "/" + e
36
36
super (OpenWRT_vm , self ).__init__ (username , password , disk_image = disk_image , ram = 128 )
37
37
self .nic_type = "virtio-net-pci"
38
38
self .num_nics = 1
39
+ self .conn_mode = conn_mode
40
+ self .hostname = hostname
41
+ self .lan_ip = lan_ip
42
+ self .lan_netmask = lan_netmask
39
43
40
44
def bootstrap_spin (self ):
41
45
""" This function should be called periodically to do work.
@@ -80,7 +84,7 @@ def bootstrap_config(self):
80
84
# Get a prompt
81
85
self .wait_write ("\r " , None )
82
86
# Configure interface
83
- self .wait_write ("ifconfig br-lan 10.0.0.15 netmask 255.255.255.0" , "#" )
87
+ self .wait_write ("ifconfig br-lan " + self . lan_ip + " netmask " + self . lan_netmask , "#" )
84
88
# Set root password (ssh login prerequisite)
85
89
self .wait_write ("passwd" , "#" )
86
90
self .wait_write (self .password , "New password:" )
@@ -96,28 +100,53 @@ def bootstrap_config(self):
96
100
# Create home dir
97
101
self .wait_write ("mkdir -p /home/%s" % (self .username ))
98
102
self .wait_write ("chown %s /home/%s" % (self .username , self .username ))
103
+ self .wait_write ("chown %s /etc/config/ -R" % (self .username ))
99
104
self .logger .info ("completed bootstrap configuration" )
100
105
101
106
class OpenWRT (vrnetlab .VR ):
102
- def __init__ (self , username , password ):
107
+ def __init__ (self , username , password , conn_mode , hostname , lan_ip , lan_netmask ):
103
108
super (OpenWRT , self ).__init__ (username , password )
104
- self .vms = [ OpenWRT_vm (username , password ) ]
109
+ self .vms = [ OpenWRT_vm (username , password , conn_mode , hostname , lan_ip , lan_netmask ) ]
110
+
111
+ import click
112
+ @click .command ()
113
+ @click .option ('--tracing' , is_flag = True , help = 'enable trace level logging' )
114
+ @click .option ('--username' ,'-u' , default = 'root' , envvar = 'USERNAME' , required = True , help = "Username" )
115
+ @click .option ('--password' ,'-p' , default = 'VR-netlab9' , envvar = 'PASSWORD' , required = True , help = "Password" )
116
+ @click .option ('--connection-mode' ,'-c' , default = 'tc' , envvar = 'CONNECTION_MODE' , required = True , help = "connection mode" )
117
+ @click .option ('--hostname' ,'-h' , default = 'OpenWRT' , envvar = 'HOSTNAME' , required = True , help = "Hostname" )
118
+ @click .option ('--lan-ip' ,'-ip' , default = '10.0.0.15' , envvar = 'LAN_IP' , required = True , help = "Lan IP" )
119
+ @click .option ('--lan-netmask' ,'-mask' , default = '255.255.255.0' , envvar = 'LAN_NETMASK' , required = True , help = "Lan netmask" )
120
+
121
+ def args (tracing ,username ,password ,connection_mode ,hostname ,lan_ip ,lan_netmask ):
122
+ LOG_FORMAT = "%(asctime)s: %(module)-10s %(levelname)-8s %(message)s"
123
+ logging .basicConfig (format = LOG_FORMAT )
124
+ logger = logging .getLogger ()
125
+
126
+ logger .setLevel (logging .DEBUG )
127
+ if tracing :
128
+ logger .setLevel (1 )
129
+
130
+ vr = OpenWRT (username , password , connection_mode , hostname , lan_ip , lan_netmask )
131
+ vr .start ()
105
132
106
133
if __name__ == '__main__' :
107
- import argparse
108
- parser = argparse .ArgumentParser (description = '' )
109
- parser .add_argument ('--trace' , action = 'store_true' , help = 'enable trace level logging' )
110
- parser .add_argument ('--username' , default = 'vrnetlab' , help = 'Username' )
111
- parser .add_argument ('--password' , default = 'VR-netlab9' , help = 'Password' )
112
- args = parser .parse_args ()
113
-
114
- LOG_FORMAT = "%(asctime)s: %(module)-10s %(levelname)-8s %(message)s"
115
- logging .basicConfig (format = LOG_FORMAT )
116
- logger = logging .getLogger ()
117
-
118
- logger .setLevel (logging .DEBUG )
119
- if args .trace :
120
- logger .setLevel (1 )
121
-
122
- vr = OpenWRT (args .username , args .password )
123
- vr .start ()
134
+ args ()
135
+ # import argparse
136
+ # parser = argparse.ArgumentParser(description='')
137
+ # parser.add_argument('--trace', action='store_true', help='enable trace level logging')
138
+ # parser.add_argument('--username', default='vrnetlab', help='Username')
139
+ # parser.add_argument('--password', default='VR-netlab9', help='Password')
140
+ # parser.add_argument(
141
+ # "--connection-mode",
142
+ # default="vrxcon",
143
+ # help="Connection mode to use in the datapath",
144
+ # )
145
+ # args = parser.parse_args()
146
+
147
+
148
+
149
+
150
+
151
+
152
+
0 commit comments