Ejemplo n.º 1
0
    def get(self, request, vimid, tenantid):
        try:
            vim_info = extsys.get_vim_by_id(vimid)
        except VimDriverVioException as e:
            return Response(data={'error': str(e)}, status=e.status_code)

        data = {'vimId': vim_info['vimId'],
                'vimName': vim_info['name'],
                'username': vim_info['userName'],
                'password': vim_info['password'],
                'url': vim_info['url'],
                'project_name': vim_info['tenant']}
        query = dict(request.query_params)
        flavors_op = OperateFlavors.OperateFlavors()
        try:
            flavors_result = flavors_op.list_flavors(data, tenantid, **query)
            flavors_dict = [nova_utils.flavor_formatter(flavor, extra)
                            for flavor, extra in flavors_result]
        except Exception as e:
            return Response(data={'error': str(e)},
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        rsp = {'vimId': vim_info['vimId'],
               'vimName': vim_info['name'],
               'tenantId': tenantid,
               'flavors': flavors_dict}

        return Response(data=rsp, status=status.HTTP_200_OK)
Ejemplo n.º 2
0
    def get(self, request, vimid, tenantid, flavorid):
        try:
            vim_info = extsys.get_vim_by_id(vimid)
        except VimDriverVioException as e:
            return Response(data={'error': str(e)}, status=e.status_code)

        data = {
            'vimId': vim_info['vimId'],
            'vimName': vim_info['name'],
            'username': vim_info['userName'],
            'password': vim_info['password'],
            'url': vim_info['url']
        }

        flavors_op = OperateFlavors.OperateFlavors()
        try:
            flavor, extra_specs = flavors_op.get_flavor(
                data, tenantid, flavorid)
            flavor_dict = nova_utils.flavor_formatter(flavor, extra_specs)
        except Exception as e:
            if hasattr(e, "http_status"):
                return Response(data={'error': str(e)}, status=e.http_status)
            else:
                return Response(data={'error': str(e)},
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        rsp = {
            'vimId': vim_info['vimId'],
            'vimName': vim_info['name'],
            'tenantId': tenantid
        }
        rsp.update(flavor_dict)
        return Response(data=rsp, status=status.HTTP_200_OK)
Ejemplo n.º 3
0
    def post(self, request, vimid, tenantid):
        create_req = json.loads(request.body)

        vim_info = extsys.get_vim_by_id(vimid)
        data = {'vimid': vim_info['vimId'],
                'vimName': vim_info['name'],
                'username': vim_info['userName'],
                'password': vim_info['password'],
                'url': vim_info['url'],
                'project_name': vim_info['tenant']}
        rsp = {'vimid': vim_info['vimId'],
               'vimName': vim_info['name'],
               'tenantId': tenantid}
        flavor_name = create_req.get('name', None)
        flavor_id = create_req.get('id', None)
        flavors_op = OperateFlavors.OperateFlavors()
        try:
            target = flavor_id or flavor_name
            flavor = flavors_op.find_flavor(data, tenantid, target)
            if flavor:
                flavor, extra_specs = flavors_op.get_flavor(
                    data, tenantid, flavor.id)
                rsp['returnCode'] = 0
            else:
                rsp['returnCode'] = 1
                flavor, extra_specs = flavors_op.create_flavor(
                    data, tenantid, create_req)
            flavor_dict = nova_utils.flavor_formatter(flavor, extra_specs)
        except Exception as e:
            return Response(data={'error': str(e)},
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
        rsp.update(flavor_dict)
        return Response(data=rsp, status=status.HTTP_200_OK)
Ejemplo n.º 4
0
    def post(self, request, vimid, tenantid):
        try:
            create_req = json.loads(request.body)
        except Exception as e:
            return Response(data={'error': 'Fail to decode request body.'},
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        try:
            vim_info = extsys.get_vim_by_id(vimid)
        except VimDriverVioException as e:
            return Response(data={'error': str(e)}, status=e.status_code)

        data = {
            'vimId': vim_info['vimId'],
            'vimName': vim_info['name'],
            'username': vim_info['userName'],
            'password': vim_info['password'],
            'url': vim_info['url']
        }
        rsp = {
            'vimId': vim_info['vimId'],
            'vimName': vim_info['name'],
            'tenantId': tenantid
        }
        flavor_name = create_req.get('name', None)
        flavor_id = create_req.get('id', None)
        flavors_op = OperateFlavors.OperateFlavors()
        exist = False
        try:
            target = flavor_id or flavor_name
            flavor = flavors_op.find_flavor(data, tenantid, target)
            if flavor:
                flavor, extra_specs = flavors_op.get_flavor(
                    data, tenantid, flavor.id)
                rsp['returnCode'] = 0
                exist = True
            else:
                rsp['returnCode'] = 1
                flavor, extra_specs = flavors_op.create_flavor(
                    data, tenantid, create_req)
            flavor_dict = nova_utils.flavor_formatter(flavor, extra_specs)
        except Exception as e:
            if hasattr(e, "http_status"):
                return Response(data={'error': str(e)}, status=e.http_status)
            else:
                return Response(data={'error': str(e)},
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR)
        rsp.update(flavor_dict)
        if exist:
            return Response(data=rsp, status=status.HTTP_200_OK)
        else:
            return Response(data=rsp, status=status.HTTP_202_ACCEPTED)