Move more common code out into common.py

Refactor existing code some more to make it more common for drivers.

Rename a lot of internal class variables to make it clearer they're
internal.
diff --git a/drivers/cisco-sX300.py b/drivers/cisco-sX300.py
index 5667a09..7f7388c 100644
--- a/drivers/cisco-sX300.py
+++ b/drivers/cisco-sX300.py
@@ -27,15 +27,14 @@
 class CiscoSX300(SwitchDriver):
 
     connection = None
-    prompt_name = ''
-    ports = []
-    systemdata = []
-    serial_number = ''
+
+    # No extra capabilities for this switch/driver yet
+    _capabilities = [
+    ]
+
     # Regexp of expected hardware information - fail if we don't see
     # this
-    expected_descr_re = re.compile('S.300-\d+P')
-
-    allowed_port_modes = [ "trunk", "general" ]
+    _expected_descr_re = re.compile('S.300-\d+P')
 
     logfile = sys.stderr
     logfile = None
@@ -57,8 +56,7 @@
         self.connection.setwinsize(132,1000)
 
         # And grab details about the switch. in case we need it
-        for line in self._get_systemdata():
-            self.systemdata.append (line)
+        self._get_systemdata()
 
         # And also validate them - make sure we're driving a switch of
         # the correct model! Also store the serial number
@@ -66,7 +64,7 @@
         sn_regex = re.compile('SN:\s+(\S_)')
         descr = ""
 
-        for line in self.systemdata:
+        for line in self._systemdata:
             match = descr_regex.match(line)
             if match:
                 descr = match.group(1)
@@ -74,12 +72,12 @@
             if match:
                 self.serial_number = match.group(1)
 
-        if not self.expected_descr_re.match(descr):
+        if not self._expected_descr_re.match(descr):
             raise IOError("Switch %s not recognised by this driver: abort" % descr)
 
         # Now build a list of our ports, for later sanity checking
-        self.ports = self._get_port_names()
-        if len(self.ports) < 4:
+        self._ports = self._get_port_names()
+        if len(self._ports) < 4:
             raise IOError("Not enough ports detected - problem!")
 
     # Log out of the switch and drop the connection and all state
@@ -97,17 +95,6 @@
         self._cli("y")
         self.connection.expect("Copy succeeded")
 
-    # 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 []
-
-    # List the names of all the ports on the switch
-    def SwitchGetPortNames(self):
-        return self.ports
-
     ################################
     ### VLAN API functions
     ################################
@@ -340,7 +327,7 @@
                 logging.error("Login failure: %s\n" % self.connection.match)
                 raise IOError
             elif index == 2:
-                self.prompt_name = self.connection.match.group(1).strip()
+                self._prompt_name = self.connection.match.group(1).strip()
                 return 0
 
     def _logout(self):
@@ -355,7 +342,7 @@
 
     def _read_paged_output(self):
         buf = []
-        prompt = self.prompt_name + '#'
+        prompt = self._prompt_name + '#'
         while True:
             index = self.connection.expect(['\x1b\[0mMore:.*<return>.*$', prompt])
             if index == 0: # More: <space>
@@ -385,20 +372,6 @@
                 interfaces.append(match.group(1))
         return interfaces
 
-    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
-
     def _show_config(self):
         logging.debug("Grabbing config")
         self._cli("show running-config")
@@ -409,25 +382,17 @@
         self._cli("show clock")
         return self._read_paged_output()
 
-    def _show_clock(self):
-        logging.debug("Grabbing ")
-        self._cli("show clock")
-        return self._read_paged_output()
-
     def _get_systemdata(self):
-        data = []
 
         logging.debug("Grabbing system data")
         self._cli("show system")
         for line in self._read_paged_output():
-            data.append(line)
+            self._systemdata.append(line)
 
         logging.debug("Grabbing system sw and hw versions")
         self._cli("show version")
         for line in self._read_paged_output():
-            data.append(line)
-
-        return data
+            self._systemdata.append(line)
 
     ######################################
     # Internal port access helper methods
@@ -492,8 +457,8 @@
     #buf = p._show_config()
     #p._dump_list(buf)
 
-    #print "System data:"
-    #p._dump_list(p.systemdata)
+    print "System data:"
+    p._dump_list(p._systemdata)
 
     print "Creating VLANs for testing:"
     for i in [ 2, 3, 4, 5, 20 ]:
@@ -552,6 +517,7 @@
     buf = p.PortGetTrunkVlanList("gi2")
     p._dump_list(buf)
 
+    print "Remove gi2 from VLANs 3,3,4"
     p.PortRemoveTrunkFromVlan("gi2", 3)
     p.PortRemoveTrunkFromVlan("gi2", 3)
     p.PortRemoveTrunkFromVlan("gi2", 4)