Add the new number field in the ports table

Added in several places:
 * database creation code
 * port addition code

Change-Id: Id4e2bd2704d5b9660df8baad34abda0f613ba4f2
diff --git a/db/db.py b/db/db.py
index b5bd631..cc79c07 100644
--- a/db/db.py
+++ b/db/db.py
@@ -78,7 +78,8 @@
     # 1. The switch referred to must already exist
     # 2. The VLANs mentioned here must already exist
     # 3. (Switch/name) must be unique
-    def create_port(self, switch_id, name, current_vlan_id, base_vlan_id):
+    # 4. (Switch/number) must be unique
+    def create_port(self, switch_id, name, number, current_vlan_id, base_vlan_id):
 
         switch = self.get_switch_by_id(switch_id)
         if switch is None:
@@ -93,9 +94,13 @@
         if port_id is not None:
             raise InputError("Already have a port %s on switch ID %d" % (name, int(switch_id)))
 
+        port_id = self.get_port_by_switch_and_number(switch_id, int(number))
+        if port_id is not None:
+            raise InputError("Already have a port %d on switch ID %d" % (int(number), int(switch_id)))
+
         try:
-            sql = "INSERT INTO port (name, switch_id, is_locked, is_trunk, current_vlan_id, base_vlan_id) VALUES (%s, %s, %s, %s, %s, %s) RETURNING port_id"
-            data = (name, switch_id,
+            sql = "INSERT INTO port (name, number, switch_id, is_locked, is_trunk, current_vlan_id, base_vlan_id) VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING port_id"
+            data = (name, number, switch_id,
                     False, False,
                     current_vlan_id, base_vlan_id)
             self.cursor.execute(sql, data)