From 2d5e949be68c1776c8e73d2d9d155cda32fcb91d Mon Sep 17 00:00:00 2001 From: David Lenwell Date: Fri, 17 May 2013 00:02:16 +0000 Subject: [PATCH] custom date output and response update Change-Id: I47b685bfd1aeedc4db5672656e13304ff4369185 --- libra/api/controllers/load_balancers.py | 2 ++ libra/api/model/lbaas.py | 23 +++++++++++++++++------ requirements.txt | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/libra/api/controllers/load_balancers.py b/libra/api/controllers/load_balancers.py index 9311b1bc..45ed9caf 100644 --- a/libra/api/controllers/load_balancers.py +++ b/libra/api/controllers/load_balancers.py @@ -145,8 +145,10 @@ class LoadBalancersController(RestController): load_balancers['nodes'].append(node) if load_balancers is None: + response.status = 400 return Responses.not_found else: + response.status = 200 return load_balancers @expose('json') diff --git a/libra/api/model/lbaas.py b/libra/api/model/lbaas.py index f8b37b46..aa17cdb5 100644 --- a/libra/api/model/lbaas.py +++ b/libra/api/model/lbaas.py @@ -12,11 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - from sqlalchemy import Table, Column, Integer, ForeignKey, create_engine -from sqlalchemy import INTEGER, VARCHAR, TIMESTAMP, BIGINT +from sqlalchemy import INTEGER, VARCHAR, BIGINT from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship, backref, sessionmaker +import sqlalchemy.types as types from pecan import conf # TODO replace this with something better @@ -40,12 +40,22 @@ loadbalancers_devices = Table( ) +class FormatedDateTime(types.TypeDecorator): + '''formats date to match iso 8601 standards + ''' + + impl = types.DateTime + + def process_result_value(self, value, dialect): + return value.strftime('%Y-%m-%dT%H:%M:%S') + + class Device(DeclarativeBase): """device model""" __tablename__ = 'devices' #column definitions az = Column(u'az', INTEGER(), nullable=False) - created = Column(u'created', TIMESTAMP(), nullable=False) + created = Column(u'created', FormatedDateTime(), nullable=False) floatingIpAddr = Column( u'floatingIpAddr', VARCHAR(length=128), nullable=False ) @@ -54,7 +64,7 @@ class Device(DeclarativeBase): publicIpAddr = Column(u'publicIpAddr', VARCHAR(length=128), nullable=False) status = Column(u'status', VARCHAR(length=128), nullable=False) type = Column(u'type', VARCHAR(length=128), nullable=False) - updated = Column(u'updated', TIMESTAMP(), nullable=False) + updated = Column(u'updated', FormatedDateTime(), nullable=False) def find_free_device(self): """queries for free and clear device @@ -73,7 +83,6 @@ class LoadBalancer(DeclarativeBase): __tablename__ = 'loadbalancers' #column definitions algorithm = Column(u'algorithm', VARCHAR(length=80), nullable=False) - created = Column(u'created', TIMESTAMP(), nullable=False) errmsg = Column(u'errmsg', VARCHAR(length=128)) id = Column(u'id', BIGINT(), primary_key=True, nullable=False) name = Column(u'name', VARCHAR(length=128), nullable=False) @@ -81,7 +90,8 @@ class LoadBalancer(DeclarativeBase): protocol = Column(u'protocol', VARCHAR(length=128), nullable=False) status = Column(u'status', VARCHAR(length=50), nullable=False) tenantid = Column(u'tenantid', VARCHAR(length=128), nullable=False) - updated = Column(u'updated', TIMESTAMP(), nullable=False) + updated = Column(u'updated', FormatedDateTime(), nullable=False) + created = Column(u'created', FormatedDateTime(), nullable=False) nodes = relationship( 'Node', backref=backref('loadbalancers', order_by='Node.id') ) @@ -105,5 +115,6 @@ class Node(DeclarativeBase): status = Column(u'status', VARCHAR(length=128), nullable=False) weight = Column(u'weight', INTEGER(), nullable=False) + """session""" session = sessionmaker(bind=engine)() diff --git a/requirements.txt b/requirements.txt index 9c7a4e3b..e9b66fec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,5 +7,5 @@ python_swiftclient>=1.3.0 requests>=1.0.0 dogapi pecan -sqlalchemy +sqlalchemy>=0.8.0 MySQL-python