blob: 44a3301357e40dd31761c5f8a8789e8228007560 [file] [log] [blame]
andrewonlaba548f962014-10-21 19:28:43 -04001#!/usr/bin/env python
2
3'''
4This driver handles the optical switch emulator linc-oe.
5
6Please follow the coding style demonstrated by existing
7functions and document properly.
8
9If you are a contributor to the driver, please
10list your email here for future contact:
11
12 andrew@onlab.us
13
14OCT 20 2014
15'''
16
17import traceback
18import pexpect
19import struct
20import fcntl
21import os
22import signal
23import re
24import sys
25import core.teston
26sys.path.append("../")
27from math import pow
28from drivers.common.cli.emulatordriver import Emulator
29from drivers.common.clidriver import CLI
30
31class LincOEDriver(Emulator):
32 '''
33 LincOEDriver class will handle all emulator functions
34 '''
35 def __init__(self):
36 super(Emulator, self).__init__()
37 self.handle = self
38 self.wrapped = sys.modules[__name__]
39 self.flag = 0
40
41 def connect(self, **connectargs):
42 '''
43 Create ssh handle for Linc-OE cli
44 '''
45 for key in connectargs:
46 vars(self)[key] = connectargs[key]
47
48 self.name = self.options['name']
49 self.handle = \
50 super(LincOEDriver, self).connect(\
51 user_name = self.user_name,
52 ip_address = self.ip_address,
53 port = None,
54 pwd = self.pwd)
55
56 self.ssh_handle = self.handle
57
58 if self.handle :
59 main.log.info(self.name+": Starting Linc-OE CLI")
60 cmdStr = "sudo ./rel/linc/bin/linc console"
61
62 self.handle.sendline(cmdStr)
andrewonlabeb08b6f2014-10-21 21:23:15 -040063 #Sending blank lines "shows" the CLI
64 self.handle.sendline("")
65 self.handle.sendline("")
andrewonlaba548f962014-10-21 19:28:43 -040066 self.handle.expect(["linc@",pexpect.EOF,pexpect.TIMEOUT])
67
68 else:
69 main.log.error(self.name+
70 ": Connection failed to the host "+
71 self.user_name+"@"+self.ip_address)
72 main.log.error(self.name+
73 ": Failed to connect to Linc-OE")
74 return main.FALSE
75
andrewonlabeb08b6f2014-10-21 21:23:15 -040076 def set_interface_up(self, intfs):
77 '''
78 Specify interface to bring up.
79 When Linc-OE is started, tap interfaces should
80 be created. They must be brought up manually
81 '''
82 try:
83 self.handle.sendline("ifconfig "+str(intf)+" up")
84 self.handle.expect("linc@")
85
86 handle = self.handle.before
87
88 return handle
89
90 except pexpect.EOF:
91 main.log.error(self.name+ ": EOF exception")
92 main.log.error(self.name+ ": " + self.handle.before)
93 main.cleanup()
94 main.exit()
95 except:
96 main.log.info(self.name+" :::::::")
97 main.log.error( traceback.print_exc())
98 main.log.info(self.name+" :::::::")
99 main.cleanup()
100 main.exit()
andrewonlaba548f962014-10-21 19:28:43 -0400101
102
103if __name__ != "__main__":
104 import sys
105 sys.modules[__name__] = LincOEDriver()
106