andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | ''' |
| 4 | This driver handles the optical switch emulator linc-oe. |
| 5 | |
| 6 | Please follow the coding style demonstrated by existing |
| 7 | functions and document properly. |
| 8 | |
| 9 | If you are a contributor to the driver, please |
| 10 | list your email here for future contact: |
| 11 | |
| 12 | andrew@onlab.us |
| 13 | |
| 14 | OCT 20 2014 |
| 15 | ''' |
| 16 | |
| 17 | import traceback |
| 18 | import pexpect |
| 19 | import struct |
| 20 | import fcntl |
| 21 | import os |
| 22 | import signal |
| 23 | import re |
| 24 | import sys |
| 25 | import core.teston |
| 26 | sys.path.append("../") |
| 27 | from math import pow |
| 28 | from drivers.common.cli.emulatordriver import Emulator |
| 29 | from drivers.common.clidriver import CLI |
| 30 | |
| 31 | class 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) |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 63 | #Sending blank lines "shows" the CLI |
| 64 | self.handle.sendline("") |
| 65 | self.handle.sendline("") |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 66 | 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 | |
andrewonlab | eb08b6f | 2014-10-21 21:23:15 -0400 | [diff] [blame] | 76 | 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() |
andrewonlab | a548f96 | 2014-10-21 19:28:43 -0400 | [diff] [blame] | 101 | |
| 102 | |
| 103 | if __name__ != "__main__": |
| 104 | import sys |
| 105 | sys.modules[__name__] = LincOEDriver() |
| 106 | |