mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
eb1214baad
Changes to the metadata format were approved here: https://github.com/ansible/proposals/issues/54 * Update documentation to the new metadata format * Changes to metadata-tool to account for new metadata * Add GPL license header * Add upgrade subcommand to upgrade metadata version * Change default metadata to the new format * Fix exclusion of non-modules from the metadata report * Fix ansible-doc for new module metadata * Exclude metadata version from ansible-doc output * Fix website docs generation for the new metadata * Update metadata schema in valiate-modules test * Update the metadata in all modules to the new version
102 lines
2.9 KiB
Python
102 lines
2.9 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# (c) 2015, Joseph Callen <jcallen () csc.com>
|
|
#
|
|
# This file is part of Ansible
|
|
#
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
|
'status': ['preview'],
|
|
'supported_by': 'community'}
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
---
|
|
module: vmware_target_canonical_facts
|
|
short_description: Return canonical (NAA) from an ESXi host
|
|
description:
|
|
- Return canonical (NAA) from an ESXi host based on SCSI target ID
|
|
version_added: "2.0"
|
|
author: Joseph Callen
|
|
notes:
|
|
requirements:
|
|
- Tested on vSphere 5.5
|
|
- PyVmomi installed
|
|
options:
|
|
target_id:
|
|
description:
|
|
- The target id based on order of scsi device
|
|
required: True
|
|
extends_documentation_fragment: vmware.documentation
|
|
'''
|
|
|
|
EXAMPLES = '''
|
|
# Example vmware_target_canonical_facts command from Ansible Playbooks
|
|
- name: Get Canonical name
|
|
local_action:
|
|
module: vmware_target_canonical_facts
|
|
hostname: "{{ ansible_ssh_host }}"
|
|
username: root
|
|
password: vmware
|
|
target_id: 7
|
|
'''
|
|
|
|
try:
|
|
from pyVmomi import vim, vmodl
|
|
HAS_PYVMOMI = True
|
|
except ImportError:
|
|
HAS_PYVMOMI = False
|
|
|
|
|
|
def find_hostsystem(content):
|
|
host_system = get_all_objs(content, [vim.HostSystem])
|
|
for host in host_system:
|
|
return host
|
|
return None
|
|
|
|
|
|
def main():
|
|
|
|
argument_spec = vmware_argument_spec()
|
|
argument_spec.update(dict(target_id=dict(required=True, type='int')))
|
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)
|
|
|
|
if not HAS_PYVMOMI:
|
|
module.fail_json(msg='pyvmomi is required for this module')
|
|
|
|
content = connect_to_api(module)
|
|
host = find_hostsystem(content)
|
|
|
|
target_lun_uuid = {}
|
|
scsilun_canonical = {}
|
|
|
|
# Associate the scsiLun key with the canonicalName (NAA)
|
|
for scsilun in host.config.storageDevice.scsiLun:
|
|
scsilun_canonical[scsilun.key] = scsilun.canonicalName
|
|
|
|
# Associate target number with LUN uuid
|
|
for target in host.config.storageDevice.scsiTopology.adapter[0].target:
|
|
for lun in target.lun:
|
|
target_lun_uuid[target.target] = lun.scsiLun
|
|
|
|
module.exit_json(changed=False, canonical=scsilun_canonical[target_lun_uuid[module.params['target_id']]])
|
|
|
|
from ansible.module_utils.basic import *
|
|
from ansible.module_utils.vmware import *
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|