@@ -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
109138def storage_policy_detail (request , storage_policy_id ):
110139
0 commit comments