summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-02-14 18:36:21 +0000
committerGerrit Code Review <review@openstack.org>2013-02-14 18:36:21 +0000
commitdbdd6945d72fdc1719f88c92d961f20eccd5d01d (patch)
treec6893affd9c0661b1f14b764974c3e9d873efd1b /nova/db
parent4ffddcfa6385703ce9a02f624999f05b388778e6 (diff)
parent00aced0ec5ad9520614ba1846d061f9605ace758 (diff)
Merge "Canonizes IPv6 before insert it into the db"
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/sqlalchemy/types.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/nova/db/sqlalchemy/types.py b/nova/db/sqlalchemy/types.py
index 275e61a4c..ef861b832 100644
--- a/nova/db/sqlalchemy/types.py
+++ b/nova/db/sqlalchemy/types.py
@@ -18,9 +18,21 @@
"""Custom SQLAlchemy types."""
from sqlalchemy.dialects import postgresql
-from sqlalchemy import String
+from sqlalchemy import types
+from nova import utils
-def IPAddress():
+
+class IPAddress(types.TypeDecorator):
"""An SQLAlchemy type representing an IP-address."""
- return String(39).with_variant(postgresql.INET(), 'postgresql')
+ impl = types.String(39).with_variant(postgresql.INET(), 'postgresql')
+
+ def process_bind_param(self, value, dialect):
+ """Process/Formats the value before insert it into the db."""
+ if dialect.name == 'postgresql':
+ return value
+ # NOTE(maurosr): The purpose here is to convert ipv6 to the shortened
+ # form, not validate it.
+ elif utils.is_valid_ipv6(value):
+ return utils.get_shortened_ipv6(value)
+ return value