1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from api.database import db_session
10 from api.database.v2.models import V2Environment
11 from api.database.v2.models import V2Openrc
12 from api.database.v2.models import V2Image
13 from api.database.v2.models import V2Pod
14 from api.database.v2.models import V2Container
15 from api.database.v2.models import V2Project
16 from api.database.v2.models import V2Task
19 class V2EnvironmentHandler(object):
21 def insert(self, kwargs):
22 environment = V2Environment(**kwargs)
23 db_session.add(environment)
28 return V2Environment.query.all()
30 def get_by_uuid(self, uuid):
31 environment = V2Environment.query.filter_by(uuid=uuid).first()
36 def update_attr(self, uuid, attr):
37 environment = self.get_by_uuid(uuid)
38 for k, v in attr.items():
39 setattr(environment, k, v)
42 def append_attr(self, uuid, attr):
43 environment = self.get_by_uuid(uuid)
44 for k, v in attr.items():
45 value = getattr(environment, k)
46 new = '{},{}'.format(value, v) if value else v
47 setattr(environment, k, new)
50 def delete_by_uuid(self, uuid):
51 environment = self.get_by_uuid(uuid)
52 db_session.delete(environment)
56 class V2OpenrcHandler(object):
58 def insert(self, kwargs):
59 openrc = V2Openrc(**kwargs)
60 db_session.add(openrc)
64 def get_by_uuid(self, uuid):
65 openrc = V2Openrc.query.filter_by(uuid=uuid).first()
70 def delete_by_uuid(self, uuid):
71 openrc = self.get_by_uuid(uuid)
72 db_session.delete(openrc)
76 class V2ImageHandler(object):
78 def insert(self, kwargs):
79 image = V2Image(**kwargs)
84 def get_by_uuid(self, uuid):
85 image = V2Image.query.filter_by(uuid=uuid).first()
91 class V2PodHandler(object):
93 def insert(self, kwargs):
99 def get_by_uuid(self, uuid):
100 pod = V2Pod.query.filter_by(uuid=uuid).first()
105 def delete_by_uuid(self, uuid):
106 pod = self.get_by_uuid(uuid)
107 db_session.delete(pod)
111 class V2ContainerHandler(object):
113 def insert(self, kwargs):
114 container = V2Container(**kwargs)
115 db_session.add(container)
119 def get_by_uuid(self, uuid):
120 container = V2Container.query.filter_by(uuid=uuid).first()
125 def delete_by_uuid(self, uuid):
126 container = self.get_by_uuid(uuid)
127 db_session.delete(container)
131 class V2ProjectHandler(object):
133 def insert(self, kwargs):
134 project = V2Project(**kwargs)
135 db_session.add(project)
139 def get_by_uuid(self, uuid):
140 project = V2Project.query.filter_by(uuid=uuid).first()
145 def update_attr(self, uuid, attr):
146 project = self.get_by_uuid(uuid)
147 for k, v in attr.items():
148 setattr(project, k, v)
151 def append_attr(self, uuid, attr):
152 project = self.get_by_uuid(uuid)
153 for k, v in attr.items():
154 value = getattr(project, k)
155 new = '{},{}'.format(value, v) if value else v
156 setattr(project, k, new)
159 def delete_by_uuid(self, uuid):
160 project = self.get_by_uuid(uuid)
161 db_session.delete(project)
165 class V2TaskHandler(object):
167 def insert(self, kwargs):
168 task = V2Task(**kwargs)
173 def get_by_uuid(self, uuid):
174 task = V2Task.query.filter_by(uuid=uuid).first()
179 def update_attr(self, uuid, attr):
180 task = self.get_by_uuid(uuid)
181 for k, v in attr.items():
185 def delete_by_uuid(self, uuid):
186 task = self.get_by_uuid(uuid)
187 db_session.delete(task)