forked from seattle-biomed/ontap-api-wrapper
/
Ontap.py
1395 lines (1055 loc) · 46.6 KB
/
Ontap.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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
import sys
from NaElement import NaElement
from NaServer import NaServer
class OntapApiException(Exception):
"""Expose errors surfaced in the NetApp API as exceptions."""
def __init__(self, errno, reason):
self.errno = errno
self.reason = reason
class OntapException(Exception):
"""Exception for syntax errors passed to API calls."""
def __init__(self, reason):
self.reason = reason
class Filer:
"""A NetApp filer."""
def __init__(self, hostname, user, passwd):
self.api = NaServer(hostname, 1, 3)
self.api.set_style('LOGIN')
self.api.set_admin_user(user, passwd)
self.api.set_transport_type('HTTPS')
self.name = hostname
out = self.invoke('system-get-version')
self.version = out.child_get_string('version')
# Used for caching performance object descriptions:
self.perf_obj_info = {}
def create_volume(self, name, aggr, size):
v = FlexVol(self, name)
v.create(aggr, size)
return v
def flexshare_disable(self):
"""Equivalent to 'priority off' on the CLI."""
self.invoke('priority-disable')
def flexshare_enable(self):
"""Equivalent to 'priority on' on the CLI."""
self.invoke('priority-enable')
def flexshare_is_enabled(self):
"""Return boolean representing whether FlexShare is enabled."""
out = self.invoke('priority-list-info')
if out.child_get_string('status') == 'on':
return True
else:
return False
def get_cifs_homedirs(self):
"""
Equivalent to 'cifs homedir' on the CLI.
Return an array of cifs home directory paths.
"""
out = self.invoke('cifs-homedir-paths-get')
if out.has_children():
homedirs = []
for d in out.child_get('homedir-paths').children_get():
homedirs.append(d.element['content'])
return homedirs
else:
return []
def get_export(self, export_path):
"""
Return an Export object representing NFS share at export_path.
If export does not exist, return False.
"""
if self.has_export(export_path):
return(Export(self, export_path))
else:
return False
def get_exports(self):
"""Return a list of Export objects of filer's configured NFS shares."""
out = self.invoke('nfs-exportfs-list-rules')
exports = []
for export in out.child_get('rules').children_get():
path = export.child_get_string('pathname')
exports.append(Export(self, path))
return exports
def get_fs_status_msg(self):
"""Return a string containing the file system status message."""
return self.get_oid('.1.3.6.1.4.1.789.1.5.7.2.0')
def get_oid(self, oid):
"""Return a generic OID from the NetApp SNMP MIB."""
out = self.invoke('snmp-get', 'object-id', oid)
return out.child_get_string('value')
def get_perf_object(self, objectname, read=[], instances=[]):
"""
Return objectname's performance data in a dict tree.
read - optional array of counters whose values are to be read.
If not set, all counters are reported.
instances - optional array of instances whose values are to be read.
If not set, all instances are reported.
"""
info = self.get_perf_object_info(objectname)
get_perf_obj = NaElement('perf-object-get-instances-iter-start')
get_perf_obj.child_add(NaElement('objectname', objectname))
if read:
read_counters = NaElement('counters')
for c in read:
read_counters.child_add(NaElement('counter', c))
get_perf_obj.child_add(read_counters)
if instances:
insts = NaElement('instances')
for inst in instances:
insts.child_add(NaElement('instance', inst))
get_perf_obj.child_add(insts)
out = self.invoke_elem(get_perf_obj)
iter_tag = out.child_get_int('tag')
iter_recs = out.child_get_int('records')
perf_insts = {}
i = 0
while i < iter_recs:
out = self.invoke('perf-object-get-instances-iter-next',
'maximum', 1,
'tag', iter_tag)
inst = out.child_get('instances').child_get('instance-data')
inst_name = inst.child_get_string('name')
perf_insts[inst_name] = {}
counters = inst.child_get('counters').children_get()
for c in counters:
name = c.child_get_string('name')
if info[name]['type'] == 'array':
vals = c.child_get_string('value').split(',')
data = {}
j = 0
while j < len(vals):
data[info[name]['labels'][j]] = int(vals[j])
j = j + 1
perf_insts[inst_name][name] = data
else:
try:
perf_insts[inst_name][name] = c.child_get_int('value')
except ValueError:
# Must be a string...
perf_insts[inst_name][name] = c.child_get_string(
'value')
i = i + 1
self.invoke('perf-object-get-instances-iter-end', 'tag', iter_tag)
return perf_insts
def get_perf_object_info(self, objectname):
"""
Return dict of static information about perf counter 'objectname'.
Information is returned as a dict of dicts.
"""
# Check cache:
if self.perf_obj_info.has_key(objectname):
return self.perf_obj_info[objectname]
out = self.invoke('perf-object-counter-list-info',
'objectname', objectname)
counters = {}
for counter in out.child_get('counters').children_get():
name = counter.child_get_string('name')
counters[name] = {}
counters[name]['desc'] = counter.child_get_string('desc')
counters[name]['privilege-level'] = counter.child_get_string(
'privilege-level')
## Handle optional keys:
for opt_key in ('base-counter', 'properties', 'type', 'unit'):
opt_val = counter.child_get_string(opt_key)
if opt_val:
counters[name][opt_key] = opt_val
elif opt_key == 'type':
counters[name]['type'] = 'scalar'
labels = counter.child_get('labels')
if labels:
counters[name]['labels'] = labels.child_get_string(
'label-info').split(',')
# Store info in cache and return
self.perf_obj_info[objectname] = counters
return counters
def get_perf_object_list(self):
"""Return dict of filer performance object names and privileges."""
out = self.invoke('perf-object-list-info')
objs = {}
for obj in out.child_get('objects').children_get():
objs[obj.child_get_string('name')] = obj.child_get_string(
'privilege-level')
return objs
def get_root_name(self):
"""Return a string containing the Filer's root volume's name."""
out = self.invoke('aggr-get-root-name')
return out.child_get_string('root-volume')
def get_share(self, name):
"""
Return a Share object representing the existing CIFS share of name.
If share does not exist, return False.
"""
if self.has_share(name):
return(Share(self, name))
else:
return False
def get_shares(self):
"""Return a list of Share objects containing filer's CIFS exports."""
out = self.invoke_cli('cifs', 'shares')
# Pattern of output is two header lines, followed by each share name
# starting at the left-hand side of the output. Regexp accounts
# For share name being able to include whitespace and other
# characters - match is anchored on first "/" following whitespace,
# which is presumed to be the start of the mount point.
output = out.child_get('cli-output').element['content'].splitlines()
share_pattern = re.compile(r'^([a-zA-Z].*\S)\s+\/')
shares = []
for line in output[2:]:
m = share_pattern.match(line)
if m:
shares.append(Share(self, m.groups()[0]))
return shares
def get_option(self, name):
"""Equivalent to 'options <name>' on the CLI."""
out = self.invoke('options-get', 'name', name)
return out.child_get_string('value')
def get_volume(self, name):
"""Return FlexVol object of existing vol 'name'; else return False."""
if self.has_volume(name):
return(FlexVol(self, name))
else:
return False
def get_volumes(self):
"""Retun a list of FlexVol objects that exist on filer."""
volumes = []
out = self.invoke('volume-list-info')
for volume in out.child_get('volumes').children_get():
name = volume.child_get_string('name')
volumes.append(FlexVol(self, name))
return volumes
def has_export(self, path):
"""Check if filer has NFS export name; return boolean."""
export = Export(self, path)
return export.configured()
def has_share(self, name):
"""Check if filer has CIFS share name; return boolean."""
share = Share(self, name)
return share.configured()
def has_volume(self, name):
"""Check if filer has FlexVol name; return boolean."""
try:
self.invoke('volume-list-info', 'volume', name)
except OntapApiException as e:
if e.errno == '13040':
return False
else:
raise
return True
def invoke(self, *args):
out = self.api.invoke(*args)
if out.results_status() == 'failed':
raise OntapApiException(out.results_errno(), out.results_reason())
return out
def invoke_cli(self, *cli_args):
"""
Call the unsupported/undocumented system-cli API.
args is a tuple of arguments that, joined with spaces, would represent
the command line if executing in the CLI.
"""
args = NaElement('args')
for arg in cli_args:
args.child_add(NaElement('arg', arg))
cli = NaElement('system-cli')
cli.child_add(args)
out = self.api.invoke_elem(cli)
if out.results_status() == 'failed':
raise OntapApiException(out.results_errno(), out.results_reason())
return out
def invoke_elem(self, naelement):
"""Call the NetApp API using an NaElement."""
out = self.api.invoke_elem(naelement)
if out.results_status() == 'failed':
raise OntapApiException(out.results_errno(), out.results_reason())
return out
def set_cifs_homedirs(self, homedirs):
"""Set the list of CIFS home directory paths for the filer."""
homedir_paths = NaElement('homedir-paths')
for d in homedirs:
homedir_paths.child_add(NaElement('homedir-path-info', d))
chps = NaElement('cifs-homedir-paths-set')
chps.child_add(homedir_paths)
self.invoke_elem(chps)
def set_option(self, option, value):
"""Equivalent to 'options <option> <value>' on the CLI."""
self.invoke('options-set', 'name', option, 'value', value)
def _xmltree_to_dict(self, out, int_values=(), key='name', value='value'):
"""Convert thinly-veiled XML from ONTAP API to a dict."""
options = {}
for option in out.child_get('options').children_get():
name = option.child_get_string(key)
if name in int_values:
options[name] = option.child_get_int(value)
else:
options[name] = option.child_get_string(value)
return options
def _xmltree_to_list(self, nae, outer_name, inner_name):
"""
Return list converted from ONTAP API NaElement 'nae'.
nae - NaElement from ONTAP API
outer_name - outer 'child' of NaElement
inner_name - inner 'child' of NaElement
"""
out_list = []
if nae.child_get(outer_name):
for item in nae.child_get(outer_name).children_get():
inner_val = item.child_get_string(inner_name)
if inner_val is not None:
out_list.append(inner_val)
return out_list
class Aggr:
"""An aggregate on a NetApp filer."""
def __init__(self, filer, name):
self.filer = filer
self.name = name
def get_space(self):
out = self.filer.invoke('aggr-list-info', 'aggregate', self.name)
space_info = out.child_get('aggregates').child_get('aggr-info').child_get('aggregate-space-details').child_get('aggregate-space-info').child_get('aggregate-space').child_get('fs-space-info')
return self.parse_space_info(space_info)
def parse_space_info(self, space_info):
"""Parse ONTAP fs-space-info, return dict with contents."""
info = {}
info['fs-size-total'] = space_info.child_get_int('fs-size-total')
info['fs-size-used'] = space_info.child_get_int('fs-size-used')
info['fs-size-available'] = space_info.child_get_int(
'fs-size-available')
info['fs-percent-used-capacity'] = space_info.child_get_int(
'fs-percent-used-capacity')
info['fs-files-total'] = space_info.child_get_int('fs-files-total')
info['fs-files-used'] = space_info.child_get_int('fs-files-used')
info['fs-percent-inode-used-capacity'] = space_info.child_get_int(
'fs-percent-inode-used-capacity')
info['fs-maxfiles-available'] = space_info.child_get_int(
'fs-maxfiles-available')
info['fs-maxfiles-used'] = space_info.child_get_int(
'fs-maxfiles-used')
info['fs-maxfiles-possible'] = space_info.child_get_int(
'fs-maxfiles-possible')
info['fs-files-private-used'] = space_info.child_get_int(
'fs-files-private-used')
info['fs-inodefile-public-capacity'] = space_info.child_get_int(
'fs-inodefile-public-capacity')
info['fs-inodefile-private-capacity'] = space_info.child_get_int(
'fs-inodefile-private-capacity')
info['fs-sis-percent-saved'] = space_info.child_get_int(
'fs-sis-percent-saved')
info['fs-sis-shared-space'] = space_info.child_get_int(
'fs-sis-shared-space')
info['fs-sis-saved-space'] = space_info.child_get_int(
'fs-sis-saved-space')
return info
class Export:
"""An NFS export on a NetApp Filer."""
def __init__(self, filer, path):
self.filer = filer
self.path = path
def configured(self):
"""
Determine if export at self.path has been configured on filer.
Return boolean.
"""
if self._get_rules():
return True
else:
return False
def create_rule(self, nosuid=True, root_hosts = [], ro_hosts = [],
rw_hosts = [], sec_flavor = 'sys'):
"""
Create new exportfs rule for an NFS share.
This method follows the semantics of the NetApp API for
default values, namely: 'By default, if no 'read-only' or
'read-write' hosts are given, then 'read-write' [access is
granted to all hosts].'
"""
# Parse arguments:
if nosuid:
nosuid_val = 'true'
else:
nosuid_val = 'false'
#
# Construct NaElement tree:
#
rule_info = NaElement('exports-rule-info')
rule_info.child_add(NaElement('nosuid', nosuid_val))
rule_info.child_add(NaElement('pathname', self.path))
host_lists = { 'root': root_hosts,
'read-only': ro_hosts,
'read-write': rw_hosts }
for elem in host_lists:
if len(host_lists[elem]) > 0:
nae = NaElement(elem)
for host in host_lists[elem]:
ehi = NaElement('exports-hostname-info')
ehi.child_add(NaElement('name', host))
nae.child_add(ehi)
rule_info.child_add(nae)
nfs_export = NaElement('nfs-exportfs-append-rules')
nfs_export.child_add(NaElement('persistent', 'true'))
rules = NaElement('rules')
rules.child_add(rule_info)
nfs_export.child_add(rules)
# Execute rule change:
self.filer.invoke_elem(nfs_export)
def delete_rule(self):
"""Remove the exportfs rule for a share."""
#
# Construct NaElement tree:
#
pathname_info = NaElement('pathname-info')
pathname_info.child_add(NaElement('name', self.path))
pathnames = NaElement('pathnames')
pathnames.child_add(pathname_info)
elem = NaElement('nfs-exportfs-delete-rules')
elem.child_add(NaElement('persistent', 'true'))
elem.child_add(pathnames)
# Execute it:
self.filer.invoke_elem(elem)
def get_nosuid(self):
"""
Return boolean reflecting nosuid setting on export.
From ONTAP API docs on nosuid setting: 'If true, causes the
server file system to silently ignore any attempt to enable
the setuid or setgid mode bits. Default value is false.'
If export does not exist, return an empty string.
"""
rules = self._get_rules()
if rules:
if rules.child_get('nosuid'):
if rules.child_get_string('nosuid') == 'true':
return True
else:
return False
else:
return False
else:
return ''
def get_ro_hosts(self):
"""
Return list of hosts permitted read-only access.
If export does not exist, return an empty list.
"""
rules = self._get_rules()
if rules:
return self.filer._xmltree_to_list(rules, 'read-only', 'name')
else:
return []
def get_rw_hosts(self):
"""Return list of hosts permitted read/write access."""
rules = self._get_rules()
return self.filer._xmltree_to_list(rules, 'read-write', 'name')
def get_root_hosts(self):
"""Return list of hosts permitted root access."""
rules = self._get_rules()
return self.filer._xmltree_to_list(rules, 'root', 'name')
def get_sec_flavor(self):
"""Return the security 'flavor' of the NFS export."""
rules = self._get_rules()
return rules.child_get('sec-flavor').child_get(
'sec-flavor-info').child_get_string('flavor')
def modify_rule(self, nosuid=True, root_hosts = [], ro_hosts = [],
rw_hosts = [], sec_flavor = 'sys'):
"""
Change the exportfs rule for an NFS share.
This method follows the semantics of the NetApp API for
default values, namely: 'By default, if no 'read-only' or
'read-write' hosts are given, then 'read-write' [access is
granted to all hosts].'
The exportfs rule must already exist before calling this method, or
an exception will be thrown.
"""
# Parse arguments:
if nosuid:
nosuid_val = 'true'
else:
nosuid_val = 'false'
#
# Construct NaElement tree:
#
rule_info = NaElement('exports-rule-info')
rule_info.child_add(NaElement('nosuid', nosuid_val))
rule_info.child_add(NaElement('pathname', self.path))
host_lists = { 'root': root_hosts,
'read-only': ro_hosts,
'read-write': rw_hosts }
for elem in host_lists:
if len(host_lists[elem]) > 0:
nae = NaElement(elem)
for host in host_lists[elem]:
ehi = NaElement('exports-hostname-info')
ehi.child_add(NaElement('name', host))
nae.child_add(ehi)
rule_info.child_add(nae)
nfs_export = NaElement('nfs-exportfs-modify-rule')
nfs_export.child_add(NaElement('persistent', 'true'))
rule = NaElement('rule')
rule.child_add(rule_info)
nfs_export.child_add(rule)
# Execute rule change:
self.filer.invoke_elem(nfs_export)
def _get_rules(self):
"""
Return an NaElement containing the 'exports-rule-info'.
If there is no 'exports-rule-info', return False.
"""
out = self.filer.invoke('nfs-exportfs-list-rules',
'pathname', self.path)
try:
return out.child_get('rules').child_get('exports-rule-info')
except AttributeError:
return False
else:
raise
class FlexVol:
"""A FlexVol on a NetApp Filer."""
def __init__(self, filer, name):
self.filer = filer
m = re.match('^/vol/(.+)$', name)
if m:
name = m.groups()[0]
self.name = name
self.path = '/vol/' + name
def create(self, aggr, size):
self.filer.invoke('volume-create',
'volume', self.name,
'containing-aggr-name', aggr,
'size', size)
def autosize_is_enabled(self):
out = self.filer.invoke('volume-autosize-get', 'volume', self.name)
if out.child_get_string('is-enabled') == 'true':
return True
else:
return False
def sis_is_enabled(self):
try:
out = self.filer.invoke('sis-status', 'path', self.path)
except OntapApiException as e:
if e.errno == '13001':
return False
else:
raise
state = out.child_get('sis-object').child_get('dense-status').child_get_string('state')
if state == 'Enabled':
return True
else:
return False
def del_sv_pri_snap_sched(self, schedule_name):
"""Delete a SnapVault primary snapshot schedule."""
self.filer.invoke('snapvault-primary-delete-snapshot-schedule',
'schedule-name', schedule_name,
'volume-name', self.name)
def del_sv_sec_snap_sched(self, schedule_name):
"""Delete a SnapVault secondary snapshot schedule."""
self.filer.invoke('snapvault-secondary-delete-snapshot-schedule',
'schedule-name', schedule_name,
'volume-name', self.name)
def get_autosize_increment(self):
out = self.filer.invoke('volume-autosize-get', 'volume', self.name)
return out.child_get_int('increment-size')
def get_autosize_increment_gb(self):
"""
Return the vol autosize increment rounded to the nearest gigabyte.
Value is returned as a string, suffixed with a 'g' to match Data
ONTAP conventions.
"""
kb = self.get_autosize_increment()
return str(int(round(kb / 1024. / 1024.))) + 'g'
def get_autosize_max_size(self):
out = self.filer.invoke('volume-autosize-get', 'volume', self.name)
return out.child_get_int('maximum-size')
def get_autosize_max_size_gb(self):
"""
Return the vol autosize maximum size rounded to the nearest gigabyte.
Value is returned as a string, suffixed with a 'g' to match Data
ONTAP conventions.
"""
kb = self.get_autosize_max_size()
return str(int(round(kb / 1024. / 1024.))) + 'g'
def get_df(self):
"""
Return an array containing space used, available and total space.
Values are returned as integers, representing bytes. Note
that values for total space are after snapshot reserve (if
any), similar to how 'df' works on the CLI.
"""
out = self.filer.invoke('volume-list-info', 'volume', self.name)
used = out.child_get('volumes').child_get(
'volume-info').child_get_int('size-used')
avail = out.child_get('volumes').child_get(
'volume-info').child_get_int('size-available')
total = out.child_get('volumes').child_get(
'volume-info').child_get_int('size-total')
return([used, avail, total])
def get_options(self):
"""Equivalent to: vol options <self.name>
Returns a dict comprised of the volume's options. Note that the API
returns options beyond what 'vol options' returns in the ONTAP
CLI."""
out = self.filer.invoke('volume-options-list-info',
'volume', self.name)
# option values that should be integers; the rest are strings:
int_values = ('fractional_reserve', 'maxdirsize',
'max_write_alloc_blocks', 'raidsize', 'resyncsnaptime')
return self.filer._xmltree_to_dict(out, int_values)
def get_priority_cache_policy(self):
"""Return the FlexShare cache policy for the volume."""
try:
out = self.filer.invoke('priority-list-info-volume',
'volume', self.name)
except OntapApiException as e:
# If volume doesn't have a priority schedule, it is default:
if e.reason == 'unable to find volume' and e.errno == '2':
return 'default'
else:
raise
pri_vol = out.child_get('priority-volume').child_get(
'priority-volume.info')
return pri_vol.child_get_string('cache-policy')
def get_security_style(self):
"""Return the security stle (unix, ntfs, mixed) of the volume."""
out = self.filer.invoke('qtree-list', 'volume', self.name)
for qtree in out.child_get('qtrees').children_get():
if qtree.child_get_string('qtree') == '':
return qtree.child_get_string('security-style')
def get_sis_state(self):
"""Get deduplication state; return 'Enabled' or 'Disabled'."""
try:
out = self.filer.invoke('sis-status', 'path', self.path)
except OntapApiException as e:
if e.errno == '13001':
return 'Disabled'
else:
raise
return out.child_get('sis-object').child_get('dense-status').child_get_string('state')
def get_size(self):
out = self.filer.invoke('volume-size', 'volume', self.name)
return out.child_get_string('volume-size')
def get_snap_autodelete(self):
"""Equivalent to: 'snap autodelete <self.name> show'
Returns a dict consisting of the snapshot autodelete options."""
out = self.filer.invoke('snapshot-autodelete-list-info',
'volume', self.name)
# option values that should be integers; the rest are strings:
int_values = ('target_free_space')
return self.filer._xmltree_to_dict(out, int_values, key='option-name',
value='option-value')
def get_snap_reserve(self):
"""Equivalent to: snap reserve <self.name>"""
out = self.filer.invoke('snapshot-get-reserve', 'volume', self.name)
return out.child_get_int('percent-reserved')
def get_snap_sched(self):
"""
Closest equivalent: snap sched <self.name>
Return a dict with the following key-value pairs:
days - The number of snapshots taken daily to keep on line.
hours - The number of snapshots taken hourly to keep on line.
minutes - The number of snapshots taken minutely to keep on line.
weeks - The number of snapshots taken weekly to keep on line.
which-hours - Comma separated string of the hours at which the hourly
snapshots are created.
which-minutes - Comma separated string of the minutes at which the
minutely snapshots are created.
"""
out = self.filer.invoke('snapshot-get-schedule', 'volume', self.name)
sched = {}
for retention in ('days', 'hours', 'minutes', 'weeks'):
sched[retention] = out.child_get_int(retention)
for t in ('which-hours', 'which-minutes'):
sched[t] = out.child_get_string(t)
return sched
def get_state(self):
"""Return state of the volume (online, offline, restricted, etc.)."""
out = self.filer.invoke('volume-list-info', 'volume', self.name)
return out.child_get('volumes').child_get(
'volume-info').child_get_string('state')
def get_sv_pri_snap_sched(self):
"""
Return the snapvault primary snapshot schedule as an array of dicts.
Roughly equivalent to:
snapvault snap sched <self.name>
Each dict in the returned array contains the following keys:
schedule-name - Name of the snap schedule
retention-count - Number of snapshots retained by this schedule
days-of-week - Days of the week schedule will run
hours-of-day - Hours of the day schedule will run, default 0
"""
out = self.filer.invoke(
'snapvault-primary-snapshot-schedule-list-info',
'volume-name', self.name)
scheds = {}
for schedxml in out.child_get('snapshot-schedules').children_get():
sched = {}
name = schedxml.child_get_string('schedule-name')
sched['retention-count'] = schedxml.child_get_int(
'retention-count')
schedinfo = schedxml.child_get('schedule').child_get(
'snapvault-schedule-info')
sched['days-of-week'] = schedinfo.child_get_string('days-of-week')
sched['hours-of-day'] = schedinfo.child_get_string('hours-of-day')
scheds[name] = sched
return scheds
def get_sv_sec_snap_sched(self):
"""
Return the snapvault secondary snapshot schedule as an array of dicts.
Roughly equivalent to:
snapvault snap sched <self.name>
Each dict in the returned array contains the following keys:
schedule-name - Name of the snap schedule
retention-count - Number of snapshots retained by this schedule
days-of-week - Days of the week schedule will run
hours-of-day - Hours of the day schedule will run, default 0
is-auto-update - boolean - Schedule initiates xfer before snap create?
"""
out = self.filer.invoke(
'snapvault-secondary-snapshot-schedule-list-info',
'volume-name', self.name)
scheds = {}
for schedxml in out.child_get('snapshot-schedules').children_get():
sched = {}
name = schedxml.child_get_string('schedule-name')
sched['retention-count'] = schedxml.child_get_int(
'retention-count')
schedinfo = schedxml.child_get('schedule').child_get(
'snapvault-schedule-info')
sched['days-of-week'] = schedinfo.child_get_string('days-of-week')
sched['hours-of-day'] = schedinfo.child_get_string('hours-of-day')
iau = schedxml.child_get_string('is-auto-update')
if iau == 'true':
sched['is-auto-update'] = True
else:
sched['is-auto-update'] = False
scheds[name] = sched
return scheds
def has_snap(self, snap_name):
"""Return boolean of whether FlexVol has snapshot 'snap_name'."""
out = self.filer.invoke('snapshot-list-info',
'target-name', self.name,
'target-type', 'volume')
for s in out.child_get('snapshots').children_get():
if s.child_get_string('name') == snap_name:
return True
return False
def set_autosize_state(self,
enabled,
increment_size = False,
maximum_size = False):
"""
Enable, disable or configure autosize for a FlexVol.
Arguments:
enabled -- Boolean: Turn autosize on or off
increment_size -- Increment size for growing FlexVol (string)
maximum_size -- Limit to which FlexVol will grow (string)
increment_size and maximum_size may be suffixed with a 'k', 'm', 'g' or
't' to indicate KB, MB, GB or TB, respectively. If there is no suffix,
the values are treated as being in KB.
"""
if enabled:
self.filer.invoke('volume-autosize-set',
'volume', self.name,
'is-enabled', 'true')
else:
self.filer.invoke('volume-autosize-set',
'volume', self.name,
'is-enabled', 'false')
if increment_size:
self.filer.invoke('volume-autosize-set',
'volume', self.name,
'increment-size', increment_size)
if maximum_size:
self.filer.invoke('volume-autosize-set',
'volume', self.name,
'maximum-size', maximum_size)