Steve McIntyre | 30bf4db | 2014-08-12 18:08:22 +0100 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | |
| 3 | # Copyright 2014 Linaro Limited |
Steve McIntyre | 6103e98 | 2014-09-18 23:37:54 +0100 | [diff] [blame^] | 4 | |
Steve McIntyre | 30bf4db | 2014-08-12 18:08:22 +0100 | [diff] [blame] | 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 2 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 | # MA 02110-1301, USA. |
| 20 | |
| 21 | import time |
| 22 | import logging |
| 23 | |
| 24 | class SwitchDriver(object): |
Steve McIntyre | 366046f | 2014-08-18 18:57:03 +0100 | [diff] [blame] | 25 | |
Steve McIntyre | 30bf4db | 2014-08-12 18:08:22 +0100 | [diff] [blame] | 26 | connection = None |
| 27 | hostname = "" |
Steve McIntyre | 366046f | 2014-08-18 18:57:03 +0100 | [diff] [blame] | 28 | serial_number = '' |
| 29 | |
| 30 | _allowed_port_modes = [ "trunk", "general" ] |
| 31 | _ports = [] |
| 32 | _prompt_name = '' |
| 33 | _systemdata = [] |
Steve McIntyre | 30bf4db | 2014-08-12 18:08:22 +0100 | [diff] [blame] | 34 | |
| 35 | def _dump_list(self, list): |
| 36 | i = 0 |
| 37 | for line in list: |
| 38 | print "%d: \"%s\"" % (i, line) |
| 39 | i += 1 |
| 40 | |
| 41 | def _delay(self): |
| 42 | time.sleep(0.5) |
| 43 | |
Steve McIntyre | 366046f | 2014-08-18 18:57:03 +0100 | [diff] [blame] | 44 | # List the capabilities of the switch (and driver) - some things |
| 45 | # make no sense to abstract. Returns a dict of strings, each one |
| 46 | # describing an extra feature that that higher levels may care |
| 47 | # about |
| 48 | def SwitchGetCapabilities(self): |
| 49 | return self._capabilities |
| 50 | |
| 51 | # List the names of all the ports on the switch |
| 52 | def SwitchGetPortNames(self): |
| 53 | return self._ports |
| 54 | |
| 55 | def _is_port_name_valid(self, name): |
| 56 | logging.debug("Checking if supplied port name \"%s\" is valid" % name) |
| 57 | for port in self._ports: |
| 58 | if name == port: |
| 59 | return True |
| 60 | return False |
| 61 | |
| 62 | def _is_port_mode_valid(self, mode): |
| 63 | logging.debug("Checking if supplied port mode \"%s\" is valid" % mode) |
| 64 | for allowed in self._allowed_port_modes: |
| 65 | if allowed == mode: |
| 66 | return True |
| 67 | return False |
| 68 | |