Skip to content

Commit 80fdff7

Browse files
author
JoanBoronat
committed
Get list of deployed SP
1 parent 22a8e03 commit 80fdff7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

api/swift_api/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
urlpatterns = [
55
# Storages Policies
66
url(r'^storage_policies/?$', views.storage_policies),
7+
url(r'^storage_policies/deployed?$', views.deployed_storage_policies),
78
url(r'^storage_policies/load?$', views.load_swift_policies),
89
url(r'^storage_policy/(?P<storage_policy_id>[^/]+)/?$', views.storage_policy_detail),
910
url(r'^storage_policy/(?P<storage_policy_id>[^/]+)/disk/?$', views.storage_policy_disks),

api/swift_api/views.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ def storage_policies(request):
105105
return JSONResponse('Only HTTP POST requests allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)
106106

107107

108+
@csrf_exempt
109+
def deployed_storage_policies(request):
110+
111+
if request.method == "GET":
112+
try:
113+
r = get_redis_connection()
114+
except RedisError:
115+
return JSONResponse('Error connecting with DB', status=status.HTTP_500_INTERNAL_SERVER_ERROR)
116+
117+
keys = r.keys("storage-policy:*")
118+
swift_file = os.path.join(settings.SWIFT_CFG_DEPLOY_DIR, 'swift.conf')
119+
config_parser = ConfigParser.RawConfigParser()
120+
config_parser.read(swift_file)
121+
122+
deployed_storage_policy_list = [sp for sp in keys if config_parser.has_section(sp)]
123+
124+
storage_policy_list = []
125+
for key in deployed_storage_policy_list:
126+
storage_policy = r.hgetall(key)
127+
to_json_bools(storage_policy, 'deprecated', 'default', 'deployed')
128+
storage_policy['id'] = str(key).split(':')[-1]
129+
storage_policy['devices'] = json.loads(storage_policy['devices'])
130+
storage_policy_list.append(storage_policy)
131+
132+
return JSONResponse(storage_policy_list, status=status.HTTP_200_OK)
133+
134+
return JSONResponse('Only HTTP POST requests allowed.', status=status.HTTP_405_METHOD_NOT_ALLOWED)
135+
136+
108137
@csrf_exempt
109138
def storage_policy_detail(request, storage_policy_id):
110139

0 commit comments

Comments
 (0)