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 9, 2017
1 parent 9bf8fe7 commit 1c2d8f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
11 changes: 5 additions & 6 deletions api/controllers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,15 @@ def post(self, request):
try:
data['id'] = controller_id
file_obj = request.FILES['file']

make_sure_path_exists(settings.CONTROLLERS_DIR)
path = save_file(file_obj, settings.CONTROLLERS_DIR)
data['controller_name'] = os.path.basename(path)

r.hmset('controller:' + str(controller_id), data)

if data['enabled']:
controller_name = data['controller_name'].split('.')[0]
start_controller(str(controller_id), controller_name, data['class_name'])

controller_name = data['controller_name'].split('.')[0]
start_controller(str(controller_id), controller_name, data['class_name'])

return JSONResponse(data, status=status.HTTP_201_CREATED)

Expand Down
3 changes: 2 additions & 1 deletion api/swift/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
urlpatterns = [
# Storages Policies
url(r'^storage_policies/?$', views.storage_policies),
url(r'^storage_policy/(?P<storage_policy_id>[^/]+)/?$', views.storage_policy_detail),

# Object Placement
url(r'^locality/(?P<account>\w+)(?:/(?P<container>[-\w]+))(?:/(?P<swift_object>[-\w]+))?/$', views.locality_list),
Expand All @@ -21,5 +22,5 @@
url(r'^regions/(?P<region_id>[^/]+)/?$', views.region_detail),
url(r'^zones/?$', views.zones),
url(r'^zones/(?P<zone_id>[^/]+)/?$', views.zone_detail),

]
34 changes: 33 additions & 1 deletion api/swift/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def storage_policies(request):
data = JSONParser().parse(request)
storage_nodes_list = []
if isinstance(data["storage_node"], dict):
data['storage_node']['policy_id'] = r.incr('storage-policies:id')
for k, v in data["storage_node"].items():
storage_nodes_list.extend([k, v])
data["storage_node"] = ','.join(map(str, storage_nodes_list))
try:
print data
storage_policies_utils.create(data)
except Exception as e:
return JSONResponse('Error creating the Storage Policy: ' + e, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Expand All @@ -60,6 +60,38 @@ def storage_policies(request):
return JSONResponse('Only HTTP POST requests allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)



@csrf_exempt
def storage_policy_detail(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
if request.method == 'GET':
if r.exists(key):
storage_policy = r.hgetall(key)
storage_policy['devices'] = json.loads(storage_policy['devices'])
return JSONResponse(storage_policy, status=status.HTTP_200_OK)
else:
return JSONResponse('Storage policy not found.', status=status.HTTP_404_NOT_FOUND)

if request.method == 'PUT':
if r.exists(key):
data = JSONParser().parse(request)
try:
r.hmset(key, data)
return JSONResponse("Storage Policy updated", status=status.HTTP_201_CREATED)
except RedisError:
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)

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


@csrf_exempt
def locality_list(request, account, container=None, swift_object=None):
"""
Expand Down

0 comments on commit 1c2d8f5

Please sign in to comment.