def index(self, request): """ List all repos by `project_id`. This method returns a dictionary list and each dict contains the following keys: - id - repo_path - created If no repos was found, a empty list will be returned. """ repos = [] project_id = request.GET.get('project_id') project = self.db.get_project(project_id) if not project: LOG.error("no such project %s" % project_id) return webob.exc.HTTPNotFound() for item in project.repos: repo = { 'id': item.id, 'repo_path': item.repo_path, 'created': isotime(item.created), } repos.append(repo) return ResponseObject(repos)
def index(self, request): """ List all users according to `project_id`. This method returns a dictionary list and each dict contains the following keys: - id the unique 64 bytes uuid - name the user name - email user's email address - role_id user's role_id - created when user be added If no use found, empty list will be returned. """ users = [] project_id = request.GET.get("project_id") project = self.db.get_project(project_id) for item in project.users: user = { "id": item.id, "name": item.name, "email": item.email, "role_id": item.role_id, "created": isotime(item.created), } users.append(user) return ResponseObject(users)
def index(self, request): """ List all users according to `project_id`. This method returns a dictionary list and each dict contains the following keys: - id the unique 64 bytes uuid - name the user name - email user's email address - role_id user's role_id - created when user be added If no use found, empty list will be returned. """ users = [] project_id = request.GET.get('project_id') project = self.db.get_project(project_id) for item in project.users: user = { 'id': item.id, 'name': item.name, 'email': item.email, 'role_id': item.role_id, 'created': isotime(item.created), } users.append(user) return ResponseObject(users)
def show(self, request, id): """ Show the use detail according to user `id`. :params id: the user id This method returns a dictionary with the following keys: - id unique 64 bytes uuid - name user's name - email user's email address - role_id user's role_id, which identified the current user as super-user or normal-user. - projects the project lists the user belong to - created when the user be added If no user found, empty dictionary will be returned. """ query = self.db.get_user(id) if query is None: LOG.error("no such user %s" % id) return ResponseObject({"projects": []}) projects_list = [] project_instances = query.projects for project in project_instances: project = { "id": project.id, "name": project.name, "desc": project.desc, "created": isotime(project.created), } projects_list.append(project) user = { "id": query.id, "name": query.name, "email": query.email, "role_id": query.role_id, "projects": projects_list, "created": isotime(query.created), } return ResponseObject(user)
def show(self, request, id): """ Show the use detail according to user `id`. :params id: the user id This method returns a dictionary with the following keys: - id unique 64 bytes uuid - name user's name - email user's email address - role_id user's role_id, which identified the current user as super-user or normal-user. - projects the project lists the user belong to - created when the user be added If no user found, empty dictionary will be returned. """ query = self.db.get_user(id) if query is None: LOG.error("no such user %s" % id) return ResponseObject({'projects': []}) projects_list = [] project_instances = query.projects for project in project_instances: project = { "id": project.id, "name": project.name, "desc": project.desc, "created": isotime(project.created) } projects_list.append(project) user = { 'id': query.id, 'name': query.name, 'email': query.email, 'role_id': query.role_id, 'projects': projects_list, 'created': isotime(query.created) } return ResponseObject(user)
def index(): images = [] query = self.db.get_images(project_id=None) for item in query: image = { 'id': item.id, 'uuid': item.uuid, 'name': item.name, 'tag': item.tag, 'desc': item.desc, 'project_id': item.project_id, 'created': isotime(item.created), 'user_id': item.user_id, 'status': item.status } images.append(image)
def index(self, request): """ List all containers on all container nodes according to `project_id` and `user_id`. This method returns a dictionary list and each dict contains the following keys: - id - name - repos - branch - image - network - created - status If no container found, empty list will be returned. """ containers = [] project_id = request.GET.get('project_id') user_id = request.GET.get('user_id') query = self.db.get_containers(project_id, user_id) for item in query: container = { 'id': item.id, 'name': item.name, 'repos': item.repos, 'branch': item.branch, 'image_id': item.image_id, 'network': item.fixed_ip, 'created': timeutils.isotime(item.created), 'status': item.status, } container.setdefault("image", "") """Get the image name and tag by the `image_id`. if the image not found, use the default.""" image_id = item.image_id image_instance = self.db.get_image(image_id) if image_instance: image = "%s:%s" % (image_instance.name, image_instance.tag) container.update({"image": image}) containers.append(container) return ResponseObject(containers)
def show(self, request, id): """ Show the container info according by container's id `id`. This method returns a dictionary with following keys: - id - name - uuid - env - project_id - repos - branch - image_id - network - created - user_id - host_id - status If no container found, empty dictionary will returned. """ container = {} query = self.db.get_container(id) if query is not None: container = { 'id': query.id, 'name': query.name, 'uuid': query.uuid, 'env': query.env, 'project_id': query.project_id, 'repos': query.repos, 'branch': query.branch, 'image_id': query.image_id, 'network': query.fixed_ip, 'created': timeutils.isotime(query.created), 'user_id': query.user_id, 'host_id': query.host_id, 'status': query.status, } return ResponseObject(container)
def index(self, request): """ List all images accorind to `project_id`. This method returns a dictionary list and each dict contains the following keys: - id - uuid - name - tag - desc - project_id - created - user_id - status If no images found, empty list will be returned. """ images = [] project_id = request.GET.get('project_id') if not project_id: LOG.error("project_id cannot be None") return webob.exc.HTTPNotFound() project_instance = self.db.get_project(project_id) if project_instance is None: LOG.error("no such project %s" % project_id) return webob.exc.HTTPNotFound() for image_instance in project_instance.images: image = { 'id': image_instance.id, 'uuid': image_instance.uuid, 'name': image_instance.name, 'tag': image_instance.tag, 'desc': image_instance.desc, 'project_id': image_instance.project_id, 'created': isotime(image_instance.created), 'user_id': image_instance.user_id, 'status': image_instance.status } images.append(image) return ResponseObject(images)
def show(self, request, id): """ Show the repo detail according repo `id`. This method returns a dictionary with following keys: - id - repo_path - project_id - created If no repos was found, a empty dictionary will be returned. """ query = self.db.get_repo(id) if query is None: return {} repo = { 'id': query.id, 'repo_path': query.repo_path, 'project_id': query.project_id, 'created': isotime(query.created) } return ResponseObject(repo)
def index(self, request): """ List all projects. This method returns a dictionary list and each dict containers the following keys: - id - name - desc - created If no projects found, empty list will be returned. """ projects = [] project_instances = self.db.get_projects() if project_instances: for instance in project_instances: project = { 'id': instance.id, 'name': instance.name, 'desc': instance.desc, 'created': isotime(instance.created) } projects.append(project) return ResponseObject(projects)
def show(self, request, id): """ Show the image detail according to `id`. :parmas id: the image id This method returns a dictionary with the following keys: - id - uuid - name - repos - tag - desc - project_id - created - user_id - status If no image found, empty dictionary will be returned. """ image = {} query = self.db.get_image(id) if query is not None: image = { 'id': query.id, 'uuid': query.uuid, 'name': query.name, 'repos': query.repos, 'tag': query.tag, 'desc': query.desc, 'project_id': query.project_id, 'created': isotime(query.created), 'user_id': query.user_id, 'status': query.status } return ResponseObject(image)
def show(self, request, id): """ Show project detail according to project `id`. This method returns a dictionary with following keys: - id - name - desc - created - users - repos - images - containers If no project found, empty dictionary will be returned. """ project_instance = self.db.get_project(id) if project_instance is None: return {} """get project user list.""" user_list = [] for user_instance in project_instance.users: user = { "id": user_instance.id, "name": user_instance.name, "email": user_instance.email, "role_id": user_instance.role_id, "created": isotime(user_instance.created) } user_list.append(user) """"get project repo list.""" repo_list = [] for repo_instance in project_instance.repos: repo = { "id": repo_instance.id, "repo_path": repo_instance.repo_path, "created": isotime(repo_instance.created) } repo_list.append(repo) """"get project image list.""" image_list = [] for image_instance in project_instance.images: image = { 'id': image_instance.id, 'uuid': image_instance.uuid, 'name': image_instance.name, 'tag': image_instance.tag, 'desc': image_instance.desc, 'project_id': image_instance.project_id, 'created': isotime(image_instance.created), 'user_id': image_instance.user_id, 'status': image_instance.status } image_list.append(image) """Get containes list""" container_list = [] for item in project_instance.containers: container = { 'id': item.id, 'name': item.name, 'uuid': item.uuid, 'env': item.env, 'project_id': item.project_id, 'repos': item.repos, 'branch': item.branch, 'image_id': item.image_id, 'network': item.network, 'created': item.created, 'user_id': item.user_id, 'host_id': item.host_id, 'status': item.status } container_list.append(container) project = { "id": project_instance.id, "name": project_instance.name, "desc": project_instance.desc, "created": isotime(project_instance.created), "users": user_list, "repos": repo_list, "images": image_list, "containers": container_list } return ResponseObject(project)