Add comments and constraints checking on create_port

Change-Id: I0af0c67a0b771f33d81cc2ebcb026a7c0acc623b
diff --git a/db/db.py b/db/db.py
index 14c36ff..9c172a5 100644
--- a/db/db.py
+++ b/db/db.py
@@ -64,7 +64,21 @@
     # up the correct VLAN_ID for each. This is *NOT* the same as the
     # VLAN tag (likely to be 1).
     # You Have Been Warned!
+    #
+    # Constraints:
+    # 1. The switch referred to must already exist
+    # 2. The VLANs mentioned here must already exist
     def create_port(self, name, switch_id, current_vlan_id, base_vlan_id):
+
+        switch = self.get_switch(switch_id)
+        if switch is None:
+            raise InputError("Switch id %s does not exist" % switch_id)
+
+        for vlan_id in (current_vlan_id, base_vlan_id):
+            vlan = self.get_vlan(vlan_id)
+            if vlan is None:
+                raise InputError("VLAN id %s does not exist" % vlan_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,