| #! /usr/bin/python |
| |
| # Copyright 2014 Linaro Limited |
| # |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 2 of the License, or |
| # (at your option) any later version. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| # GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with this program; if not, write to the Free Software |
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| # MA 02110-1301, USA. |
| |
| import time |
| import logging |
| |
| class SwitchDriver(object): |
| |
| connection = None |
| hostname = "" |
| serial_number = '' |
| |
| _allowed_port_modes = [ "trunk", "general" ] |
| _ports = [] |
| _prompt_name = '' |
| _systemdata = [] |
| |
| def _dump_list(self, list): |
| i = 0 |
| for line in list: |
| print "%d: \"%s\"" % (i, line) |
| i += 1 |
| |
| def _delay(self): |
| time.sleep(0.5) |
| |
| # List the capabilities of the switch (and driver) - some things |
| # make no sense to abstract. Returns a dict of strings, each one |
| # describing an extra feature that that higher levels may care |
| # about |
| def SwitchGetCapabilities(self): |
| return self._capabilities |
| |
| # List the names of all the ports on the switch |
| def SwitchGetPortNames(self): |
| return self._ports |
| |
| def _is_port_name_valid(self, name): |
| logging.debug("Checking if supplied port name \"%s\" is valid" % name) |
| for port in self._ports: |
| if name == port: |
| return True |
| return False |
| |
| def _is_port_mode_valid(self, mode): |
| logging.debug("Checking if supplied port mode \"%s\" is valid" % mode) |
| for allowed in self._allowed_port_modes: |
| if allowed == mode: |
| return True |
| return False |
| |