-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathrequest_context.py
716 lines (658 loc) · 30.4 KB
/
request_context.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
import abc
import json
import re
from collections import OrderedDict
from oslo_log import log as logging
import hpedockerplugin.exception as exception
from hpedockerplugin.hpe import share
LOG = logging.getLogger(__name__)
class RequestContextBuilderFactory(object):
def __init__(self, all_configs):
self._all_configs = all_configs
# if 'block' in all_configs:
# block_configs = all_configs['block']
# backend_configs = block_configs[1]
# self._vol_req_ctxt_creator = VolumeRequestContextBuilder(
# backend_configs)
# else:
# self._vol_req_ctxt_creator = NullRequestContextBuilder(
# "ERROR: Volume driver not enabled. Please provide hpe.conf "
# "file to enable it")
if 'file' in all_configs:
file_configs = all_configs['file']
f_backend_configs = file_configs[1]
self._file_req_ctxt_builder = FileRequestContextBuilder(
f_backend_configs)
else:
self._file_req_ctxt_builder = NullRequestContextBuilder(
"ERROR: File driver not enabled. Please provide hpe_file.conf "
"file to enable it")
def get_request_context_builder(self):
return self._file_req_ctxt_builder
class NullRequestContextBuilder(object):
def __init__(self, msg):
self._msg = msg
def build_request_context(self, contents, def_backend_name):
raise exception.InvalidInput(self._msg)
class RequestContextBuilder(object):
def __init__(self, backend_configs):
self._backend_configs = backend_configs
def build_request_context(self, contents, def_backend_name):
LOG.info("build_request_context: Entering...")
self._validate_name(contents['Name'])
req_ctxt_map = self._get_build_req_ctxt_map()
if 'Opts' in contents and contents['Opts']:
# self._validate_mutually_exclusive_ops(contents)
self._validate_dependent_opts(contents)
for op_name, req_ctxt_creator in req_ctxt_map.items():
op_name = op_name.split(',')
found = not (set(op_name) - set(contents['Opts'].keys()))
if found:
return req_ctxt_creator(contents, def_backend_name)
return self._default_req_ctxt_creator(contents)
@staticmethod
def _validate_name(vol_name):
is_valid_name = re.match("^[A-Za-z0-9]+[A-Za-z0-9_-]+$", vol_name)
if not is_valid_name:
msg = 'Invalid volume name: %s is passed.' % vol_name
raise exception.InvalidInput(reason=msg)
@staticmethod
def _get_int_option(options, option_name, default_val):
opt = options.get(option_name)
if opt and opt != '':
try:
opt = int(opt)
except ValueError as ex:
msg = "ERROR: Invalid value '%s' specified for '%s' option. " \
"Please specify an integer value." % (opt, option_name)
LOG.error(msg)
raise exception.InvalidInput(msg)
else:
opt = default_val
return opt
# This method does the following:
# 1. Option specified
# - Some value:
# -- return if valid value else exception
# - Blank value:
# -- Return default if provided
# ELSE
# -- Throw exception if value_unset_exception is set
# 2. Option NOT specified
# - Return default value
@staticmethod
def _get_str_option(options, option_name, default_val, valid_values=None,
value_unset_exception=False):
opt = options.get(option_name)
if opt:
if opt != '':
opt = str(opt)
if valid_values and opt.lower() not in valid_values:
msg = "ERROR: Invalid value '%s' specified for '%s'" \
"option. Valid values are: %s" %\
(opt, option_name, valid_values)
LOG.error(msg)
raise exception.InvalidInput(msg)
return opt
if default_val:
return default_val
if value_unset_exception:
return json.dumps({
'Err': "Value not set for option: %s" % opt
})
return default_val
def _validate_dependent_opts(self, contents):
pass
# To be implemented by derived class
@abc.abstractmethod
def _get_build_req_ctxt_map(self):
pass
def _default_req_ctxt_creator(self, contents):
pass
@staticmethod
def _validate_mutually_exclusive_ops(contents):
mutually_exclusive_ops = ['virtualCopyOf', 'cloneOf', 'importVol',
'replicationGroup']
if 'Opts' in contents and contents['Opts']:
received_opts = contents.get('Opts').keys()
diff = set(mutually_exclusive_ops) - set(received_opts)
if len(diff) < len(mutually_exclusive_ops) - 1:
mutually_exclusive_ops.sort()
msg = "Operations %s are mutually exclusive and cannot be " \
"specified together. Please check help for usage." % \
mutually_exclusive_ops
raise exception.InvalidInput(reason=msg)
@staticmethod
def _check_valid_fsMode_string(value):
valid_type = ['A', 'D', 'U', 'L']
valid_flag = ['f', 'd', 'p', 'i', 'S', 'F', 'g']
valid_perm1 = ['r', 'w', 'a', 'x', 'd', 'D', 't', 'T']
valid_perm2 = ['n', 'N', 'c', 'C', 'o', 'y']
valid_perm = valid_perm1 + valid_perm2
type_flag_perm = value.split(':')
if len(type_flag_perm) != 3:
msg = "Incorrect value passed , please check correct "\
"format and values to be passed in help"
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
vtype = type_flag_perm[0]
if vtype not in valid_type:
msg = "Incorrect value passed for type of a mode, please check "\
"correct format and values to be passed."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
passed_vflag_len = len(list(type_flag_perm[1]))
vflag = list(set(list(type_flag_perm[1])))
if len(vflag) < passed_vflag_len:
msg = "Duplicate characters for given flag are passed. "\
"Please correct the passed flag characters for fsMode."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
if set(vflag) - set(valid_flag):
msg = "Invalid flag passed for the fsMode. Please "\
"pass the correct flag characters"
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
passed_vperm_len = len(list(type_flag_perm[2]))
vperm = list(set(list(type_flag_perm[2])))
if len(vperm) < passed_vperm_len:
msg = "Duplicate characters for given permission are passed. "\
"Please correct the passed permissions for fsMode."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
if set(vperm) - set(valid_perm):
msg = "Invalid characters for the permissions of fsMode are "\
"passed. Please remove the invalid characters."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
return True
def _check_is_valid_acl_string(self, fsMode):
fsMode_list = fsMode.split(',')
if len(fsMode_list) != 3:
msg = "Passed acl string is not valid. "\
"Pass correct acl string."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
for value in fsMode_list:
self._check_valid_fsMode_string(value)
return True
@staticmethod
def _is_valid_octal_num(fsMode):
return re.match('^0[0-7]{3}$', fsMode)
def _validate_fsMode(self, fsMode):
is_valid_fs_mode = True
if ':' in fsMode:
is_valid_fs_mode = self._check_is_valid_acl_string(fsMode)
else:
is_valid_fs_mode = self._is_valid_octal_num(fsMode)
if not is_valid_fs_mode:
msg = "Invalid value passed for the fsMode."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
@staticmethod
def _validate_fsOwner(fsOwner):
fsOwner_list = fsOwner.split(':')
if len(fsOwner_list) != 2:
msg = "Invalid value specified for fsOwner Option."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
try:
for val in fsOwner_list:
int(val)
except ValueError as ex:
msg = "Please provide correct fsowner inforamtion. You have "\
"passed non integer values."
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
@staticmethod
def _validate_opts(operation, contents, valid_opts, mandatory_opts=None):
LOG.info("Validating options for operation '%s'" % operation)
if 'Opts' in contents and contents['Opts']:
received_opts = contents.get('Opts').keys()
if mandatory_opts:
diff = set(mandatory_opts) - set(received_opts)
if diff:
# Print options in sorted manner
mandatory_opts.sort()
msg = "One or more mandatory options %s are missing " \
"for operation %s" % (mandatory_opts, operation)
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
diff = set(received_opts) - set(valid_opts)
if diff:
diff = list(diff)
diff.sort()
msg = "Invalid option(s) %s specified for operation %s. " \
"Please check help for usage." % \
(diff, operation)
LOG.error(msg)
raise exception.InvalidInput(reason=msg)
class FileRequestContextBuilder(RequestContextBuilder):
def __init__(self, backend_configs):
super(FileRequestContextBuilder, self).__init__(backend_configs)
def _get_build_req_ctxt_map(self):
build_req_ctxt_map = OrderedDict()
# If share-dir is specified, file-store MUST be specified
build_req_ctxt_map['filePersona,help'] = self._create_help_req_ctxt
build_req_ctxt_map['filePersona'] = \
self._create_share_req_ctxt
# build_req_ctxt_map['persona,cpg'] = \
# self._create_share_req_ctxt
# build_req_ctxt_map['persona,cpg,size'] = \
# self._create_share_req_ctxt
# build_req_ctxt_map['persona,cpg,size,fpg_name'] = \
# self._create_share_req_ctxt
# build_req_ctxt_map['virtualCopyOf,shareName'] = \
# self._create_snap_req_ctxt
# build_req_ctxt_map['updateShare'] = \
# self._create_update_req_ctxt
return build_req_ctxt_map
def _create_share_req_params(self, name, options, def_backend_name):
LOG.info("_create_share_req_params: Entering...")
# import pdb
# pdb.set_trace()
backend = self._get_str_option(options, 'backend', def_backend_name)
if backend == 'DEFAULT_BLOCK':
msg = 'Backend DEFAULT_BLOCK is reserved for Block ' \
'operations. Cannot specify it for File operations'
LOG.error(msg)
raise exception.InvalidInput(msg)
config = self._backend_configs.get(backend)
if not config:
raise exception.InvalidInput(
'ERROR: Backend %s is not configured for File Persona'
% backend
)
cpg = self._get_str_option(
options, 'cpg',
config.hpe3par_cpg[0] if config.hpe3par_cpg else None)
if not cpg:
raise exception.InvalidInput(
"ERROR: CPG is not configured in hpe.conf. Please specify"
"name of an existing CPG in hpe.conf and restart plugin")
fpg = self._get_str_option(options, 'fpg', None)
fsMode = self._get_str_option(options, 'fsMode', None)
fsOwner = self._get_str_option(options, 'fsOwner', None)
if fsMode:
self._validate_fsMode(fsMode)
if fsOwner:
self._validate_fsOwner(fsOwner)
if fsMode:
if fsOwner is None:
raise exception.InvalidInput(
" ERROR: If mode bits or directory permissions"
" needs to be changed then, providing fsOwner"
" is mandetory")
size_gib = self._get_int_option(options, 'size', 1024)
# Default share size or quota in MiB which is 1TiB
size = size_gib * 1024
fpg_size_gib = int(config.hpe3par_default_fpg_size) * 1024
if size_gib > fpg_size_gib:
raise exception.InvalidInput(
"ERROR: Share size cannot be greater than the FPG size. "
"Either specify hpe3par_default_fpg_size >= %s GiB or "
"specify option '-o size' < %s GiB"
% (size_gib, fpg_size_gib))
# TODO: This check would be required when VFS needs to be created.
# NOT HERE
# if not ip_subnet and not config.hpe3par_ip_pool:
# raise exception.InvalidInput(
# "ERROR: Unable to create share as neither 'ipSubnet' "
# "option specified not IP address pool hpe3par_ip_pool "
# "configured in configuration file specified")
readonly_str = self._get_str_option(options, 'readonly', 'false')
readonly = str.lower(readonly_str)
if readonly == 'true':
readonly = True
elif readonly == 'false':
readonly = False
else:
raise exception.InvalidInput(
'ERROR: Invalid value "%s" supplied for "readonly" option. '
'Valid values are case insensitive ["true", "false"]'
% readonly_str)
nfs_options = self._get_str_option(options, 'nfsOptions', None)
comment = self._get_str_option(options, 'comment', None)
share_details = share.create_metadata(backend, cpg, fpg, name, size,
readonly=readonly,
nfs_options=nfs_options,
comment=comment, fsMode=fsMode,
fsOwner=fsOwner)
LOG.info("_create_share_req_params: %s" % share_details)
return share_details
def _create_share_req_ctxt(self, contents, def_backend_name):
LOG.info("_create_share_req_ctxt: Entering...")
valid_opts = ('backend', 'filePersona', 'cpg', 'fpg',
'size', 'mountConflictDelay', 'fsMode', 'fsOwner')
mandatory_opts = ('filePersona',)
self._validate_opts("create share", contents, valid_opts,
mandatory_opts)
share_args = self._create_share_req_params(contents['Name'],
contents['Opts'],
def_backend_name)
ctxt = {'orchestrator': 'file',
'operation': 'create_share',
'kwargs': share_args}
LOG.info("_create_share_req_ctxt: Exiting: %s" % ctxt)
return ctxt
def _create_help_req_ctxt(self, contents, def_backend_name):
LOG.info("_create_help_req_ctxt: Entering...")
valid_opts = ('filePersona', 'help', 'mountConflictDelay')
self._validate_opts("create help content for share", contents,
valid_opts, mandatory_opts=None)
options = contents['Opts']
if options:
value = self._get_str_option(options, 'help', None)
if not value:
return {
'orchestrator': 'file',
'operation': 'create_share_help',
'kwargs': {}
}
if value == 'backends':
return {
'orchestrator': 'file',
'operation': 'get_backends_status',
'kwargs': {}
}
else:
raise exception.InvalidInput(
"ERROR: Invalid value %s for option 'help' specified."
% value)
LOG.info("_create_help_req_ctxt: Exiting...")
def _create_snap_req_ctxt(self, contents):
pass
def _create_update_req_ctxt(self, contents):
pass
# TODO: This is work in progress - can be taken up later if agreed upon
# class VolumeRequestContextBuilder(RequestContextBuilder):
# def __init__(self, backend_configs):
# super(VolumeRequestContextBuilder, self).__init__(backend_configs)
#
# def _get_build_req_ctxt_map(self):
# build_req_ctxt_map = OrderedDict()
# build_req_ctxt_map['virtualCopyOf,scheduleName'] = \
# self._create_snap_schedule_req_ctxt,
# build_req_ctxt_map['virtualCopyOf,scheduleFrequency'] = \
# self._create_snap_schedule_req_ctxt
# build_req_ctxt_map['virtualCopyOf,snaphotPrefix'] = \
# self._create_snap_schedule_req_ctxt
# build_req_ctxt_map['virtualCopyOf'] = \
# self._create_snap_req_ctxt
# build_req_ctxt_map['cloneOf'] = \
# self._create_clone_req_ctxt
# build_req_ctxt_map['importVol'] = \
# self._create_import_vol_req_ctxt
# build_req_ctxt_map['replicationGroup'] = \
# self._create_rcg_req_ctxt
# build_req_ctxt_map['help'] = self._create_help_req_ctxt
# return build_req_ctxt_map
#
# def _default_req_ctxt_creator(self, contents):
# return self._create_vol_create_req_ctxt(contents)
#
# @staticmethod
# def _validate_mutually_exclusive_ops(contents):
# mutually_exclusive_ops = ['virtualCopyOf', 'cloneOf', 'importVol',
# 'replicationGroup']
# if 'Opts' in contents and contents['Opts']:
# received_opts = contents.get('Opts').keys()
# diff = set(mutually_exclusive_ops) - set(received_opts)
# if len(diff) < len(mutually_exclusive_ops) - 1:
# mutually_exclusive_ops.sort()
# msg = "Operations %s are mutually exclusive and cannot be " \
# "specified together. Please check help for usage." % \
# mutually_exclusive_ops
# raise exception.InvalidInput(reason=msg)
#
# @staticmethod
# def _validate_opts(operation, contents, valid_opts, mandatory_opts=None):
# if 'Opts' in contents and contents['Opts']:
# received_opts = contents.get('Opts').keys()
#
# if mandatory_opts:
# diff = set(mandatory_opts) - set(received_opts)
# if diff:
# # Print options in sorted manner
# mandatory_opts.sort()
# msg = "One or more mandatory options %s are missing " \
# "for operation %s" % (mandatory_opts, operation)
# raise exception.InvalidInput(reason=msg)
#
# diff = set(received_opts) - set(valid_opts)
# if diff:
# diff = list(diff)
# diff.sort()
# msg = "Invalid option(s) %s specified for operation %s. " \
# "Please check help for usage." % \
# (diff, operation)
# raise exception.InvalidInput(reason=msg)
#
# def _create_vol_create_req_ctxt(self, contents):
# valid_opts = ['compression', 'size', 'provisioning',
# 'flash-cache', 'qos-name', 'fsOwner',
# 'fsMode', 'mountConflictDelay', 'cpg',
# 'snapcpg', 'backend']
# self._validate_opts("create volume", contents, valid_opts)
# return {'operation': 'create_volume',
# '_vol_orchestrator': 'volume'}
#
# def _create_clone_req_ctxt(self, contents):
# valid_opts = ['cloneOf', 'size', 'cpg', 'snapcpg',
# 'mountConflictDelay']
# self._validate_opts("clone volume", contents, valid_opts)
# return {'operation': 'clone_volume',
# 'orchestrator': 'volume'}
#
# def _create_snap_req_ctxt(self, contents):
# valid_opts = ['virtualCopyOf', 'retentionHours', 'expirationHours',
# 'mountConflictDelay', 'size']
# self._validate_opts("create snapshot", contents, valid_opts)
# return {'operation': 'create_snapshot',
# '_vol_orchestrator': 'volume'}
#
# def _create_snap_schedule_req_ctxt(self, contents):
# valid_opts = ['virtualCopyOf', 'scheduleFrequency', 'scheduleName',
# 'snapshotPrefix', 'expHrs', 'retHrs',
# 'mountConflictDelay', 'size']
# mandatory_opts = ['scheduleName', 'snapshotPrefix',
# 'scheduleFrequency']
# self._validate_opts("create snapshot schedule", contents,
# valid_opts, mandatory_opts)
# return {'operation': 'create_snapshot_schedule',
# 'orchestrator': 'volume'}
#
# def _create_import_vol_req_ctxt(self, contents):
# valid_opts = ['importVol', 'backend', 'mountConflictDelay']
# self._validate_opts("import volume", contents, valid_opts)
#
# # Replication enabled backend cannot be used for volume import
# backend = contents['Opts'].get('backend', 'DEFAULT')
# if backend == '':
# backend = 'DEFAULT'
#
# try:
# config = self._backend_configs[backend]
# except KeyError:
# backend_names = list(self._backend_configs.keys())
# backend_names.sort()
# msg = "ERROR: Backend '%s' doesn't exist. Available " \
# "backends are %s. Please use " \
# "a valid backend name and retry." % \
# (backend, backend_names)
# raise exception.InvalidInput(reason=msg)
#
# if config.replication_device:
# msg = "ERROR: Import volume not allowed with replication " \
# "enabled backend '%s'" % backend
# raise exception.InvalidInput(reason=msg)
#
# volname = contents['Name']
# existing_ref = str(contents['Opts']['importVol'])
# manage_opts = contents['Opts']
# return {'orchestrator': 'volume',
# 'operation': 'import_volume',
# 'args': (volname,
# existing_ref,
# backend,
# manage_opts)}
#
# def _create_rcg_req_ctxt(self, contents):
# valid_opts = ['replicationGroup', 'size', 'provisioning',
# 'backend', 'mountConflictDelay', 'compression']
# self._validate_opts('create replicated volume', contents, valid_opts)
#
# # It is possible that the user configured replication in hpe.conf
# # but didn't specify any options. In that case too, this operation
# # must fail asking for "replicationGroup" parameter
# # Hence this validation must be done whether "Opts" is there or not
# options = contents['Opts']
# backend = self._get_str_option(options, 'backend', 'DEFAULT')
# create_vol_args = self._get_create_volume_args(options)
# rcg_name = create_vol_args['replicationGroup']
# try:
# self._validate_rcg_params(rcg_name, backend)
# except exception.InvalidInput as ex:
# return json.dumps({u"Err": ex.msg})
#
# return {'operation': 'create_volume',
# 'orchestrator': 'volume',
# 'args': create_vol_args}
#
# def _get_fs_owner(self, options):
# val = self._get_str_option(options, 'fsOwner', None)
# if val:
# fs_owner = val.split(':')
# if len(fs_owner) != 2:
# msg = "Invalid value '%s' specified for fsOwner. Please " \
# "specify a correct value." % val
# raise exception.InvalidInput(msg)
# return fs_owner
# return None
#
# def _get_fs_mode(self, options):
# fs_mode_str = self._get_str_option(options, 'fsMode', None)
# if fs_mode_str:
# try:
# int(fs_mode_str)
# except ValueError as ex:
# msg = "Invalid value '%s' specified for fsMode. Please " \
# "specify an integer value." % fs_mode_str
# raise exception.InvalidInput(msg)
#
# if fs_mode_str[0] != '0':
# msg = "Invalid value '%s' specified for fsMode. Please " \
# "specify an octal value." % fs_mode_str
# raise exception.InvalidInput(msg)
#
# for mode in fs_mode_str:
# if int(mode) > 7:
# msg = "Invalid value '%s' specified for fsMode. Please"\
# " specify an octal value." % fs_mode_str
# raise exception.InvalidInput(msg)
# return fs_mode_str
#
# def _get_create_volume_args(self, options):
# ret_args = dict()
# ret_args['size'] = self._get_int_option(
# options, 'size', volume.DEFAULT_SIZE)
# ret_args['provisioning'] = self._get_str_option(
# options, 'provisioning', volume.DEFAULT_PROV,
# ['full', 'thin', 'dedup'])
# ret_args['flash-cache'] = self._get_str_option(
# options, 'flash-cache', volume.DEFAULT_FLASH_CACHE,
# ['true', 'false'])
# ret_args['qos-name'] = self._get_str_option(
# options, 'qos-name', volume.DEFAULT_QOS)
# ret_args['compression'] = self._get_str_option(
# options, 'compression', volume.DEFAULT_COMPRESSION_VAL,
# ['true', 'false'])
# ret_args['fsOwner'] = self._get_fs_owner(options)
# ret_args['fsMode'] = self._get_fs_mode(options)
# ret_args['mountConflictDelay'] = self._get_int_option(
# options, 'mountConflictDelay',
# volume.DEFAULT_MOUNT_CONFLICT_DELAY)
# ret_args['cpg'] = self._get_str_option(options, 'cpg', None)
# ret_args['snapcpg'] = self._get_str_option(options, 'snapcpg', None)
# ret_args['replicationGroup'] = self._get_str_option(
# options, 'replicationGroup', None)
#
# return ret_args
#
# def _validate_rcg_params(self, rcg_name, backend_name):
# LOG.info("Validating RCG: %s, backend name: %s..." % (rcg_name,
# backend_name))
# hpepluginconfig = self._backend_configs[backend_name]
# replication_device = hpepluginconfig.replication_device
#
# LOG.info("Replication device: %s" % six.text_type(
# replication_device))
#
# if rcg_name and not replication_device:
# msg = "Request to create replicated volume cannot be fulfilled"\
# "without defining 'replication_device' entry defined in"\
# "hpe.conf for the backend '%s'. Please add it and execute"\
# "the request again." % backend_name
# raise exception.InvalidInput(reason=msg)
#
# if replication_device and not rcg_name:
# backend_names = list(self._backend_configs.keys())
# backend_names.sort()
#
# msg = "'%s' is a replication enabled backend. " \
# "Request to create replicated volume cannot be fulfilled "\
# "without specifying 'replicationGroup' option in the "\
# "request. Please either specify 'replicationGroup' or use"\
# "a normal backend and execute the request again. List of"\
# "backends defined in hpe.conf: %s" % (backend_name,
# backend_names)
# raise exception.InvalidInput(reason=msg)
#
# if rcg_name and replication_device:
#
# def _check_valid_replication_mode(mode):
# valid_modes = ['synchronous', 'asynchronous', 'streaming']
# if mode.lower() not in valid_modes:
# msg = "Unknown replication mode '%s' specified. Valid "\
# "values are 'synchronous | asynchronous | " \
# "streaming'" % mode
# raise exception.InvalidInput(reason=msg)
#
# rep_mode = replication_device['replication_mode'].lower()
# _check_valid_replication_mode(rep_mode)
# if replication_device.get('quorum_witness_ip'):
# if rep_mode.lower() != 'synchronous':
# msg = "For Peer Persistence, replication mode must be "\
# "synchronous"
# raise exception.InvalidInput(reason=msg)
#
# sync_period = replication_device.get('sync_period')
# if sync_period and rep_mode == 'synchronous':
# msg = "'sync_period' can be defined only for 'asynchronous'"\
# " and 'streaming' replicate modes"
# raise exception.InvalidInput(reason=msg)
#
# if (rep_mode == 'asynchronous' or rep_mode == 'streaming')\
# and sync_period:
# try:
# sync_period = int(sync_period)
# except ValueError as ex:
# msg = "Non-integer value '%s' not allowed for " \
# "'sync_period'. %s" % (
# replication_device.sync_period, ex)
# raise exception.InvalidInput(reason=msg)
# else:
# SYNC_PERIOD_LOW = 300
# SYNC_PERIOD_HIGH = 31622400
# if sync_period < SYNC_PERIOD_LOW or \
# sync_period > SYNC_PERIOD_HIGH:
# msg = "'sync_period' must be between 300 and " \
# "31622400 seconds."
# raise exception.InvalidInput(reason=msg)
#
# @staticmethod
# def _validate_name(vol_name):
# is_valid_name = re.match("^[A-Za-z0-9]+[A-Za-z0-9_-]+$", vol_name)
# if not is_valid_name:
# msg = 'Invalid volume name: %s is passed.' % vol_name
# raise exception.InvalidInput(reason=msg)