Skip to content

Commit bee95dd

Browse files
author
Pon-Karuppasamy
committed
Add multiple disk pool support for the zvmsdk
Signed-off-by: Pon-Karuppasamy <[email protected]>
1 parent ac03fe1 commit bee95dd

8 files changed

+340
-36
lines changed

zvmsdk/api.py

+72-20
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,18 @@ def host_get_diskpool_volumes(self, disk_pool=None):
320320
# they want to get the disk pool info of CONF.zvm.disk_pool.
321321
# The default value of CONF.zvm.disk_pool is None, if it's configured,
322322
# the format must be "ECKD:eckdpool" or "FBA:fbapool".
323-
disk_pool = disk_pool or CONF.zvm.disk_pool
323+
disk_pool = disk_pool
324+
if disk_pool is None:
325+
disk_pool = CONF.zvm.disk_pool
326+
if disk_pool is not None:
327+
disk_pools = disk_pool.split(",")
328+
if len(disk_pools) == 1:
329+
disk_pool = disk_pools[0]
330+
else:
331+
errmsg = ("disk_pool input is required if multiple disk_pool"
332+
" is configured for sdkserver.")
333+
LOG.error(errmsg)
334+
raise exception.SDKInvalidInputFormat(msg=errmsg)
324335
if disk_pool is None:
325336
# Support disk_pool not configured, return empty list
326337
return {}
@@ -409,23 +420,41 @@ def host_diskpool_get_info(self, disk_pool=None, details=False):
409420
return {'disk_total': 0, 'disk_used': 0, 'disk_available': 0}
410421
else:
411422
return {}
412-
if ':' not in disk_pool:
413-
msg = ('Invalid input parameter disk_pool, expect ":" in'
414-
'disk_pool, eg. ECKD:eckdpool')
415-
LOG.error(msg)
416-
raise exception.SDKInvalidInputFormat(msg)
417-
diskpool_type = disk_pool.split(':')[0].upper()
418-
diskpool_name = disk_pool.split(':')[1]
419-
if diskpool_type not in ('ECKD', 'FBA'):
420-
msg = ('Invalid disk pool type found in disk_pool, expect'
421-
'disk_pool like ECKD:eckdpool or FBA:fbapool')
422-
LOG.error(msg)
423-
raise exception.SDKInvalidInputFormat(msg)
424-
425-
action = "get information of disk pool: '%s' '%s'" % (disk_pool, details)
426-
with zvmutils.log_and_reraise_sdkbase_error(action):
427-
return self._hostops.diskpool_get_info(diskpool_name, details)
428-
423+
disk_pools_total = 0
424+
disk_pools_used = 0
425+
disk_pools_available = 0
426+
disk_pools = disk_pool.split(',')
427+
disk_pool_info = {}
428+
for disk_pool in disk_pools:
429+
if ':' not in disk_pool:
430+
msg = ('Invalid input parameter disk_pool, expect ":" in'
431+
'disk_pool, eg. ECKD:eckdpool')
432+
LOG.error(msg)
433+
raise exception.SDKInvalidInputFormat(msg)
434+
diskpool_type = disk_pool.split(':')[0].upper()
435+
diskpool_name = disk_pool.split(':')[1]
436+
if diskpool_type not in ('ECKD', 'FBA'):
437+
msg = ('Invalid disk pool type found in disk_pool, expect'
438+
'disk_pool like ECKD:eckdpool or FBA:fbapool')
439+
LOG.error(msg)
440+
raise exception.SDKInvalidInputFormat(msg)
441+
442+
action = "get information of disk pool: '%s' '%s'" % (disk_pool, details)
443+
with zvmutils.log_and_reraise_sdkbase_error(action):
444+
dp_info = self._hostops.diskpool_get_info(diskpool_name, details)
445+
if not details:
446+
disk_pools_total = disk_pools_total + dp_info.get("disk_total", 0)
447+
disk_pools_used = disk_pools_used + dp_info.get("disk_used", 0)
448+
disk_pools_available = disk_pools_available + dp_info.get("disk_available", 0)
449+
disk_pool_info = {
450+
'disk_total': disk_pools_total,
451+
'disk_used': disk_pools_used,
452+
'disk_available': disk_pools_available
453+
}
454+
else:
455+
disk_pool_info.update(dp_info)
456+
return disk_pool_info
457+
429458
def image_delete(self, image_name):
430459
"""Delete image from image repository
431460
@@ -939,7 +968,18 @@ def guest_create(self, userid, vcpus, memory, disk_list=None,
939968
raise exception.SDKInvalidInputFormat(msg=errmsg)
940969

941970
# check disk_pool
942-
disk_pool = disk.get('disk_pool') or CONF.zvm.disk_pool
971+
disk_pool = disk.get('disk_pool')
972+
if disk_pool is None:
973+
disk_pool = CONF.zvm.disk_pool
974+
if disk_pool is not None:
975+
disk_pools = disk_pool.split(",")
976+
if len(disk_pools) == 1:
977+
disk_pool = disk_pools[0]
978+
else:
979+
errmsg = ("disk_pool input is required if multiple disk_pool"
980+
" is configured for sdkserver.")
981+
LOG.error(errmsg)
982+
raise exception.SDKInvalidInputFormat(msg=errmsg)
943983
if not swap_only:
944984
if disk_pool is None:
945985
errmsg = ("Invalid disk_pool input, disk_pool should"
@@ -1132,7 +1172,19 @@ def guest_create_disks(self, userid, disk_list):
11321172
LOG.error(errmsg)
11331173
raise exception.SDKInvalidInputFormat(msg=errmsg)
11341174
# check disk_pool
1135-
disk_pool = disk.get('disk_pool') or CONF.zvm.disk_pool
1175+
disk_pool = disk.get('disk_pool')
1176+
if disk_pool is None:
1177+
disk_pool = CONF.zvm.disk_pool
1178+
if disk_pool is not None:
1179+
disk_pools = disk_pool.split(",")
1180+
if len(disk_pools) == 1:
1181+
disk_pool = disk_pools[0]
1182+
else:
1183+
errmsg = ("disk_pool input is required if multiple disk_pool"
1184+
" is configured for sdkserver.")
1185+
LOG.error(errmsg)
1186+
raise exception.SDKInvalidInputFormat(msg=errmsg)
1187+
11361188
if disk_pool is None:
11371189
errmsg = ("Invalid disk_pool input, it should be configured"
11381190
" for sdkserver.")

zvmsdk/config.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,14 @@ def _check_value(self, conf):
777777
self._check_user_default_max_cpu(v2['default'])
778778

779779
def _check_zvm_disk_pool(self, value):
780-
disks = value.split(':')
781-
if (len(disks) != 2) or (disks[0].upper() not in ['FBA', 'ECKD']) or (
782-
disks[1] == ''):
783-
raise OptFormatError("zvm", "disk_pool", value)
780+
disk_pools = value.split(',')
781+
if (len(disk_pools) > 10):
782+
raise LenFormatError("zvm", "disk_pool", disk_pools)
783+
for disk_pool in disk_pools:
784+
disks = disk_pool.split(':')
785+
if (len(disks) != 2) or (disks[0].upper() not in ['FBA', 'ECKD']) or (
786+
disks[1] == ''):
787+
raise OptFormatError("zvm", "disk_pool", value)
784788

785789
def _check_user_default_max_memory(self, value):
786790
suffix = value[-1].upper()
@@ -917,6 +921,15 @@ def __str__(self):
917921
self.opt_name)
918922

919923

924+
class LenFormatError(Exception):
925+
def __init__(self, grp_name, opt_name, value):
926+
self.grp_name = grp_name
927+
self.opt_name = opt_name
928+
self.value = value
929+
def __str__(self):
930+
return "value %s, not more than 10 disk pools can be added" % (self.value)
931+
932+
920933
CONFOPTS = ConfigOpts()
921934
CONF = CONFOPTS.register(zvm_opts)
922935

zvmsdk/hostops.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,25 @@ def get_info(self):
8282
host_info['zvm_host'] = inv_info['zvm_host']
8383
host_info['hypervisor_hostname'] = inv_info['hypervisor_name']
8484

85-
disk_pool = CONF.zvm.disk_pool
86-
if disk_pool is None:
87-
dp_info = {'disk_total': 0, 'disk_used': 0, 'disk_available': 0}
88-
else:
89-
diskpool_name = disk_pool.split(':')[1]
90-
dp_info = self.diskpool_get_info(diskpool_name)
91-
host_info.update(dp_info)
92-
85+
disk_pool_list = CONF.zvm.disk_pool
86+
disk_pools_total = 0
87+
disk_pools_used = 0
88+
disk_pools_available = 0
89+
if disk_pool_list is not None:
90+
disk_pools = disk_pool_list.split(',')
91+
for disk_pool in disk_pools:
92+
if disk_pool is not None:
93+
disk_pool_name = disk_pool.split(':')[1]
94+
dp_info = self.diskpool_get_info(disk_pool_name)
95+
disk_pools_total = disk_pools_total + dp_info.get("disk_total", 0)
96+
disk_pools_used = disk_pools_used + dp_info.get("disk_used", 0)
97+
disk_pools_available = disk_pools_available + dp_info.get("disk_available", 0)
98+
disk_pool_info = {
99+
'disk_total': disk_pools_total,
100+
'disk_used': disk_pools_used,
101+
'disk_available': disk_pools_available
102+
}
103+
host_info.update(disk_pool_info)
93104
return host_info
94105

95106
def guest_list(self):

zvmsdk/smtclient.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,18 @@ def add_mdisks(self, userid, disk_list, start_vdev=None):
211211
# and not configured(the default vaule is None), report error
212212
# report error
213213
for idx, disk in enumerate(disk_list):
214-
disk_pool = disk.get('disk_pool') or CONF.zvm.disk_pool
214+
disk_pool = disk.get('disk_pool')
215+
if disk_pool is None:
216+
disk_pool = CONF.zvm.disk_pool
217+
if disk_pool is not None:
218+
disk_pools = disk_pool.split(",")
219+
if len(disk_pools) == 1:
220+
disk_pool = disk_pools[0]
221+
else:
222+
errmsg = ("disk_pool input is required if multiple disk_pool"
223+
" is configured for sdkserver.")
224+
LOG.error(errmsg)
225+
raise exception.SDKGuestOperationError(rs=2, msg=errmsg)
215226
disk['disk_pool'] = disk_pool
216227
if disk_pool is None:
217228
msg = ('disk_pool not configured for sdkserver.')
@@ -856,7 +867,18 @@ def _add_mdisk(self, userid, disk, vdev):
856867
"""
857868
size = disk['size']
858869
fmt = disk.get('format', 'ext4')
859-
disk_pool = disk.get('disk_pool') or CONF.zvm.disk_pool
870+
disk_pool = disk.get('disk_pool')
871+
if disk_pool is None:
872+
disk_pool = CONF.zvm.disk_pool
873+
if disk_pool is not None:
874+
disk_pools = disk_pool.split(",")
875+
if len(disk_pools) == 1:
876+
disk_pool = disk_pools[0]
877+
else:
878+
errmsg = ("disk_pool input is required if multiple disk_pool"
879+
" is configured for sdkserver.")
880+
LOG.error(errmsg)
881+
raise exception.SDKGuestOperationError(rs=2, msg=errmsg)
860882
# Check disk_pool, if it's None, report error
861883
if disk_pool is None:
862884
msg = ('disk_pool not configured for sdkserver.')

0 commit comments

Comments
 (0)