Skip to content

Commit

Permalink
Edit storage-policies
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanBoronat committed Oct 18, 2017
1 parent cd68358 commit 7ade1a3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api/swift/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def storage_policies(request):
storage_policy_list = []
for key in keys:
storage_policy = r.hgetall(key)
to_json_bools(storage_policy, 'deprecated', 'default', 'deployed')
storage_policy['id'] = str(key).split(':')[-1]
storage_policy['devices'] = json.loads(storage_policy['devices'])
storage_policy_list.append(storage_policy)
Expand Down Expand Up @@ -76,7 +77,7 @@ def storage_policy_detail(request, storage_policy_id):
if r.exists(key):
storage_policy = r.hgetall(key)
to_json_bools(storage_policy, 'deprecated', 'default', 'deployed')
print storage_policy
storage_policy['storage_policy_id'] = storage_policy_id
storage_policy['devices'] = json.loads(storage_policy['devices'])
devices = []
for device in storage_policy['devices']:
Expand All @@ -103,6 +104,18 @@ def storage_policy_detail(request, storage_policy_id):
return JSONResponse("Error updating storage policy", status=status.HTTP_400_BAD_REQUEST)
else:
return JSONResponse('Storage policy not found.', status=status.HTTP_404_NOT_FOUND)

if request.method == 'DELETE':
if r.exists(key):
try:
r.delete(key)
if not r.keys('storage-policy:*'):
r.delete('storage-policies:id')
return JSONResponse("Storage Policy deleted", status=status.HTTP_201_CREATED)
except RedisError:
return JSONResponse("Error deleting storage policy", status=status.HTTP_400_BAD_REQUEST)
else:
return JSONResponse('Storage policy not found.', status=status.HTTP_404_NOT_FOUND)

return JSONResponse('Method not allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)

Expand Down

0 comments on commit 7ade1a3

Please sign in to comment.