]>
git.proxmox.com Git - ceph.git/blob - ceph/src/brag/server/ceph_brag/controllers/root.py
1 from pecan
import expose
, request
, abort
, response
3 from pecan
.rest
import RestController
4 from ceph_brag
.model
import db
7 class RootController(RestController
):
8 def fail(self
, status_code
=200, msg
="OK"):
9 response
.status
= status_code
13 def get(self
, *args
, **kwargs
):
15 #return the list of uuids
17 result
= db
.get_uuids()
18 except Exception as e
:
19 return self
.fail(500, msg
="Internal Server Error")
20 elif len(args
) == 1 or len(args
) == 2 and args
[1] == '':
23 result
= db
.get_versions(args
[0])
24 except Exception as e
:
25 return self
.fail(status_code
=500, msg
="Internal Server Error")
28 return self
.fail(400, msg
="Invalid UUID")
29 elif len(args
) == 2 or len(args
) == 3 and args
[2] == '':
32 result
= db
.get_brag(args
[0], args
[1])
33 except Exception as e
:
34 return self
.fail(status_code
=500, msg
="Internal Server Error")
37 return self
.fail(status_code
=400, msg
="Invalid UUID,version combination")
39 return self
.fail(status_code
=400, msg
="Invalid args")
43 @expose(content_type
='application/json')
44 def put(self
, *args
, **kwargs
):
46 db
.put_new_version(request
.body
.decode('utf-8'))
47 except ValueError as ve
:
48 return self
.fail(status_code
=422, msg
="Improper payload : " + str(ve
))
49 except KeyError as ke
:
50 msg
= "Payload not as expected, some keys are missing : " + str(ke
)
51 return self
.fail(status_code
=422, msg
=msg
)
52 except Exception as e
:
53 return self
.fail(status_code
=500, msg
="Internal Server Error : " + str(e
))
59 def delete(self
, *args
, **kwargs
):
60 if 'uuid' not in kwargs
:
61 return self
.fail(status_code
=400, msg
="Required uuid parameter")
65 status
= db
.delete_uuid(uuid
)
66 except Exception as e
:
67 return self
.fail(status_code
=500, msg
="Internal Server Error")
69 if status
is not None:
70 return self
.fail(status_code
=status
['status'], msg
=status
['msg'])