-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathclient.py
More file actions
5073 lines (4452 loc) · 222 KB
/
client.py
File metadata and controls
5073 lines (4452 loc) · 222 KB
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
# (c) Copyright 2012-2016 Hewlett Packard Enterprise Development LP
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
""" HPE 3PAR REST Client.
.. module: client
.. moduleauthor: Walter A. Boring IV
.. moduleauthor: Kurt Martin
:Author: Walter A. Boring IV
:Description: This is the 3PAR Client that talks to 3PAR's REST WSAPI Service.
It provides the ability to provision 3PAR volumes, VLUNs, CPGs. This version
also supports running actions on the 3PAR that use SSH.
This client requires and works with 3PAR InForm 3.1.3 MU1 firmware
"""
import copy
import re
import time
import uuid
import logging
try:
# For Python 3.0 and later
from urllib.parse import quote
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import quote
from hpe3parclient import exceptions, http, ssh
from hpe3parclient import showport_parser
logger = logging.getLogger(__name__)
class HPE3ParClient(object):
""" The 3PAR REST API Client.
:param api_url: The url to the WSAPI service on 3PAR
ie. http://<3par server>:8080/api/v1
:type api_url: str
"""
CHAP_INITIATOR = 1
CHAP_TARGET = 2
PORT_MODE_TARGET = 2
PORT_MODE_INITIATOR = 3
PORT_MODE_PEER = 4
PORT_TYPE_HOST = 1
PORT_TYPE_DISK = 2
PORT_TYPE_FREE = 3
PORT_TYPE_IPORT = 4
PORT_TYPE_RCFC = 5
PORT_TYPE_PEER = 6
PORT_TYPE_RCIP = 7
PORT_TYPE_ISCSI = 8
PORT_TYPE_CNA = 9
PORT_PROTO_FC = 1
PORT_PROTO_ISCSI = 2
PORT_PROTO_FCOE = 3
PORT_PROTO_IP = 4
PORT_PROTO_SAS = 5
PORT_STATE_READY = 4
PORT_STATE_SYNC = 5
PORT_STATE_OFFLINE = 10
SET_MEM_ADD = 1
SET_MEM_REMOVE = 2
SET_RESYNC_PHYSICAL_COPY = 3
SET_STOP_PHYSICAL_COPY = 4
STOP_PHYSICAL_COPY = 1
RESYNC_PHYSICAL_COPY = 2
GROW_VOLUME = 3
PROMOTE_VIRTUAL_COPY = 4
VIRTUAL_COPY = 3
UPDATE_VIRTUAL_COPY = 7
TUNE_VOLUME = 6
TPVV = 1
FPVV = 2
TDVV = 3
CONVERT_TO_DECO = 4
TARGET_TYPE_VVSET = 1
TARGET_TYPE_SYS = 2
PRIORITY_LOW = 1
PRIORITY_NORMAL = 2
PRIORITY_HIGH = 3
TASK_TYPE_VV_COPY = 1
TASK_TYPE_PHYS_COPY_RESYNC = 2
TASK_TYPE_MOVE_REGIONS = 3
TASK_TYPE_PROMOTE_SV = 4
TASK_TYPE_REMOTE_COPY_SYNC = 5
TASK_TYPE_REMOTE_COPY_REVERSE = 6
TASK_TYPE_REMOTE_COPY_FAILOVER = 7
TASK_TYPE_REMOTE_COPY_RECOVER = 8
TASK_TYPE_REMOTE_COPY_RESTORE = 9
TASK_TYPE_COMPACT_CPG = 10
TASK_TYPE_COMPACT_IDS = 11
TASK_TYPE_SNAPSHOT_ACCOUNTING = 12
TASK_TYPE_CHECK_VV = 13
TASK_TYPE_SCHEDULED_TASK = 14
TASK_TYPE_SYSTEM_TASK = 15
TASK_TYPE_BACKGROUND_TASK = 16
TASK_TYPE_IMPORT_VV = 17
TASK_TYPE_ONLINE_COPY = 18
TASK_TYPE_CONVERT_VV = 19
TASK_DONE = 1
TASK_ACTIVE = 2
TASK_CANCELLED = 3
TASK_FAILED = 4
# build contains major minor mj=3 min=01 main=03 build=230
# When updating these, make sure desc is appropriate for error messages
# and make sure the version overrides in file_client are still OK.
HPE3PAR_WS_MIN_BUILD_VERSION = 30103230
HPE3PAR_WS_MIN_BUILD_VERSION_DESC = '3.1.3 MU1'
HPE3PAR_WS_PRIMERA_MIN_BUILD_VERSION = 40000128
HPE3PAR_WS_PRIMERA_MIN_BUILD_VERSIONDESC = '4.2.0'
# Minimum build version needed for VLUN query support.
HPE3PAR_WS_MIN_BUILD_VERSION_VLUN_QUERY = 30201292
HPE3PAR_WS_MIN_BUILD_VERSION_VLUN_QUERY_DESC = '3.2.1 MU2'
WSAPI_MIN_VERSION_COMPRESSION_SUPPORT = '1.6.0'
VLUN_TYPE_EMPTY = 1
VLUN_TYPE_PORT = 2
VLUN_TYPE_HOST = 3
VLUN_TYPE_MATCHED_SET = 4
VLUN_TYPE_HOST_SET = 5
VLUN_MULTIPATH_UNKNOWN = 1
VLUN_MULTIPATH_ROUND_ROBIN = 2
VLUN_MULTIPATH_FAILOVER = 3
CPG_RAID_R0 = 1 # RAID 0
CPG_RAID_R1 = 2 # RAID 1
CPG_RAID_R5 = 3 # RAID 5
CPG_RAID_R6 = 4 # RAID 6
CPG_HA_PORT = 1 # Support failure of a port.
CPG_HA_CAGE = 2 # Support failure of a drive cage.
CPG_HA_MAG = 3 # Support failure of a drive magazine.
# Lowest numbered available chunklets, where transfer rate is the fastest.
CPG_CHUNKLET_POS_PREF_FIRST = 1
# Highest numbered available chunklets, where transfer rate is the slowest.
CPG_CHUNKLET_POS_PREF_LAST = 2
CPG_DISK_TYPE_FC = 1 # Fibre Channel
CPG_DISK_TYPE_NL = 2 # Near Line
CPG_DISK_TYPE_SSD = 3 # SSD
HOST_EDIT_ADD = 1
HOST_EDIT_REMOVE = 2
HOST_PERSONA_GENERIC = 1
HOST_PERSONA_GENERIC_ALUA = 2
HOST_PERSONA_GENERIC_LEGACY = 3
HOST_PERSONA_HPUX_LEGACY = 4
HOST_PERSONA_AIX_LEGACY = 5
HOST_PERSONA_EGENERA = 6
HOST_PERSONA_ONTAP_LEGACY = 7
HOST_PERSONA_VMWARE = 8
HOST_PERSONA_OPENVMS = 9
HOST_PERSONA_HPUX = 10
HOST_PERSONA_WINDOWS_SERVER = 11
CHAP_OPERATION_MODE_INITIATOR = 1
CHAP_OPERATION_MODE_TARGET = 2
FLASH_CACHE_ENABLED = 1
FLASH_CACHE_DISABLED = 2
RC_ACTION_CHANGE_DIRECTION = 6
RC_ACTION_CHANGE_TO_PRIMARY = 7
RC_ACTION_MIGRATE_GROUP = 8
RC_ACTION_CHANGE_TO_SECONDARY = 9
RC_ACTION_CHANGE_TO_NATURUAL_DIRECTION = 10
RC_ACTION_OVERRIDE_FAIL_SAFE = 11
def __init__(self, api_url, debug=False, secure=False, timeout=None,
suppress_ssl_warnings=False):
self.api_url = api_url
self.http = http.HTTPJSONRESTClient(
self.api_url, secure=secure,
timeout=timeout, suppress_ssl_warnings=suppress_ssl_warnings)
api_version = None
self.ssh = None
self.vlun_query_supported = False
self.primera_supported = False
self.compression_supported = False
self.debug_rest(debug)
try:
api_version = self.getWsApiVersion()
except exceptions as ex:
ex_desc = ex.get_description()
if (ex_desc and ("Unable to find the server at" in ex_desc or
"Only absolute URIs are allowed" in ex_desc)):
raise exceptions.HTTPBadRequest(ex_desc)
if (ex_desc and "SSL Certificate Verification Failed" in ex_desc):
raise exceptions.SSLCertFailed()
else:
msg = ('Error: \'%s\' - Error communicating with the 3PAR WS. '
'Check proxy settings. If error persists, either the '
'3PAR WS is not running or the version of the WS is '
'not supported.') % ex_desc
raise exceptions.UnsupportedVersion(msg)
# Note the build contains major, minor, maintenance and build
# e.g. 30102422 is 3 01 02 422
# therefore all we need to compare is the build
if (api_version is None or
api_version['build'] < self.HPE3PAR_WS_MIN_BUILD_VERSION):
raise exceptions.UnsupportedVersion(
'Invalid 3PAR WS API, requires version, %s' %
self.HPE3PAR_WS_MIN_BUILD_VERSION_DESC)
# Check for VLUN query support.
if (api_version['build'] >=
self.HPE3PAR_WS_MIN_BUILD_VERSION_VLUN_QUERY):
self.vlun_query_supported = True
if (api_version['build'] >=
self.HPE3PAR_WS_PRIMERA_MIN_BUILD_VERSION):
self.primera_supported = True
current_wsapi_version = '{}.{}.{}'.format(api_version.get('major'),
api_version.get('minor'),
api_version.get('revision'))
if current_wsapi_version >= self.WSAPI_MIN_VERSION_COMPRESSION_SUPPORT:
self.compression_supported = True
def is_primera_array(self):
return self.primera_supported
def setSSHOptions(self, ip, login, password, port=22,
conn_timeout=None, privatekey=None,
**kwargs):
"""Set SSH Options for ssh calls.
This is used to set the SSH credentials for calls
that use SSH instead of REST HTTP.
"""
self.ssh = ssh.HPE3PARSSHClient(ip, login, password, port,
conn_timeout, privatekey,
**kwargs)
def _run(self, cmd):
if self.ssh is None:
raise exceptions.SSHException('SSH is not initialized. Initialize'
' it by calling "setSSHOptions".')
else:
self.ssh.open()
return self.ssh.run(cmd)
def getWsApiVersion(self):
"""Get the 3PAR WS API version.
:returns: Version dict
"""
try:
# remove everything down to host:port
host_url = self.api_url.split('/api')
self.http.set_url(host_url[0])
# get the api version
response, body = self.http.get('/api')
return body
finally:
# reset the url
self.http.set_url(self.api_url)
def debug_rest(self, flag):
"""This is useful for debugging requests to 3PAR.
:param flag: set to True to enable debugging
:type flag: bool
"""
self.http.set_debug_flag(flag)
if self.ssh:
self.ssh.set_debug_flag(flag)
def login(self, username, password, optional=None):
"""This authenticates against the 3PAR wsapi server and creates a
session.
:param username: The username
:type username: str
:param password: The Password
:type password: str
:returns: None
"""
self.http.authenticate(username, password, optional)
def logout(self):
"""This destroys the session and logs out from the 3PAR server.
The SSH connection to the 3PAR server is also closed.
:returns: None
"""
self.http.unauthenticate()
if self.ssh:
self.ssh.close()
def getStorageSystemInfo(self):
"""Get the Storage System Information
:returns: Dictionary of Storage System Info
"""
response, body = self.http.get('/system')
return body
def getWSAPIConfigurationInfo(self):
"""Get the WSAPI Configuration Information.
:returns: Dictionary of WSAPI configurations
"""
response, body = self.http.get('/wsapiconfiguration')
return body
def getOverallSystemCapacity(self):
"""Get the overall system capacity for the 3PAR server.
:returns: Dictionary of system capacity information
.. code-block:: python
capacity = {
"allCapacity": { # Overall system capacity
# includes FC, NL, SSD
# device types
"totalMiB": 20054016, # Total system capacity
# in MiB
"allocated": { # Allocated space info
"totalAllocatedMiB": 12535808, # Total allocated
# capacity
"volumes": { # Volume capacity info
"totalVolumesMiB": 10919936, # Total capacity
# allocated to volumes
"nonCPGsMiB": 0, # Total non-CPG capacity
"nonCPGUserMiB": 0, # The capacity allocated
# to non-CPG user space
"nonCPGSnapshotMiB": 0, # The capacity allocated
# to non-CPG snapshot
# volumes
"nonCPGAdminMiB": 0, # The capacity allocated
# to non-CPG
# administrative volumes
"CPGsMiB": 10919936, # Total capacity
# allocated to CPGs
"CPGUserMiB": 7205538, # User CPG space
"CPGUserUsedMiB": 7092550, # The CPG allocated to
# user space that is
# in use
"CPGUserUnusedMiB": 112988, # The CPG allocated to
# user space that is not
# in use
"CPGSnapshotMiB": 2411870, # Snapshot CPG space
"CPGSnapshotUsedMiB": 210256, # CPG allocated to
# snapshot that is in use
"CPGSnapshotUnusedMiB": 2201614, # CPG allocated to
# snapshot space that is
# not in use
"CPGAdminMiB": 1302528, # Administrative volume
# CPG space
"CPGAdminUsedMiB": 115200, # The CPG allocated to
# administrative space
# that is in use
"CPGAdminUnusedMiB": 1187328, # The CPG allocated to
# administrative space
# that is not in use
"unmappedMiB": 0 # Allocated volume space
# that is unmapped
},
"system": { # System capacity info
"totalSystemMiB": 1615872, # System space capacity
"internalMiB": 780288, # The system capacity
# allocated to internal
# resources
"spareMiB": 835584, # Total spare capacity
"spareUsedMiB": 0, # The system capacity
# allocated to spare resources
# in use
"spareUnusedMiB": 835584 # The system capacity
# allocated to spare resources
# that are unused
}
},
"freeMiB": 7518208, # Free capacity
"freeInitializedMiB": 7518208, # Free initialized capacity
"freeUninitializedMiB": 0, # Free uninitialized capacity
"unavailableCapacityMiB": 0, # Unavailable capacity in MiB
"failedCapacityMiB": 0 # Failed capacity in MiB
},
"FCCapacity": { # System capacity from FC devices only
... # Same structure as above
},
"NLCapacity": { # System capacity from NL devices only
... # Same structure as above
},
"SSDCapacity": { # System capacity from SSD devices only
... # Same structure as above
}
}
"""
response, body = self.http.get('/capacity')
return body
# Volume methods
def getVolumes(self):
"""Get the list of Volumes
:returns: list of Volumes
"""
response, body = self.http.get('/volumes')
return body
def getVolume(self, name):
"""Get information about a volume.
:param name: The name of the volume to find
:type name: str
:returns: volume
:raises: :class:`~hpe3parclient.exceptions.HTTPNotFound`
- NON_EXISTENT_VOL - volume doesn't exist
"""
response, body = self.http.get('/volumes/%s' % name)
return body
def createVolume(self, name, cpgName, sizeMiB, optional=None):
"""Create a new volume.
For the primera array there is support for only thin and DECO volume.
To create DECO volume 'tdvv' and 'compression' both must be True.
If only one of them is specified, it results in HTTPBadRequest.
:param name: the name of the volume
:type name: str
:param cpgName: the name of the destination CPG
:type cpgName: str
:param sizeMiB: size in MiB for the volume
:type sizeMiB: int
:param optional: dict of other optional items
:type optional: dict
.. code-block:: python
optional = {
'id': 12, # Volume ID. If not specified, next
# available is chosen
'comment': 'some comment', # Additional information up to 511
# characters
'policies: { # Specifies VV policies
'staleSS': False, # True allows stale snapshots.
'oneHost': True, # True constrains volume export to
# single host or host cluster
'zeroDetect': True, # True requests Storage System to
# scan for zeros in incoming write
# data
'system': False, # True special volume used by system
# False is normal user volume
'caching': True}, # Read-only. True indicates write &
# read caching & read ahead enabled
'snapCPG': 'CPG name', # CPG Used for snapshots
'ssSpcAllocWarningPct': 12, # Snapshot space allocation warning
'ssSpcAllocLimitPct': 22, # Snapshot space allocation limit
'tpvv': True, # True: Create TPVV
# False (default) Create FPVV
'usrSpcAllocWarningPct': 22, # Enable user space allocation
# warning
'usrSpcAllocLimitPct': 22, # User space allocation limit
'expirationHours': 256, # Relative time from now to expire
# volume (max 43,800 hours)
'retentionHours': 256 # Relative time from now to retain
# volume (max 43,800 hours)
}
:returns: List of Volumes
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT - Invalid Parameter
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- TOO_LARGE - Volume size above limit
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- NO_SPACE - Not Enough space is available
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- PERM_DENIED - Permission denied
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- EXISTENT_SV - Volume Exists already
"""
info = {'name': name, 'cpg': cpgName, 'sizeMiB': sizeMiB}
# For primera array there is no compression and tdvv keys
# removing tdvv, compression and
# replacing compression+tdvv with reduce key for DECO
if not optional and self.primera_supported:
optional = {'tpvv': True}
if optional:
if self.primera_supported:
for key in ['tpvv', 'compression', 'tdvv']:
option = optional.get(key)
if option and option not in [True, False]:
# raising exception for junk compression input
ex_desc = "39 - invalid input: wrong type for key "\
"[%s]. Valid values are [True, False]" % key
raise exceptions.HTTPBadRequest(ex_desc)
if optional.get('compression') is True:
combination = ['tdvv', 'compression']
len_diff = len(set(combination) - set(optional.keys()))
msg = "invalid input: For compressed and deduplicated "\
"volumes both 'compression' and " \
"'tdvv' must be specified as true"
if len_diff == 1:
raise exceptions.HTTPBadRequest(msg)
if optional.get('tdvv') is True \
and optional.get('compression') is True:
optional['reduce'] = True
if optional.get('tdvv') is False \
and optional.get('compression') is True:
raise exceptions.HTTPBadRequest(msg)
else:
msg = "invalid input: For compressed and deduplicated "\
"volumes both 'compression' and "\
"'tdvv' must be specified as true"
if optional.get('tdvv') is False \
and optional.get('compression') is False:
optional['reduce'] = False
if optional.get('tdvv') is True \
and optional.get('compression') is False:
raise exceptions.HTTPBadRequest(msg)
if 'compression' in optional:
optional.pop('compression')
if 'tdvv' in optional:
optional.pop('tdvv')
info = self._mergeDict(info, optional)
logger.debug("Parameters passed for create volume %s" % info)
try:
response, body = self.http.post('/volumes', body=info)
return body
except exceptions.HTTPBadRequest as ex:
if self.primera_supported:
ex_desc = 'invalid input: one of the parameters is required'
ex_code = ex.get_code()
# INV_INPUT_ONE_REQUIRED => 78
if ex_code == 78 and \
ex.get_description() == ex_desc and \
ex.get_ref() == 'tpvv,reduce':
new_ex_desc = "invalid input: Either tpvv must be true "\
"OR for compressed and deduplicated "\
"volumes both 'compression' and 'tdvv' "\
"must be specified as true"
raise exceptions.HTTPBadRequest(new_ex_desc)
raise ex
def deleteVolume(self, name):
"""Delete a volume.
:param name: the name of the volume
:type name: str
:raises: :class:`~hpe3parclient.exceptions.HTTPNotFound`
- NON_EXISTENT_VOL - The volume does not exist
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- PERM_DENIED - Permission denied
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- RETAINED - Volume retention time has not expired
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- HAS_RO_CHILD - Volume has read-only child
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- HAS_CHILD - The volume has a child volume
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- IN_USE - The volume is in use by VV set, VLUN, etc
"""
response, body = self.http.delete('/volumes/%s' % name)
return body
def modifyVolume(self, name, volumeMods, appType=None):
"""Modify a volume.
:param name: the name of the volume
:type name: str
:param volumeMods: dictionary of volume attributes to change
:type volumeMods: dict
.. code-block:: python
volumeMods = {
'newName': 'newName', # New volume name
'comment': 'some comment', # New volume comment
'snapCPG': 'CPG name', # Snapshot CPG name
'policies: { # Specifies VV policies
'staleSS': False, # True allows stale snapshots.
'oneHost': True, # True constrains volume export to
# single host or host cluster
'zeroDetect': True, # True requests Storage System to
# scan for zeros in incoming write
# data
'system': False, # True special volume used by system
# False is normal user volume
'caching': True}, # Read-only. True indicates write &
# read caching & read ahead enabled
'ssSpcAllocWarningPct': 12, # Snapshot space allocation warning
'ssSpcAllocLimitPct': 22, # Snapshot space allocation limit
'tpvv': True, # True: Create TPVV
# False: (default) Create FPVV
'usrSpcAllocWarningPct': 22, # Enable user space allocation
# warning
'usrSpcAllocLimitPct': 22, # User space allocation limit
'userCPG': 'User CPG name', # User CPG name
'expirationHours': 256, # Relative time from now to expire
# volume (max 43,800 hours)
'retentionHours': 256, # Relative time from now to retain
# volume (max 43,800 hours)
'rmSsSpcAllocWarning': False, # True removes snapshot space
# allocation warning.
# False sets it when value > 0
'rmUsrSpcAllocWarwaning': False, # True removes user space
# allocation warning.
# False sets it when value > 0
'rmExpTime': False, # True resets expiration time to 0.
# False sets it when value > 0
'rmSsSpcAllocLimit': False, # True removes snapshot space
# allocation limit.
# False sets it when value > 0
'rmUsrSpcAllocLimit': False # True removes user space
# allocation limit.
# False sets it when value > 0
}
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_WARN_GT_LIMIT - Allocation warning level is higher than
the limit.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_USR_ALRT_NON_TPVV - User space allocation alerts are
valid only with a TPVV.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_RETAIN_GT_EXPIRE - Retention time is greater than
expiration time.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_VV_POLICY - Invalid policy specification (for example,
caching or system is set to true).
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_EXCEEDS_LENGTH - Invalid input: string length exceeds
limit.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_TIME - Invalid time specified.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_MODIFY_USR_CPG_TPVV - usr_cpg cannot be modified
on a TPVV.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- UNLICENSED_FEATURE - Retention time cannot be modified on a
system without the Virtual Lock license.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- CPG_NOT_IN_SAME_DOMAIN - Snap CPG is not in the same domain as
the user CPG.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_PEER_VOLUME - Cannot modify a peer volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPInternalServerError`
- INT_SERV_ERR - Metadata of the VV is corrupted.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_SYS_VOLUME - Cannot modify retention time on a
system volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_INTERNAL_VOLUME - Cannot modify an internal
volume
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_VOLUME_NOT_DEFINED_ALL_NODES - Cannot modify a
volume until the volume is defined on all volumes.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INVALID_OPERATION_VV_ONLINE_COPY_IN_PROGRESS - Cannot modify a
volume when an online copy for that volume is in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INVALID_OPERATION_VV_VOLUME_CONV_IN_PROGRESS - Cannot modify a
volume in the middle of a conversion operation.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INVALID_OPERATION_VV_SNAPSPACE_NOT_MOVED_TO_CPG - Snapshot space
of a volume needs to be moved to a CPG before the user space.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_VOLUME_ACCOUNTING_IN_PROGRESS - The volume
cannot be renamed until snapshot accounting has finished.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_ZERO_DETECT_TPVV - The zero_detect policy can be
used only on TPVVs.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_CPG_ON_SNAPSHOT - CPG cannot be assigned to a
snapshot.
"""
response = self.http.put('/volumes/%s' % name, body=volumeMods)
if appType is not None:
if 'newName' in volumeMods and volumeMods['newName']:
name = volumeMods['newName']
try:
self.setVolumeMetaData(name, 'hpe_ecosystem_product', appType)
except Exception:
pass
return response
def growVolume(self, name, amount):
"""Grow an existing volume by 'amount' Mebibytes.
:param name: the name of the volume
:type name: str
:param amount: the additional size in MiB to add, rounded up to the
next chunklet size (e.g. 256 or 1000 MiB)
:type amount: int
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_NOT_IN_SAME_DOMAIN - The volume is not in the same domain.
:raises: :class:`~hpe3parclient.exceptions.HTTPNotFound`
- NON_EXISTENT_VOL - The volume does not exist.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_UNSUPPORTED_VV_TYPE - Invalid operation: Cannot
grow this type of volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_TUNE_IN_PROGRESS - Invalid operation: Volume
tuning is in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_EXCEEDS_LENGTH - Invalid input: String length exceeds
limit.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_VV_GROW_SIZE - Invalid grow size.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_NEW_SIZE_EXCEEDS_CPG_LIMIT - New volume size exceeds CPG limit
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_INTERNAL_VOLUME - This operation is not allowed
on an internal volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_VOLUME_CONV_IN_PROGRESS - Invalid operation: VV
conversion is in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_VOLUME_COPY_IN_PROGRESS - Invalid operation:
online copy is in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_CLEANUP_IN_PROGRESS - Internal volume cleanup is
in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_IS_BEING_REMOVED - The volume is being removed.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_IN_INCONSISTENT_STATE - The volume has an internal consistency
error.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_SIZE_CANNOT_REDUCE - New volume size is smaller than the
current size.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_NEW_SIZE_EXCEEDS_LIMITS - New volume size exceeds the limit.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_SA_SD_SPACE_REMOVED - Invalid operation: Volume
SA/SD space is being removed.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_IS_BUSY - Invalid operation: Volume is currently
busy.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_NOT_STARTED - Volume is not started.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_IS_PCOPY - Invalid operation: Volume is a
physical copy.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_NOT_IN_NORMAL_STATE - Volume state is not normal
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_PROMOTE_IN_PROGRESS - Invalid operation: Volume
promotion is in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_PARENT_OF_PCOPY - Invalid operation: Volume is
the parent of physical copy.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- NO_SPACE - Insufficent space for requested operation.
"""
info = {'action': self.GROW_VOLUME,
'sizeMiB': int(amount)}
response, body = self.http.put('/volumes/%s' % name, body=info)
return body
def promoteVirtualCopy(self, snapshot, optional=None):
"""Revert a volume to snapshot.
:param snapshot: the snapshot name
:type snapshot: str
:param optional: Dictionary of optional params
:type optional: dict
.. code-block:: python
optional = {
'online': False, # should execute promote
# operation on online volume?
'allowRemoteCopyParent': 'False',
# allow promote operation if
# volume is in remote copy
# volume group?
'priority': 1 # taskPriorityEnum (does not
# apply to online copy)
}
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_NOT_STARTED - Volume is not started.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_IS_BEING_REMOVED - The volume is being removed.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_IN_STALE_STATE - The volume is in a stale state.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_CANNOT_STOP_ONLINE_PROMOTE - The online
promote cannot be stopped.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_BASE_VOLUME - The volume is a base volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_PCOPY_IN_PROGRESS - The destination volume has
a physical copy in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_PARENT_PCOPY_IN_PROGRESS - The parent is involved
in a physical copy.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_TUNE_IN_PROGRESS - Volume tuning is in
progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_IN_REMOTE_COPY - The volume is involved in
Remote Copy.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_PARENT_VV_EXPORTED - Parent volume is exported.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_EXPORTED - Parent volume is exported.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_PROMOTE_TARGET_NOT_BASE_VV - The promote target is
not a base volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_PARENT_SIZE_HAS_INCREASED - The parent volume size
has increased.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_PARAM_CONFLICT - Parameters cannot be present at
the same time.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_IS_BUSY - Volume is currently busy.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_PROMOTE_IN_PROGRESS - Volume promotion is in
progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_PROMOTE_IS_NOT_IN_PROGRESS - Volume promotion
is not in progress.
"""
info = {'action': self.PROMOTE_VIRTUAL_COPY}
if optional:
info = self._mergeDict(info, optional)
response, body = self.http.put('/volumes/%s' % snapshot, body=info)
return body
def updateVirtualCopy(self, snapshots, readOnly=False):
"""Update a virtual volume snapshot
:param snapshots: the list of snapshot names
:param readOnly: Specifies that if the virtual copy is read-write, the
command updates the read-only parent volume also
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- UNLICENSED_FEATURE: This system is not licensed with promote
"""
if isinstance(snapshots, str):
snapshots = [snapshots, ]
info = {
'action': self.UPDATE_VIRTUAL_COPY,
'parameters': {
'volumeSnapshotList': snapshots,
'readOnly': readOnly
}
}
response, body = self.http.post('/volumes/', body=info)
return body
def copyVolume(self, src_name, dest_name, dest_cpg, optional=None):
"""Copy/Clone a volume.
:param src_name: the source volume name
:type src_name: str
:param dest_name: the destination volume name
:type dest_name: str
:param dest_cpg: the destination CPG
:type dest_cpg: str
:param optional: Dictionary of optional params
:type optional: dict
.. code-block:: python
optional = {
'online': False, # should physical copy be
# performed online?
'tpvv': False, # use thin provisioned space
# for destination
# (online copy only)
'snapCPG': 'OpenStack_SnapCPG', # snapshot CPG for the
# destination
# (online copy only)
'saveSnapshot': False, # save the snapshot of the
# source volume
'priority': 1 # taskPriorityEnum (does not
# apply to online copy)
}
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_ILLEGAL_CHAR - Invalid VV name or CPG name.
:raises: :class:`~hpe3parclient.exceptions.HTTPNotFound`
- NON_EXISTENT_CPG - The CPG does not exists.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- CPG_NOT_IN SAME_DOMAIN - The CPG is not in the current domain.
:raises: :class:`~hpe3parclient.exceptions.HTTPNotFound`
- NON_EXISTENT_VOL - The volume does not exist
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- VV_NOT_IN_SAME_DOMAIN - The volume is not in the same domain.
:raises: :class:`~hpe3parclient.exceptions.HTTPBadRequest`
- INV_INPUT_BAD_ENUM_VALUE - The priority value in not in the valid
range(1-3).
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- EXISTENT_VOLUME - The volume already exists.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_SYS_VOLUME - The operation is not allowed on a
system volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_NON_BASE_VOLUME - The destination volume is not a
base volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_IN_REMOTE_COPY - The destination volume is involved
in a remote copy.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_EXPORTED - The volume is exported.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_COPY_TO_SELF - The destination volume is the
same as the parent.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_READONLY_SNAPSHOT - The parent volume is a
read-only snapshot.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_COPY_TO_BASE - The destination volume is the
base volume of a parent volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_VOLUME_CONV_IN_PROGRESS - The volume is in a
conversion operation.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_NO_SNAPSHOT_ALLOWED - The parent volume must
allow snapshots.
:raises: :class:`~hpe3parclient.exceptions.HTTPConflict`
- INV_OPERATION_VV_ONLINE_COPY_IN_PROGRESS - The volume is the
target of an online copy.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_CLEANUP_IN_PROGRESS - Cleanup of internal volume
for the volume is in progress.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_CIRCULAR_COPY - The parent volume is a copy of
the destination volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_PEER_VOLUME - The operation is not allowed on a
peer volume.
:raises: :class:`~hpe3parclient.exceptions.HTTPForbidden`
- INV_OPERATION_VV_INTERNAL_VOLUME - The operation is not allowed