You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
| 2 | This file contains intent class for CHOTestMonkey |
| 3 | Author: you@onlab.us |
| 4 | """ |
| 5 | from threading import Lock |
| 6 | |
| 7 | class Controller: |
| 8 | def __init__( self, index ): |
| 9 | self.default = '' |
| 10 | self.index = index |
| 11 | self.ip = main.onosIPs[ index - 1 ] |
| 12 | self.CLI = None |
| 13 | self.CLILock = Lock() |
| 14 | self.status = 'up' |
| 15 | |
| 16 | def setCLI( self, CLI ): |
| 17 | self.CLI = CLI |
| 18 | |
| 19 | def startCLI( self ): |
| 20 | return self.CLI.startOnosCli( self.ip ) |
| 21 | |
| 22 | def isUp( self ): |
| 23 | return self.status == 'up' |
| 24 | |
| 25 | def bringDown( self ): |
| 26 | self.status = 'down' |
| 27 | |
| 28 | def bringUp( self ): |
| 29 | self.status = 'up' |
| 30 | |
| 31 | class Intent: |
| 32 | def __init__( self, id ): |
| 33 | self.default = '' |
| 34 | self.type = 'INTENT' |
| 35 | self.id = id |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 36 | self.expectedState = 'INSTALLED' |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 37 | |
| 38 | def isHostIntent( self ): |
| 39 | return self.type == 'INTENT_HOST' |
| 40 | |
| 41 | def isPointIntent( self ): |
| 42 | return self.type == 'INTENT_POINT' |
| 43 | |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 44 | def isFailed( self ): |
| 45 | return self.expectedState == 'FAILED' |
| 46 | |
| 47 | def isInstalled( self ): |
| 48 | return self.expectedState == 'INSTALLED' |
| 49 | |
| 50 | def setFailed( self ): |
| 51 | self.expectedState = 'FAILED' |
| 52 | |
| 53 | def setInstalled( self ): |
| 54 | self.expectedState = 'INSTALLED' |
| 55 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 56 | class HostIntent( Intent ): |
| 57 | def __init__( self, id, hostA, hostB ): |
| 58 | Intent.__init__( self, id ) |
| 59 | self.type = 'INTENT_HOST' |
| 60 | self.hostA = hostA |
| 61 | self.hostB = hostB |
You Wang | 2b687c0 | 2016-05-13 17:01:31 -0700 | [diff] [blame] | 62 | self.deviceA = hostA.device |
| 63 | self.deviceB = hostB.device |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 64 | |
| 65 | def __str__( self ): |
| 66 | return "ID: " + self.id |
| 67 | |
| 68 | class PointIntent( Intent ): |
| 69 | def __init__( self, id, deviceA, deviceB ): |
| 70 | Intent.__init__( self, id ) |
| 71 | self.type = 'INTENT_POINT' |
| 72 | self.deviceA = deviceA |
| 73 | self.deviceB = deviceB |
| 74 | |
| 75 | def __str__( self ): |
| 76 | return "ID: " + self.id |