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