Skip to content

Commit

Permalink
Add API call to get minidisks list
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Bischoff <[email protected]>
  • Loading branch information
Bischoff committed Jan 21, 2024
1 parent 52d8b86 commit 5fe3d66
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 0 deletions.
11 changes: 11 additions & 0 deletions zvmconnector/restclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ def req_guest_get_adapters_info(start_index, *args, **kwargs):
return url, body


def req_guest_get_disks_info(start_index, *args, **kwargs):
url = '/guests/%s/disks'
body = None
return url, body


def req_guest_create_nic(start_index, *args, **kwargs):
url = '/guests/%s/nic'
body = {'nic': {}}
Expand Down Expand Up @@ -916,6 +922,11 @@ def req_vswitch_set_vlan_id_for_user(start_index, *args, **kwargs):
'args_required': 2,
'params_path': 1,
'request': req_guest_config_minidisks},
'guest_get_disks_info': {
'method': 'GET',
'args_required': 1,
'params_path': 1,
'request': req_guest_get_disks_info},
'volume_attach': {
'method': 'POST',
'args_required': 1,
Expand Down
12 changes: 12 additions & 0 deletions zvmsdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ def guest_get_adapters_info(self, userid):
with zvmutils.log_and_reraise_sdkbase_error(action):
return self._vmops.get_adapters_info(userid)

def guest_get_disks_info(self, userid):
"""Get the disks information of a virtual machine.
:param str userid: the id of the virtual machine
:returns: Dictionary contains:
TODO
"""
action = "get disks info of guest '%s'" % userid
with zvmutils.log_and_reraise_sdkbase_error(action):
return self._vmops.get_disks_info(userid)

def guest_get_user_direct(self, userid):
"""Get user direct of the specified guest vm
Expand Down
1 change: 1 addition & 0 deletions zvmsdk/sdkwsgi/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
'POST': guest.guest_create_disks,
'DELETE': guest.guest_delete_disks,
'PUT': guest.guest_config_disks,
'GET': guest.guest_get_disks_info,
}),
('/smapi-healthy', {
'GET': healthy.healthy,
Expand Down
24 changes: 24 additions & 0 deletions zvmsdk/sdkwsgi/handlers/guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def get_adapters(self, req, userid):
info = self.client.send_request('guest_get_adapters_info', userid)
return info

@validation.query_schema(guest.userid_list_query)
def get_disks(self, req, userid):
info = self.client.send_request('guest_get_disks_info', userid)
return info

@validation.query_schema(guest.userid_list_query)
def get_definition_info(self, req, userid):
info = self.client.send_request('guest_get_definition_info', userid)
Expand Down Expand Up @@ -566,6 +571,25 @@ def _guest_get_adapters_info(req, userid):
return req.response


@util.SdkWsgify
@tokens.validate
def guest_get_disks_info(req):

def _guest_get_disks_info(req, userid):
action = get_handler()
return action.get_disks(req, userid)

userid = util.wsgi_path_item(req.environ, 'userid')
info = _guest_get_disks_info(req, userid)

info_json = json.dumps(info)
req.response.status = util.get_http_code_from_sdk_return(info,
additional_handler=util.handle_not_found)
req.response.body = utils.to_utf8(info_json)
req.response.content_type = 'application/json'
return req.response


@util.SdkWsgify
@tokens.validate
def guest_get(req):
Expand Down
41 changes: 41 additions & 0 deletions zvmsdk/smtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,47 @@ def get_adapters_info(self, userid):
found_mac = False
return adapters_info

def get_disks_info(self, userid):
rd = "SMAPI %s API Image_Query_DM" % userid
results = None
action = "get info of userid '%s'" % userid
with zvmutils.log_and_reraise_smt_request_failed(action):
results = self._request(rd)
ret = results['response']
disks_info = []
for line in ret:
if line.startswith('MDISK'):
vdev = line.split(' ')[1]
rd = ' '.join((
"SMAPI %s API Image_Disk_Query" % userid,
"--operands",
"-k 'vdasd_id=%s'" % vdev))
results = None
action = "get disk info of disk '%s'" % vdev
with zvmutils.log_and_reraise_smt_request_failed(action):
results = self._request(rd)
ret2 = results['response']
disk = dict()
for line2 in ret2:
key = line2.split(':')[0].strip()
value = line2.split(':')[-1].strip()
if key == 'DASD VDEV':
disk['vdev'] = value
if key == 'RDEV':
disk['rdev'] = value
if key == 'Access type':
disk['access_type'] = value
if key == 'Device type':
disk['device_type'] = value
if key == 'Device size':
disk['device_size'] = int(value)
if key == 'Device units':
disk['device_units'] = value
if key == 'Device volume label':
disk['volume_label'] = value
disks_info.append(disk)
return disks_info

def _parse_vswitch_inspect_data(self, rd_list):
""" Parse the Virtual_Network_Vswitch_Query_Byte_Stats data to get
inspect data.
Expand Down
5 changes: 5 additions & 0 deletions zvmsdk/tests/unit/test_smtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,11 @@ def test_get_image_disk_type_failed(self, image_info):
self.assertEqual(self._smtclient._get_image_disk_type(image_info),
None)

# IN PROGRESS
# @mock.patch.object(smtclient.SMTClient, '_request')
# def test_get_disks_info(self, request):
# userid = 'FakeID'

@mock.patch.object(smtclient.SMTClient, '_request')
def test_get_adapters_info(self, request):
userid = 'FakeID'
Expand Down
15 changes: 15 additions & 0 deletions zvmsdk/tests/unit/test_vmops.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ def test_get_info_get_uid_failed(self, gps, gipi, ggbu, gud):
self.assertRaises(exception.ZVMVirtualMachineNotExist,
self.vmops.get_info, 'fakeid')

@mock.patch("zvmsdk.smtclient.SMTClient.get_disks_info")
def test_get_disks_info(self, get_disks_info):
minidisks = [{'vdev': '0100',
'rdev': '6018',
'access_type': 'R/W',
'device_type': '3390',
'device_size': 29128,
'device_units': 'Cylinders',
'volume_label': 'VM6018'}]
get_disks_info.return_value = minidisks
ret = self.vmops.get_disks_info('fakeid')
print('Eric')
print(ret['minidisks'][0])
self.assertEqual(ret['minidisks'][0]['vdev'], '0100')

@mock.patch("zvmsdk.smtclient.SMTClient.get_adapters_info")
def test_get_adapters_info(self, adapters_info):
adapters = [{u'lan_owner': u'SYSTEM',
Expand Down
8 changes: 8 additions & 0 deletions zvmsdk/vmops.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def get_adapters_info(self, userid):
raise exception.SDKInternalError(msg=msg, modID='guest')
return {'adapters': adapters_info}

def get_disks_info(self, userid):
disks_info = self._smtclient.get_disks_info(userid)
if not disks_info:
msg = 'Get disks information failed on: %s' % userid
LOG.error(msg)
raise exception.SDKInternalError(msg=msg, modID='guest')
return {'minidisks': disks_info}

def instance_metadata(self, instance, content, extra_md):
pass

Expand Down

0 comments on commit 5fe3d66

Please sign in to comment.