diff options
author | Jing Lu <lvjing5@huawei.com> | 2017-07-12 02:54:02 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-07-12 02:54:02 +0000 |
commit | 0832b64daeeae389db660d87c139e82c1c6593f8 (patch) | |
tree | 43b56208411abf35466dcc6185c2a1d5c7ba4154 /api | |
parent | 7949507437f8b1b1d9100bd13cf2d90bae60279d (diff) | |
parent | e6b3c9dbeb1210af5f0f84b4a582f65d2d31058b (diff) |
Merge "Yardstick api database v2 model"
Diffstat (limited to 'api')
-rw-r--r-- | api/database/v2/__init__.py | 0 | ||||
-rw-r--r-- | api/database/v2/handlers.py | 185 | ||||
-rw-r--r-- | api/database/v2/models.py | 100 |
3 files changed, 285 insertions, 0 deletions
diff --git a/api/database/v2/__init__.py b/api/database/v2/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/api/database/v2/__init__.py diff --git a/api/database/v2/handlers.py b/api/database/v2/handlers.py new file mode 100644 index 000000000..eb732817d --- /dev/null +++ b/api/database/v2/handlers.py @@ -0,0 +1,185 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +from api.database import db_session +from api.database.v2.models import V2Environment +from api.database.v2.models import V2Openrc +from api.database.v2.models import V2Image +from api.database.v2.models import V2Pod +from api.database.v2.models import V2Container +from api.database.v2.models import V2Project +from api.database.v2.models import V2Task + + +class V2EnvironmentHandler(object): + + def insert(self, kwargs): + environment = V2Environment(**kwargs) + db_session.add(environment) + db_session.commit() + return environment + + def get_by_uuid(self, uuid): + environment = V2Environment.query.filter_by(uuid=uuid).first() + if not environment: + raise ValueError + return environment + + def update_attr(self, uuid, attr): + environment = self.get_by_uuid(uuid) + for k, v in attr.items(): + setattr(environment, k, v) + db_session.commit() + + def append_attr(self, uuid, attr): + environment = self.get_by_uuid(uuid) + for k, v in attr.items(): + value = getattr(environment, k) + new = '{},{}'.format(value, v) if value else v + setattr(environment, k, new) + db_session.commit() + + def delete_by_uuid(self, uuid): + environment = self.get_by_uuid(uuid) + db_session.delete(environment) + db_session.commit() + + +class V2OpenrcHandler(object): + + def insert(self, kwargs): + openrc = V2Openrc(**kwargs) + db_session.add(openrc) + db_session.commit() + return openrc + + def get_by_uuid(self, uuid): + openrc = V2Openrc.query.filter_by(uuid=uuid).first() + if not openrc: + raise ValueError + return openrc + + def delete_by_uuid(self, uuid): + openrc = self.get_by_uuid(uuid) + db_session.delete(openrc) + db_session.commit() + + +class V2ImageHandler(object): + + def insert(self, kwargs): + image = V2Image(**kwargs) + db_session.add(image) + db_session.commit() + return image + + def get_by_uuid(self, uuid): + image = V2Image.query.filter_by(uuid=uuid).first() + if not image: + raise ValueError + return image + + +class V2PodHandler(object): + + def insert(self, kwargs): + pod = V2Pod(**kwargs) + db_session.add(pod) + db_session.commit() + return pod + + def get_by_uuid(self, uuid): + pod = V2Pod.query.filter_by(uuid=uuid).first() + if not pod: + raise ValueError + return pod + + def delete_by_uuid(self, uuid): + pod = self.get_by_uuid(uuid) + db_session.delete(pod) + db_session.commit() + + +class V2ContainerHandler(object): + + def insert(self, kwargs): + container = V2Container(**kwargs) + db_session.add(container) + db_session.commit() + return container + + def get_by_uuid(self, uuid): + container = V2Container.query.filter_by(uuid=uuid).first() + if not container: + raise ValueError + return container + + def delete_by_uuid(self, uuid): + container = self.get_by_uuid(uuid) + db_session.delete(container) + db_session.commit() + + +class V2ProjectHandler(object): + + def insert(self, kwargs): + project = V2Project(**kwargs) + db_session.add(project) + db_session.commit() + return project + + def get_by_uuid(self, uuid): + project = V2Project.query.filter_by(uuid=uuid).first() + if not project: + raise ValueError + return project + + def update_attr(self, uuid, attr): + project = self.get_by_uuid(uuid) + for k, v in attr.items(): + setattr(project, k, v) + db_session.commit() + + def append_attr(self, uuid, attr): + project = self.get_by_uuid(uuid) + for k, v in attr.items(): + value = getattr(project, k) + new = '{},{}'.format(value, v) if value else v + setattr(project, k, new) + db_session.commit() + + def delete_by_uuid(self, uuid): + project = self.get_by_uuid(uuid) + db_session.delete(project) + db_session.commit() + + +class V2TaskHandler(object): + + def insert(self, kwargs): + task = V2Task(**kwargs) + db_session.add(task) + db_session.commit() + return task + + def get_by_uuid(self, uuid): + task = V2Task.query.filter_by(uuid=uuid).first() + if not task: + raise ValueError + return task + + def update_attr(self, uuid, attr): + task = self.get_by_uuid(uuid) + for k, v in attr.items(): + setattr(task, k, v) + db_session.commit() + + def delete_by_uuid(self, uuid): + task = self.get_by_uuid(uuid) + db_session.delete(task) + db_session.commit() diff --git a/api/database/v2/models.py b/api/database/v2/models.py new file mode 100644 index 000000000..64d49cc9d --- /dev/null +++ b/api/database/v2/models.py @@ -0,0 +1,100 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +from __future__ import absolute_import +from sqlalchemy import Column +from sqlalchemy import Integer +from sqlalchemy import String +from sqlalchemy import Text +from sqlalchemy import DateTime +from sqlalchemy import Boolean + +from api.database import Base + + +class V2Environment(Base): + __tablename__ = 'v2_environment' + id = Column(Integer, primary_key=True) + uuid = Column(String(30)) + name = Column(String(30)) + description = Column(Text) + openrc_id = Column(String(10)) + image_id = Column(String(30)) + container_id = Column(Text) + pod_id = Column(String(10)) + time = Column(DateTime) + + +class V2Openrc(Base): + __tablename__ = 'V2_openrc' + id = Column(Integer, primary_key=True) + uuid = Column(String(30)) + name = Column(String(30)) + description = Column(Text) + environment_id = Column(String(30)) + content = Column(Text) + time = Column(DateTime) + + +class V2Image(Base): + __tablename__ = 'v2_image' + id = Column(Integer, primary_key=True) + uuid = Column(String(30)) + name = Column(String(30)) + description = Column(Text) + environment_id = Column(String(30)) + size = Column(String(30)) + status = Column(String(30)) + time = Column(DateTime) + + +class V2Container(Base): + __tablename__ = 'v2_container' + id = Column(Integer, primary_key=True) + uuid = Column(String(30)) + name = Column(String(30)) + environment_id = Column(String(30)) + status = Column(Integer) + port = Column(Integer) + time = Column(String(30)) + + +class V2Pod(Base): + __tablename__ = 'v2_pod' + id = Column(Integer, primary_key=True) + uuid = Column(String(30)) + environment_id = Column(String(30)) + content = Column(Text) + time = Column(String(30)) + + +class V2Project(Base): + __tablename__ = 'v2_project' + id = Column(Integer, primary_key=True) + uuid = Column(String(30)) + name = Column(String(30)) + description = Column(Text) + time = Column(DateTime) + tasks = Column(Text) + + +class V2Task(Base): + __tablename__ = 'v2_task' + id = Column(Integer, primary_key=True) + uuid = Column(String(30)) + name = Column(String(30)) + description = Column(Text) + project_id = Column(String(30)) + environment_id = Column(String(30)) + time = Column(DateTime) + case_name = Column(String(30)) + suite = Column(Boolean) + content = Column(Text) + result = Column(Text) + error = Column(Text) + status = Column(Integer) |