Ejemplo n.º 1
0
    def get(self):
        project_handler = V2ProjectHandler()
        projects = [change_obj_to_dict(p) for p in project_handler.list_all()]

        for p in projects:
            tasks = p['tasks']
            p['tasks'] = tasks.split(',') if tasks else []

        return result_handler(consts.API_SUCCESS, {'projects': projects})
Ejemplo n.º 2
0
    def test_change_obj_to_dict(self):
        class A(object):
            def __init__(self):
                self.name = 'yardstick'

        obj = A()
        obj_r = utils.change_obj_to_dict(obj)
        obj_s = {'name': 'yardstick'}
        self.assertEqual(obj_r, obj_s)
Ejemplo n.º 3
0
    def get(self):
        task_handler = V2TaskHandler()
        tasks = [change_obj_to_dict(t) for t in task_handler.list_all()]

        for t in tasks:
            result = t['result']
            t['result'] = jsonutils.loads(result) if result else None

        return result_handler(consts.API_SUCCESS, {'tasks': tasks})
Ejemplo n.º 4
0
    def get(self):
        project_handler = V2ProjectHandler()
        projects = [change_obj_to_dict(p) for p in project_handler.list_all()]

        for p in projects:
            tasks = p['tasks']
            p['tasks'] = tasks.split(',') if tasks else []

        return result_handler(consts.API_SUCCESS, {'projects': projects})
Ejemplo n.º 5
0
    def get(self):
        environment_handler = V2EnvironmentHandler()
        environments = [
            change_obj_to_dict(e) for e in environment_handler.list_all()
        ]

        for e in environments:
            container_info = e['container_id']
            e['container_id'] = jsonutils.loads(
                container_info) if container_info else {}

        data = {'environments': environments}

        return result_handler(consts.API_SUCCESS, data)
Ejemplo n.º 6
0
    def get(self):
        environment_handler = V2EnvironmentHandler()
        environments = [change_obj_to_dict(e) for e in environment_handler.list_all()]

        for e in environments:
            container_info = e['container_id']
            e['container_id'] = jsonutils.loads(container_info) if container_info else {}

            image_id = e['image_id']
            e['image_id'] = image_id.split(',') if image_id else []

        data = {
            'environments': environments
        }

        return result_handler(consts.API_SUCCESS, data)
Ejemplo n.º 7
0
    def get(self, task_id):
        try:
            uuid.UUID(task_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid task id')

        task_handler = V2TaskHandler()
        try:
            task = task_handler.get_by_uuid(task_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'no such task id')

        task_info = change_obj_to_dict(task)
        result = task_info['result']
        task_info['result'] = jsonutils.loads(result) if result else None

        return result_handler(consts.API_SUCCESS, {'task': task_info})
Ejemplo n.º 8
0
    def get(self, project_id):
        try:
            uuid.UUID(project_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid project id')

        project_handler = V2ProjectHandler()
        try:
            project = project_handler.get_by_uuid(project_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'no such project id')

        project_info = change_obj_to_dict(project)
        tasks = project_info['tasks']
        project_info['tasks'] = tasks.split(',') if tasks else []

        return result_handler(consts.API_SUCCESS, {'project': project_info})
Ejemplo n.º 9
0
    def get(self, environment_id):
        try:
            uuid.UUID(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid environment id')

        environment_handler = V2EnvironmentHandler()
        try:
            environment = environment_handler.get_by_uuid(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'no such environment id')

        environment = change_obj_to_dict(environment)
        container_id = environment['container_id']
        environment['container_id'] = jsonutils.loads(
            container_id) if container_id else {}
        return result_handler(consts.API_SUCCESS, {'environment': environment})
Ejemplo n.º 10
0
    def get(self, project_id):
        try:
            uuid.UUID(project_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid project id')

        project_handler = V2ProjectHandler()
        try:
            project = project_handler.get_by_uuid(project_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'no such project id')

        project_info = change_obj_to_dict(project)
        tasks = project_info['tasks']
        project_info['tasks'] = tasks.split(',') if tasks else []

        return result_handler(consts.API_SUCCESS, {'project': project_info})
Ejemplo n.º 11
0
    def get(self):
        try:
            source_env(consts.OPENRC)
        except Exception:
            return result_handler(consts.API_ERROR, 'source openrc error')

        nova_client = get_nova_client()
        try:
            images_list = nova_client.images.list()
        except Exception:
            return result_handler(consts.API_ERROR, 'get images error')
        else:
            images = {
                i.name: self.get_info(change_obj_to_dict(i))
                for i in images_list
            }

        return result_handler(consts.API_SUCCESS, {
            'status': 1,
            'images': images
        })
Ejemplo n.º 12
0
    def get(self, environment_id):
        try:
            uuid.UUID(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid environment id')

        environment_handler = V2EnvironmentHandler()
        try:
            environment = environment_handler.get_by_uuid(environment_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'no such environment id')

        environment = change_obj_to_dict(environment)

        container_id = environment['container_id']
        environment['container_id'] = jsonutils.loads(container_id) if container_id else {}

        image_id = environment['image_id']
        environment['image_id'] = image_id.split(',') if image_id else []

        return result_handler(consts.API_SUCCESS, {'environment': environment})
Ejemplo n.º 13
0
    def get(self):
        try:
            source_env(consts.OPENRC)
        except:
            return result_handler(consts.API_ERROR, 'source openrc error')

        nova_client = get_nova_client()
        try:
            images_list = nova_client.images.list()
        except:
            return result_handler(consts.API_ERROR, 'get images error')
        else:
            images = [
                self.get_info(change_obj_to_dict(i)) for i in images_list
            ]
            status = 1 if all(i['status'] == 'ACTIVE' for i in images) else 0
            if not images:
                status = 0

        return result_handler(consts.API_SUCCESS, {
            'status': status,
            'images': images
        })
Ejemplo n.º 14
0
    def get(self, image_id):
        try:
            uuid.UUID(image_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'invalid image id')

        image_handler = V2ImageHandler()
        try:
            image = image_handler.get_by_uuid(image_id)
        except ValueError:
            return result_handler(consts.API_ERROR, 'no such image id')

        nova_client = get_nova_client()
        images = nova_client.images.list()
        try:
            image = next((i for i in images if i.name == image.name))
        except StopIteration:
            pass

        return_image = self.get_info(change_obj_to_dict(image))
        return_image['id'] = image_id

        return result_handler(consts.API_SUCCESS, {'image': return_image})
Ejemplo n.º 15
0
    def _get_current_host_name(self, server_id):

        return change_obj_to_dict(self.nova_client.servers.get(server_id))['OS-EXT-SRV-ATTR:host']