Revert "Added Error Response"
This reverts commit 830176bbc7d0517d04002b71704f65da0c03fc1f. Change-Id: Id936d677251083a21e3a64f6a2d004870b41cda6
This commit is contained in:
parent
830176bbc7
commit
27f72aa38e
@ -27,32 +27,15 @@ from valence.api.v1.storages import StoragesList as v1StoragesList
|
|||||||
from valence.api.v1.systems import Systems as v1Systems
|
from valence.api.v1.systems import Systems as v1Systems
|
||||||
from valence.api.v1.systems import SystemsList as v1SystemsList
|
from valence.api.v1.systems import SystemsList as v1SystemsList
|
||||||
from valence.api.v1.version import V1
|
from valence.api.v1.version import V1
|
||||||
from valence.common import exception
|
|
||||||
|
|
||||||
app = flaskapp.get_app()
|
app = flaskapp.get_app()
|
||||||
cors = CORS(app)
|
cors = CORS(app)
|
||||||
|
api = Api(app)
|
||||||
|
|
||||||
class ValenceService(Api):
|
|
||||||
"""Overriding Flask Restful Error handler"""
|
|
||||||
|
|
||||||
def handle_error(self, error):
|
|
||||||
|
|
||||||
if issubclass(error.__class__, exception.ValenceError):
|
|
||||||
return self.make_response(error.as_dict(), error.status)
|
|
||||||
elif hasattr(error, 'status'):
|
|
||||||
return self.make_response(exception.httpexception(error),
|
|
||||||
error.code)
|
|
||||||
else:
|
|
||||||
return self.make_response(exception.generalexception(error, 500),
|
|
||||||
500)
|
|
||||||
|
|
||||||
api = ValenceService(app)
|
|
||||||
|
|
||||||
|
|
||||||
"""API V1.0 Operations"""
|
"""API V1.0 Operations"""
|
||||||
|
|
||||||
# Root Operations
|
|
||||||
|
# API Root operation
|
||||||
api.add_resource(Root, '/', endpoint='root')
|
api.add_resource(Root, '/', endpoint='root')
|
||||||
|
|
||||||
# V1 Root operations
|
# V1 Root operations
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
# Copyright (c) 2016 Intel, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
|
|
||||||
from valence.api import base
|
|
||||||
from valence.api import types
|
|
||||||
|
|
||||||
|
|
||||||
class ValenceError(Exception, base.APIBase):
|
|
||||||
"""Valence Error representation.
|
|
||||||
|
|
||||||
As per openstack Error Schema
|
|
||||||
http://specs.openstack.org/openstack/api-wg/guidelines/errors.html
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
fields = {
|
|
||||||
'request_id': {
|
|
||||||
'validate': types.Text.validate
|
|
||||||
},
|
|
||||||
'code': {
|
|
||||||
'validate': types.Text.validate
|
|
||||||
},
|
|
||||||
'status': {
|
|
||||||
'validate': types.Integer.validate
|
|
||||||
},
|
|
||||||
'title': {
|
|
||||||
'validate': types.Text.validate
|
|
||||||
},
|
|
||||||
'detail': {
|
|
||||||
'validate': types.Text.validate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ValenceConfirmation(base.APIBase):
|
|
||||||
"""Valence Confirmation Message representation.
|
|
||||||
|
|
||||||
Whenever confirmation response needs to send back to client
|
|
||||||
for successfull operation
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
fields = {
|
|
||||||
'request_id': {
|
|
||||||
'validate': types.Text.validate
|
|
||||||
},
|
|
||||||
'code': {
|
|
||||||
'validate': types.Text.validate
|
|
||||||
},
|
|
||||||
'detail': {
|
|
||||||
'validate': types.Text.validate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RedfishException(ValenceError):
|
|
||||||
|
|
||||||
def __init__(self, responsejson, status_code=400):
|
|
||||||
Exception.__init__(self)
|
|
||||||
data = responsejson['error']
|
|
||||||
self.request_id = "00000000-0000-0000-0000-000000000000"
|
|
||||||
self.code = data['code']
|
|
||||||
self.status = status_code
|
|
||||||
self.title = data['message']
|
|
||||||
message_detail = " ".join(
|
|
||||||
[i['Message']
|
|
||||||
for i in data['@Message.ExtendedInfo']])
|
|
||||||
self.detail = message_detail
|
|
||||||
|
|
||||||
|
|
||||||
class NotFound(Exception):
|
|
||||||
status = 404
|
|
||||||
|
|
||||||
|
|
||||||
def error(requestid, error_code, http_status,
|
|
||||||
error_title, error_detail):
|
|
||||||
# responseobj - the response object of Requests framework
|
|
||||||
err_obj = ValenceError()
|
|
||||||
err_obj.request_id = requestid
|
|
||||||
err_obj.code = error_code
|
|
||||||
err_obj.status = http_status
|
|
||||||
err_obj.title = error_title
|
|
||||||
err_obj.detail = error_detail
|
|
||||||
return err_obj.as_dict()
|
|
||||||
|
|
||||||
|
|
||||||
def httpexception(e):
|
|
||||||
return error("", type(e).__name__, e.code, type(e).__name__, str(e))
|
|
||||||
|
|
||||||
|
|
||||||
def generalexception(e, errorcode):
|
|
||||||
return error("", type(e).__name__, errorcode, type(e).__name__, str(e))
|
|
||||||
|
|
||||||
|
|
||||||
def confirmation(requestid, confirm_code, confirm_detail):
|
|
||||||
# responseobj - the response object of Requests framework
|
|
||||||
confirm_obj = ValenceConfirmation()
|
|
||||||
confirm_obj.request_id = requestid
|
|
||||||
confirm_obj.code = confirm_code
|
|
||||||
confirm_obj.detail = confirm_detail
|
|
||||||
return confirm_obj.as_dict()
|
|
@ -20,7 +20,6 @@ import os
|
|||||||
import requests
|
import requests
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
|
|
||||||
from valence.common import exception
|
|
||||||
from valence.common import utils
|
from valence.common import utils
|
||||||
from valence import config as cfg
|
from valence import config as cfg
|
||||||
from valence.redfish import tree
|
from valence.redfish import tree
|
||||||
@ -257,10 +256,7 @@ def get_systembyid(systemid):
|
|||||||
|
|
||||||
|
|
||||||
def get_nodebyid(nodeid):
|
def get_nodebyid(nodeid):
|
||||||
node = nodes_list({"Id": nodeid})
|
return nodes_list({"Id": nodeid})
|
||||||
if not node:
|
|
||||||
raise exception.NotFound()
|
|
||||||
return node[0]
|
|
||||||
|
|
||||||
|
|
||||||
def build_hierarchy_tree():
|
def build_hierarchy_tree():
|
||||||
@ -286,24 +282,21 @@ def compose_node(data):
|
|||||||
compose_url = nodes_url + "/Actions/Allocate"
|
compose_url = nodes_url + "/Actions/Allocate"
|
||||||
headers = {'Content-type': 'application/json'}
|
headers = {'Content-type': 'application/json'}
|
||||||
criteria = data["criteria"]
|
criteria = data["criteria"]
|
||||||
resp = send_request(compose_url, "POST", json=criteria, headers=headers)
|
if not criteria:
|
||||||
if resp.status_code == 201:
|
resp = send_request(compose_url, "POST", headers=headers)
|
||||||
composednode = resp.headers['Location']
|
|
||||||
return {"node": composednode}
|
|
||||||
else:
|
else:
|
||||||
raise exception.RedfishException(resp.json(),
|
resp = send_request(compose_url, "POST", json=criteria,
|
||||||
status_code=resp.status_code)
|
headers=headers)
|
||||||
|
|
||||||
|
composed_node = resp.headers['Location']
|
||||||
|
return {"node": composed_node}
|
||||||
|
|
||||||
|
|
||||||
def delete_composednode(nodeid):
|
def delete_composednode(nodeid):
|
||||||
nodes_url = get_base_resource_url("Nodes")
|
nodes_url = get_base_resource_url("Nodes")
|
||||||
delete_url = nodes_url + str(nodeid)
|
delete_url = nodes_url + str(nodeid)
|
||||||
resp = send_request(delete_url, "DELETE")
|
resp = send_request(delete_url, "DELETE")
|
||||||
if resp.status_code == 204:
|
return resp
|
||||||
return exception.confirmation("", "DELETED"), resp.status_code
|
|
||||||
else:
|
|
||||||
raise exception.RedfishException(resp.json(),
|
|
||||||
status_code=resp.status_code)
|
|
||||||
|
|
||||||
|
|
||||||
def nodes_list(filters={}):
|
def nodes_list(filters={}):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user