blob: b34cdde7483e4a954f2ea15606c260cb24c5b56c [file] [log] [blame]
Steve McIntyre30bf4db2014-08-12 18:08:22 +01001#! /usr/bin/python
2
3# Copyright 2014 Linaro Limited
Steve McIntyre6103e982014-09-18 23:37:54 +01004
Steve McIntyre30bf4db2014-08-12 18:08:22 +01005#
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
21import time
22import logging
23
24class SwitchDriver(object):
Steve McIntyre366046f2014-08-18 18:57:03 +010025
Steve McIntyre30bf4db2014-08-12 18:08:22 +010026 connection = None
27 hostname = ""
Steve McIntyre366046f2014-08-18 18:57:03 +010028 serial_number = ''
29
30 _allowed_port_modes = [ "trunk", "general" ]
31 _ports = []
32 _prompt_name = ''
33 _systemdata = []
Steve McIntyre30bf4db2014-08-12 18:08:22 +010034
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 McIntyre366046f2014-08-18 18:57:03 +010044 # 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