Skip to content

Commit

Permalink
Deploy storage policies
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanBoronat committed Oct 25, 2017
1 parent 5a952a2 commit c17293a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/swift/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
url(r'^storage_policy/(?P<storage_policy_id>[^/]+)/?$', views.storage_policy_detail),
url(r'^storage_policy/(?P<storage_policy_id>[^/]+)/disk/?$', views.storage_policy_disks),
url(r'^storage_policy/(?P<storage_policy_id>[^/]+)/disk/(?P<disk_id>[^/]+)/?$', views.delete_storage_policy_disks),
url(r'^storage_policy/(?P<storage_policy_id>[^/]+)/deploy/?$', views.deploy_storage_policy),

# Object Placement
url(r'^locality/(?P<account>\w+)(?:/(?P<container>[-\w]+))(?:/(?P<swift_object>[-\w]+))?/$', views.locality_list),
Expand Down
29 changes: 29 additions & 0 deletions api/swift/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def storage_policy_detail(request, storage_policy_id):
if r.exists(key):
data = JSONParser().parse(request)
try:
data['deployed'] = False
r.hmset(key, data)
return JSONResponse("Storage Policy updated", status=status.HTTP_201_CREATED)
except RedisError:
Expand Down Expand Up @@ -161,6 +162,7 @@ def storage_policy_disks(request, storage_policy_id):
storage_policy['devices'].append(disk)
storage_policy['devices'] = json.dumps(storage_policy['devices'])
r.hset(key, 'devices', storage_policy['devices'])
r.hset(key, 'deployed', False)
return JSONResponse('Disk added correctly', status=status.HTTP_200_OK)
else:
return JSONResponse('Disk could not be added.', status=status.HTTP_400_BAD_REQUEST)
Expand All @@ -186,6 +188,7 @@ def delete_storage_policy_disks(request, storage_policy_id, disk_id):
storage_policy['devices'].remove(disk_id)
storage_policy['devices'] = json.dumps(storage_policy['devices'])
r.hset(key, 'devices', storage_policy['devices'])
r.hset(key, 'deployed', False)
return JSONResponse("Disk removed", status=status.HTTP_204_NO_CONTENT)
else:
return JSONResponse('Disk not found', status=status.HTTP_404_NOT_FOUND)
Expand All @@ -197,6 +200,32 @@ def delete_storage_policy_disks(request, storage_policy_id, disk_id):
return JSONResponse('Method not allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)



@csrf_exempt
def deploy_storage_policy(request, storage_policy_id):

try:
r = get_redis_connection()
except RedisError:
return JSONResponse('Error connecting with DB', status=status.HTTP_500_INTERNAL_SERVER_ERROR)

key = "storage-policy:" + storage_policy_id

print request.method
if request.method == "POST":
if r.exists(key):
try:
r.hset(key, 'deployed', True)
return JSONResponse('Storage policy deployed correctly', status=status.HTTP_200_OK)
except RedisError:
return JSONResponse('Storage policy could not be deployed', status=status.HTTP_400_BAD_REQUEST)
else:
return JSONResponse('Storage policy not found.', status=status.HTTP_404_NOT_FOUND)

return JSONResponse('Only HTTP POST requests allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)



@csrf_exempt
def load_swift_policies(request):

Expand Down

0 comments on commit c17293a

Please sign in to comment.