1 from pecan import expose, request, response
2 from pecan.rest import RestController
4 from restful import common, module
5 from restful.decorators import auth
8 class PoolId(RestController):
9 def __init__(self, pool_id):
10 self.pool_id = pool_id
13 @expose(template='json')
15 def get(self, **kwargs):
17 Show the information for the pool id
19 pool = module.instance.get_pool_by_id(self.pool_id)
23 return {'message': 'Failed to identify the pool id "%d"' % self.pool_id}
25 # pgp_num is called pg_placement_num, deal with that
26 if 'pg_placement_num' in pool:
27 pool['pgp_num'] = pool.pop('pg_placement_num')
31 @expose(template='json')
33 def patch(self, **kwargs):
35 Modify the information for the pool id
41 return {'message': 'Bad request: malformed JSON or wrong Content-Type'}
43 # Get the pool info for its name
44 pool = module.instance.get_pool_by_id(self.pool_id)
47 return {'message': 'Failed to identify the pool id "%d"' % self.pool_id}
49 # Check for invalid pool args
50 invalid = common.invalid_pool_args(args)
53 return {'message': 'Invalid arguments found: "%s"' % str(invalid)}
55 # Schedule the update request
56 return module.instance.submit_request(common.pool_update_commands(pool['pool_name'], args), **kwargs)
59 @expose(template='json')
61 def delete(self, **kwargs):
63 Remove the pool data for the pool id
65 pool = module.instance.get_pool_by_id(self.pool_id)
69 return {'message': 'Failed to identify the pool id "%d"' % self.pool_id}
71 return module.instance.submit_request([[{
72 'prefix': 'osd pool delete',
73 'pool': pool['pool_name'],
74 'pool2': pool['pool_name'],
75 'sure': '--yes-i-really-really-mean-it'
80 class Pool(RestController):
81 @expose(template='json')
83 def get(self, **kwargs):
85 Show the information for all the pools
87 pools = module.instance.get('osd_map')['pools']
89 # pgp_num is called pg_placement_num, deal with that
91 if 'pg_placement_num' in pool:
92 pool['pgp_num'] = pool.pop('pg_placement_num')
97 @expose(template='json')
99 def post(self, **kwargs):
102 Requires name and pg_num dict arguments
106 # Check for the required arguments
107 pool_name = args.pop('name', None)
108 if pool_name is None:
109 response.status = 500
110 return {'message': 'You need to specify the pool "name" argument'}
112 pg_num = args.pop('pg_num', None)
114 response.status = 500
115 return {'message': 'You need to specify the "pg_num" argument'}
117 # Run the pool create command first
119 'prefix': 'osd pool create',
124 # Check for invalid pool args
125 invalid = common.invalid_pool_args(args)
127 response.status = 500
128 return {'message': 'Invalid arguments found: "%s"' % str(invalid)}
130 # Schedule the creation and update requests
131 return module.instance.submit_request(
133 common.pool_update_commands(pool_name, args),
139 def _lookup(self, pool_id, *remainder):
140 return PoolId(int(pool_id)), remainder