1- from utils import Singleton , Download
21from collections import defaultdict
32
3+ from netsim_wrapper .utils import Singleton , Download
4+
5+
46
57class AuthGroup (metaclass = Singleton ):
68 name = __name__
79
8- def local (self ):
9- return """
10+ def add (self , type ):
11+ def local ():
12+ return """
1013<devices xmlns="http://tail-f.com/ns/ncs">
1114 <authgroups>
1215 <group>
@@ -20,8 +23,8 @@ def local(self):
2023</devices>
2124"""
2225
23- def system (self ):
24- return """
26+ def system ():
27+ return """
2528<devices xmlns="http://tail-f.com/ns/ncs">
2629 <authgroups>
2730 <group>
@@ -45,13 +48,15 @@ def system(self):
4548 </authgroups>
4649</devices>
4750"""
48-
51+ if type == 'system' :
52+ return system ()
53+ return local ()
4954
5055class AAA (metaclass = Singleton ):
5156 name = __name__
5257
5358 def add (self , type ):
54- def admin (self ):
59+ def admin ():
5560 return """
5661<config xmlns="http://tail-f.com/ns/config/1.0">
5762 <aaa xmlns="http://tail-f.com/ns/aaa/1.1">
@@ -79,7 +84,7 @@ def admin(self):
7984</config>
8085"""
8186
82- def default (self ):
87+ def default ():
8388 return """
8489<config xmlns="http://tail-f.com/ns/config/1.0">
8590 <aaa xmlns="http://tail-f.com/ns/aaa/1.1">
@@ -176,10 +181,7 @@ def compile_neds(self):
176181
177182 def load_authgroup (self , type , path = None ): # type -> local/system/custom
178183 path = path or '/tmp/authgroup.xml'
179- if type == 'local' :
180- self .utils .xml .dump (self .auth .local , path )
181- if type == 'system' :
182- self .utils .xml .dump (self .auth .system , path )
184+ self .utils .xml .dump (self .auth .add (type ), path )
183185 return path
184186
185187 def load_aaa (self , type ): # type -> add.admin/add.default
@@ -208,20 +210,24 @@ def download_neds(self):
208210 self .default ['neds' ]
209211 )
210212
211- def extract_neds (self , extract_tar = True ):
213+ def extract_neds (self , signed_bin = True , extract_tar = True ):
212214 self .log .debug ("extracting neds" )
213215 # TODO: need to test
214- cmd = ['cd' , self . default [ 'ppath' ], '&&' ]
216+ files = []
215217 for ned in self .default ['neds' ]:
216218 file = ned .split ('/' )[- 1 ]
217219 self .log .debug ('ned: {}' .format (file ))
218220 self .utils .cmd .run (['mv' , file , self .default ['ppath' ]])
219- self .utils .cmd .run (cmd + ['bash' , file ])
220- if not extract_tar :
221- continue
222- tar_file = self .utils .get_tar (file )
223- self .utils .cmd .run (cmd + ['tar' , '-xvf' , tar_file ])
224- self .utils .cmd .run (cmd + ['rm' , '-rf' , tar_file , file ])
221+ files .append (file )
222+
223+ self .utils .change_dir (self .default ['ppath' ])
224+ for ned in files :
225+ if signed_bin :
226+ self .utils .cmd .run (['bash' , ned ])
227+ if extract_tar :
228+ tar_file = self .utils .get_tar (ned )
229+ self .utils .cmd .run (['tar' , '-xvf' , tar_file ])
230+ self .utils .cmd .run (['rm' , '-rf' , tar_file , ned ])
225231 self .log .debug ('extraction done' )
226232
227233 def create_devices (self ):
@@ -277,8 +283,10 @@ def analyse_params(self):
277283
278284 self .log .debug ("analysing template done" )
279285
280- def apply (self ):
286+ def apply (self , username , password ):
281287 self .analyse_params ()
288+ self .default ['username' ] = username
289+ self .default ['password' ] = password
282290
283291 self .log .debug ("per-netsim steps" )
284292 if self .default ['download-neds' ]:
@@ -307,7 +315,7 @@ def pre_create():
307315 self .nwrap .netsim .start ()
308316
309317 if self .default ['add-to-nso' ]:
310- path = 'tmp/devices.xml'
318+ path = '/ tmp/devices.xml'
311319 data = self .nwrap .netsim .ncs_xml_init (sysout = False )
312320 self .utils .xml .dump (data , path )
313321
0 commit comments