NetApp: return lun info for na_ontap_lun_map module (#42961)

* return lun details for na_ontap_lun_map

return lun details for na_ontap_lun_map.py and added return value documentation
This commit is contained in:
njferrant 2018-08-24 10:37:28 -04:00 committed by John R Barker
parent 53405f673c
commit 507d6e241e

View file

@ -81,7 +81,36 @@ EXAMPLES = """
"""
RETURN = """
lun_node:
description: NetApp controller that is hosting the LUN.
returned: success
type: string
sample: node01
lun_ostype:
description: Specifies the OS of the host accessing the LUN.
returned: success
type: string
sample: vmware
lun_serial:
description: A unique, 12-byte, ASCII string used to identify the LUN.
returned: success
type: string
sample: 80E7/]LZp1Tt
lun_naa_id:
description: The Network Address Authority (NAA) identifier for the LUN.
returned: success
type: string
sample: 600a0980383045372f5d4c5a70315474
lun_state:
description: Online or offline tatus of the LUN.
returned: success
type: string
sample: online
lun_size:
description: Size of the LUN in bytes.
returned: success
type: int
sample: 2199023255552
"""
import traceback
@ -103,8 +132,8 @@ class NetAppOntapLUNMap(object):
initiator_group_name=dict(required=True, type='str'),
path=dict(required=True, type='str'),
vserver=dict(required=True, type='str'),
lun_id=dict(required=False, type='str', default=None)),
)
lun_id=dict(required=False, type='str', default=None),
))
self.module = AnsibleModule(
argument_spec=self.argument_spec,
@ -114,6 +143,10 @@ class NetAppOntapLUNMap(object):
supports_check_mode=True
)
self.result = dict(
changed=False,
)
p = self.module.params
# set up state variables
@ -152,6 +185,41 @@ class NetAppOntapLUNMap(object):
return return_value
def get_lun(self):
"""
Return details about the LUN
:return: Details about the lun
:rtype: dict
"""
# build the lun query
query_details = netapp_utils.zapi.NaElement('lun-info')
query_details.add_new_child('path', self.path)
query = netapp_utils.zapi.NaElement('query')
query.add_child_elem(query_details)
lun_query = netapp_utils.zapi.NaElement('lun-get-iter')
lun_query.add_child_elem(query)
# find lun using query
result = self.server.invoke_successfully(lun_query, True)
return_value = None
if result.get_child_by_name('num-records') and int(result.get_child_content('num-records')) >= 1:
lun = result.get_child_by_name('attributes-list').get_child_by_name('lun-info')
# extract and assign lun infomation to return value
return_value = {
'lun_node': lun.get_child_content('node'),
'lun_ostype': lun.get_child_content('multiprotocol-type'),
'lun_serial': lun.get_child_content('serial-number'),
'lun_naa_id': '600a0980' + lun.get_child_content('serial-number').encode('hex'),
'lun_state': lun.get_child_content('state'),
'lun_size': lun.get_child_content('size'),
}
return return_value
def create_lun_map(self):
"""
Create LUN map
@ -182,39 +250,23 @@ class NetAppOntapLUNMap(object):
exception=traceback.format_exc())
def apply(self):
property_changed = False
lun_map_exists = False
netapp_utils.ems_log_event("na_ontap_lun_map", self.server)
lun_map_detail = self.get_lun_map()
lun_details = self.get_lun()
lun_map_details = self.get_lun_map()
if lun_map_detail:
lun_map_exists = True
if self.state == 'present' and lun_details:
self.result.update(lun_details)
if self.state == 'absent':
property_changed = True
elif self.state == 'present':
pass
else:
if self.state == 'present':
property_changed = True
if property_changed:
if self.module.check_mode:
pass
else:
if self.state == 'present':
# TODO delete this line in next release
if not lun_map_exists:
if self.state == 'present' and not lun_map_details:
self.result['changed'] = True
if not self.module.check_mode:
self.create_lun_map()
elif self.state == 'absent':
elif self.state == 'absent' and lun_map_details:
self.result['changed'] = True
if not self.module.check_mode:
self.delete_lun_map()
changed = property_changed
# TODO: include other details about the lun (size, etc.)
self.module.exit_json(changed=changed)
self.module.exit_json(**self.result)
def main():