aboutsummaryrefslogtreecommitdiff
path: root/db/db.py
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2014-12-05 16:57:13 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2014-12-05 16:57:13 +0000
commita1c7522eb553cfbec2ba5b26edf3c1ea17a66ef9 (patch)
treef54d08392c650693b4fd3e3e5a527a3cadde6998 /db/db.py
parentae95fd65a43c16737e2e2cc2e5b53cd8ab6c1da7 (diff)
Misc consistency updates
All IDs should be ints, so make sure All messages about IDs should describe them as such, in upper case Change-Id: I38619f0807b22b88ceff0cc96d75ed95d5259ab7
Diffstat (limited to 'db/db.py')
-rw-r--r--db/db.py58
1 files changed, 29 insertions, 29 deletions
diff --git a/db/db.py b/db/db.py
index 67f02e3..eb0048b 100644
--- a/db/db.py
+++ b/db/db.py
@@ -74,22 +74,22 @@ class VlanDB:
switch = self.get_switch_by_id(switch_id)
if switch is None:
- raise InputError("Switch id %s does not exist" % switch_id)
+ raise InputError("Switch ID %d does not exist" % int(switch_id))
for vlan_id in (current_vlan_id, base_vlan_id):
vlan = self.get_vlan_by_id(vlan_id)
if vlan is None:
- raise InputError("VLAN id %s does not exist" % vlan_id)
+ raise InputError("VLAN ID %d does not exist" % int(vlan_id))
port_id = self.get_port_by_switch_and_name(switch_id, name)
if port_id is not None:
- raise InputError("Already have a port %s on switch_id %d" % (name, int(switch_id)))
+ raise InputError("Already have a port %s on switch ID %d" % (name, 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, switch_id, is_locked, is_trunk, current_vlan_id, base_vlan_id) VALUES (%s, %d, %s, %s, %d, %d) RETURNING port_id"
+ data = (name, int(switch_id),
False, False,
- current_vlan_id, base_vlan_id)
+ int(current_vlan_id), int(base_vlan_id))
self.cursor.execute(sql, data)
port_id = self.cursor.fetchone()[0]
self.connection.commit()
@@ -117,8 +117,8 @@ class VlanDB:
try:
dt = datetime.datetime.now()
- sql = "INSERT INTO vlan (name, tag, is_base_vlan, creation_time) VALUES (%s, %s, %s, %s) RETURNING vlan_id"
- data = (name, tag, is_base_vlan, dt)
+ sql = "INSERT INTO vlan (name, tag, is_base_vlan, creation_time) VALUES (%s, %d, %s, %s) RETURNING vlan_id"
+ data = (name, int(tag), is_base_vlan, dt)
self.cursor.execute(sql, data)
vlan_id = self.cursor.fetchone()[0]
self.connection.commit()
@@ -147,11 +147,11 @@ class VlanDB:
def delete_switch(self, switch_id):
switch = self.get_switch_by_id(switch_id)
if switch is None:
- raise InputError("Switch ID %s does not exist" % switch_id)
+ raise InputError("Switch ID %d does not exist" % int(switch_id))
ports = self.get_ports_by_switch(switch_id)
if ports is not None:
- raise InputError("Cannot delete switch ID %s when it still has %d ports" %
- (switch_id, len(ports)))
+ raise InputError("Cannot delete switch ID %d when it still has %d ports" %
+ (int(switch_id), len(ports)))
self._delete_row("switch", "switch_id", switch_id)
return switch_id
@@ -163,9 +163,9 @@ class VlanDB:
def delete_port(self, port_id):
port = self.get_port_by_id(port_id)
if port is None:
- raise InputError("Port ID %s does not exist" % port_id)
+ raise InputError("Port ID %d does not exist" % int(port_id))
if port.is_locked:
- raise InputError("Cannot delete port ID %s as it is locked" % port_id)
+ raise InputError("Cannot delete port ID %d as it is locked" % int(port_id))
self._delete_row("port", "port_id", port_id)
return port_id
@@ -177,15 +177,15 @@ class VlanDB:
def delete_vlan(self, vlan_id):
vlan = self.get_vlan_by_id(vlan_id)
if vlan is None:
- raise InputError("VLAN ID %s does not exist" % vlan_id)
+ raise InputError("VLAN ID %d does not exist" % int(vlan_id))
ports = self.get_ports_by_current_vlan(vlan_id)
if ports is not None:
- raise InputError("Cannot delete VLAN ID %s when it still has %d ports" %
- (vlan_id, len(ports)))
+ raise InputError("Cannot delete VLAN ID %d when it still has %d ports" %
+ (int(vlan_id), len(ports)))
ports = self.get_ports_by_base_vlan(vlan_id)
if ports is not None:
- raise InputError("Cannot delete VLAN ID %s when it still has %d ports" %
- (vlan_id, len(ports)))
+ raise InputError("Cannot delete VLAN ID %d when it still has %d ports" %
+ (int(vlan_id), len(ports)))
self._delete_row("vlan", "vlan_id", vlan_id)
return vlan_id
@@ -332,10 +332,10 @@ class VlanDB:
def set_port_is_locked(self, port_id, is_locked):
port = self.get_port_by_id(port_id)
if port is None:
- raise InputError("Port %s does not exist" % port_id)
+ raise InputError("Port ID %d does not exist" % int(port_id))
try:
- sql = "UPDATE port SET is_locked=%s WHERE port_id=%s"
- data = (is_locked, port_id)
+ sql = "UPDATE port SET is_locked=%s WHERE port_id=%d"
+ data = (is_locked, int(port_id))
self.cursor.execute(sql, data)
port_id = self.cursor.fetchone()[0]
self.connection.commit()
@@ -349,7 +349,7 @@ class VlanDB:
def set_port_mode(self, port_id, mode):
port = self.get_port_by_id(port_id)
if port is None:
- raise InputError("Port %s does not exist" % port_id)
+ raise InputError("Port ID %d does not exist" % int(port_id))
if mode == "access":
is_trunk = False
elif mode == "trunk":
@@ -358,7 +358,7 @@ class VlanDB:
raise InputError("Port mode %s is not valid" % mode)
try:
sql = "UPDATE port SET is_trunk=%s WHERE port_id=%d"
- data = (is_trunk, (int)port_id)
+ data = (is_trunk, int(port_id))
self.cursor.execute(sql, data)
port_id = self.cursor.fetchone()[0]
self.connection.commit()
@@ -370,18 +370,18 @@ class VlanDB:
def set_vlan(self, port_id, vlan_id):
port = self.get_port_by_id(port_id)
if port is None:
- raise InputError("Port %s does not exist" % port_id)
+ raise InputError("Port ID %d does not exist" % int(port_id))
if port["is_trunk"] or port["is_locked"]:
raise CriticalError("The port is locked")
vlan = self.get_vlan_by_id(vlan_id)
if vlan is None:
- raise InputError("VLAN %s does not exist" % vlan_id)
+ raise InputError("VLAN ID %d does not exist" % int(vlan_id))
try:
- sql = "UPDATE port SET current_vlan_id=%s WHERE port_id=%s"
- data = (vlan_id, port_id)
+ sql = "UPDATE port SET current_vlan_id=%d WHERE port_id=%d"
+ data = (int(vlan_id), int(port_id))
self.cursor.execute(sql, data)
except:
self.connection.rollback()
@@ -390,14 +390,14 @@ class VlanDB:
def restore_default_vlan(self, port_id):
port = self.get_port_by_id(port_id)
if port is None:
- raise InputError("Port %s does not exist")
+ raise InputError("Port ID %d does not exist" % int(port_id))
if port["is_trunk"] or port["is_locked"]:
raise CriticalError("The port is locked")
try:
sql = "UPDATE port SET current_vlan_id=base_vlan_id WHERE port_id=%d"
- data = port_id
+ data = (int(port_id),)
self.cursor.execute(sql, data)
except:
self.connection.rollback()