@@ -100,7 +100,7 @@ def storage_policies(request):
100
100
ring .save (get_policy_file_path (settings .SWIFT_CFG_TMP_DIR , sp_id ))
101
101
102
102
r .hmset (key , data )
103
- except :
103
+ except Exception :
104
104
return JSONResponse ('Error creating the Storage Policy' , status = status .HTTP_500_INTERNAL_SERVER_ERROR )
105
105
106
106
return JSONResponse ('Account created successfully' , status = status .HTTP_201_CREATED )
@@ -159,8 +159,17 @@ def storage_policy_detail(request, storage_policy_id):
159
159
object_node_devices = json .loads (object_node ['devices' ])
160
160
device_detail = object_node_devices [device_id ]
161
161
device_detail ['id' ] = device [0 ]
162
- device_detail ['region' ] = r .hgetall ('region:' + object_node ['region_id' ])['name' ]
163
- device_detail ['zone' ] = r .hgetall ('zone:' + object_node ['zone_id' ])['name' ]
162
+ r_id = object_node ['region_id' ]
163
+ z_id = object_node ['zone_id' ]
164
+ if r .exists ('region:' + r_id ):
165
+ device_detail ['region' ] = r .hgetall ('region:' + object_node ['region_id' ])['name' ]
166
+ else :
167
+ device_detail ['region' ] = r_id
168
+
169
+ if r .exists ('region:' + r_id ):
170
+ device_detail ['zone' ] = r .hgetall ('zone:' + object_node ['zone_id' ])['name' ]
171
+ else :
172
+ device_detail ['zone' ] = z_id
164
173
devices .append (device_detail )
165
174
storage_policy ['devices' ] = devices
166
175
return JSONResponse (storage_policy , status = status .HTTP_200_OK )
@@ -251,8 +260,17 @@ def storage_policy_disks(request, storage_policy_id):
251
260
object_node = r .hgetall ('object_node:' + object_node_id )
252
261
device_detail = json .loads (object_node ['devices' ])[device_id ]
253
262
device_detail ['id' ] = device
254
- device_detail ['region' ] = r .hgetall ('region:' + object_node ['region_id' ])['name' ]
255
- device_detail ['zone' ] = r .hgetall ('zone:' + object_node ['zone_id' ])['name' ]
263
+ r_id = object_node ['region_id' ]
264
+ z_id = object_node ['zone_id' ]
265
+ if r .exists ('region:' + r_id ):
266
+ device_detail ['region' ] = r .hgetall ('region:' + object_node ['region_id' ])['name' ]
267
+ else :
268
+ device_detail ['region' ] = r_id
269
+
270
+ if r .exists ('region:' + r_id ):
271
+ device_detail ['zone' ] = r .hgetall ('zone:' + object_node ['zone_id' ])['name' ]
272
+ else :
273
+ device_detail ['zone' ] = z_id
256
274
available_devices_detail .append (device_detail )
257
275
return JSONResponse (available_devices_detail , status = status .HTTP_200_OK )
258
276
else :
@@ -359,9 +377,20 @@ def deploy_storage_policy(request, storage_policy_id):
359
377
ringdata .save (deploy_gzip_filename )
360
378
361
379
data = r .hgetall (key )
362
- update_sp_files (settings .SWIFT_CFG_DEPLOY_DIR , storage_policy_id , {'name' : data ['name' ],
363
- 'deprecated' : data ['deprecated' ],
364
- 'default' : data ['default' ]})
380
+ policy = {'name' : data ['name' ],
381
+ 'deprecated' : data ['deprecated' ],
382
+ 'default' : data ['default' ]}
383
+
384
+ if data ['policy_type' ] == 'EC' :
385
+ policy .update ({'policy_type' : 'erasure_coding' ,
386
+ 'ec_type' : data ['ec_type' ],
387
+ 'ec_num_data_fragments' : data ['ec_num_data_fragments' ],
388
+ 'ec_num_parity_fragments' : data ['ec_num_parity_fragments' ],
389
+ 'ec_object_segment_size' : data ['ec_object_segment_size' ],
390
+ 'ec_duplication_factor' : data ['ec_duplication_factor' ]})
391
+ update_sp_files (settings .SWIFT_CFG_DEPLOY_DIR , storage_policy_id , policy )
392
+ else :
393
+ update_sp_files (settings .SWIFT_CFG_DEPLOY_DIR , storage_policy_id , policy )
365
394
366
395
copyfile (tmp_policy_file , deploy_policy_file )
367
396
rsync_dir_with_nodes (settings .SWIFT_CFG_DEPLOY_DIR , '/etc/swift' )
@@ -371,7 +400,7 @@ def deploy_storage_policy(request, storage_policy_id):
371
400
return JSONResponse ('Storage policy deployed correctly' , status = status .HTTP_200_OK )
372
401
except RedisError :
373
402
return JSONResponse ('Storage policy could not be deployed' , status = status .HTTP_400_BAD_REQUEST )
374
- except exceptions .RingBuilderError , e :
403
+ except exceptions .RingBuilderError as e :
375
404
return JSONResponse ('Storage policy could not be deployed. Error message: %s' % e .message , status = status .HTTP_400_BAD_REQUEST )
376
405
else :
377
406
return JSONResponse ('Storage policy not found.' , status = status .HTTP_404_NOT_FOUND )
@@ -426,13 +455,13 @@ def load_swift_policies(request):
426
455
files = glob .glob (pattern )
427
456
428
457
try :
458
+ sp_id_list = []
429
459
for builder_file in files :
430
460
builder = RingBuilder .load (builder_file )
431
461
if '-' in builder_file :
432
462
sp_id = builder_file .split ('.' )[0 ].split ('-' )[- 1 ]
433
463
key = 'storage-policy:' + sp_id
434
- if int (sp_id ) > r .get ('storage-policies:id' ):
435
- r .set ('storage-policies:id' , sp_id )
464
+ sp_id_list .append (int (sp_id ))
436
465
else :
437
466
key = 'storage-policy:0'
438
467
@@ -457,10 +486,12 @@ def load_swift_policies(request):
457
486
nodes_data [node ] = r .hgetall (node )
458
487
459
488
for device in builder .devs :
489
+ if device is None :
490
+ continue
460
491
try :
461
492
inet_aton (device ['ip' ])
462
493
device ['ip' ] = next ((nodes_data [node ]['name' ] for node in nodes_data if nodes_data [node ]['ip' ] == device ['ip' ]), device ['ip' ])
463
- except :
494
+ except Exception :
464
495
pass
465
496
devices .append ((device ['ip' ] + ':' + device ['device' ], device ['id' ]))
466
497
@@ -470,18 +501,36 @@ def load_swift_policies(request):
470
501
'time' : builder .min_part_hours ,
471
502
'devices' : json .dumps (devices ),
472
503
'deployed' : 'True' ,
473
- 'policy_type' : policy_type if policy_type else 'Replication' ,
474
504
'partition_power' : int (math .log (builder .parts , 2 )),
475
505
'replicas' : int (builder .replicas )
476
506
}
507
+ if policy_type == 'Replication' :
508
+ data .update ({'policy_type' : policy_type if policy_type else 'Replication' })
509
+ else :
510
+ ec_type = config_parser .get (key , 'ec_type' ) if config_parser .has_option (key , 'ec_type' ) else 'liberasurecode_rs_vand'
511
+ ec_num_parity_fragments = config_parser .get (key , 'ec_num_parity_fragments' )
512
+ ec_num_data_fragments = config_parser .get (key , 'ec_num_data_fragments' )
513
+ ec_duplication_factor = config_parser .get (key , 'ec_duplication_factor' ) if config_parser .has_option (key , 'ec_duplication_factor' ) else '1'
514
+ ec_object_segment_size = config_parser .get (key , 'ec_object_segment_size' ) if config_parser .has_option (key , 'ec_object_segment_size' ) else '1048576'
515
+ data .update ({'policy_type' : 'EC' ,
516
+ 'ec_type' : ec_type ,
517
+ 'ec_num_data_fragments' : ec_num_data_fragments ,
518
+ 'ec_num_parity_fragments' : ec_num_parity_fragments ,
519
+ 'ec_duplication_factor' : ec_duplication_factor ,
520
+ 'ec_object_segment_size' : ec_object_segment_size })
477
521
478
522
r .hmset (key , data )
479
523
480
524
else :
481
525
pass
526
+ if len (sp_id_list ):
527
+ max_sp_id = max (sp_id_list )
528
+ r .set ('storage-policies:id' , max_sp_id )
529
+ else :
530
+ pass
482
531
483
532
except RedisError :
484
- return JSONResponse ('Policies could not be loaded' , status = status .HTTP_500_INTERNAL_SERVER_ERROR )
533
+ return JSONResponse ('Policies could not be loaded' , status = status .HTTP_500_INTERNAL_SERVER_ERROR )
485
534
486
535
return JSONResponse ('Policies loaded correctly' , status = status .HTTP_200_OK )
487
536
@@ -805,8 +854,8 @@ def create_container(request, project_id, container_name):
805
854
url = settings .SWIFT_URL + "/AUTH_" + project_id
806
855
807
856
swift_client .put_container (url , token , container_name , headers )
808
- except Exception as ex :
809
- return JSONResponse (ex .message , status = status .HTTP_500_INTERNAL_SERVER_ERROR )
857
+ except Exception as e :
858
+ return JSONResponse (e .message , status = status .HTTP_500_INTERNAL_SERVER_ERROR )
810
859
811
860
return JSONResponse ("Container Policy updated correctly" , status = status .HTTP_201_CREATED )
812
861
return JSONResponse ('Method ' + str (request .method ) + ' not allowed.' , status = status .HTTP_405_METHOD_NOT_ALLOWED )
0 commit comments