def main():
    argument_spec = ovirt_info_full_argument_spec(
        storage_domain=dict(default=None),
        max=dict(default=None, type='int'),
        unregistered=dict(default=False, type='bool'),
    )
    module = AnsibleModule(argument_spec)
    is_old_facts = module._name in (
        'ovirt_storage_template_facts',
        'community.general.ovirt_storage_template_facts')
    if is_old_facts:
        module.deprecate(
            "The 'ovirt_storage_template_facts' module has been renamed to 'ovirt_storage_template_info', "
            "and the renamed one no longer returns ansible_facts",
            version='3.0.0',
            collection_name='community.general')  # was Ansible 2.13

    check_sdk(module)

    try:
        auth = module.params.pop('auth')
        connection = create_connection(auth)
        storage_domains_service = connection.system_service(
        ).storage_domains_service()
        sd_id = get_id_by_name(storage_domains_service,
                               module.params['storage_domain'])
        storage_domain_service = storage_domains_service.storage_domain_service(
            sd_id)
        templates_service = storage_domain_service.templates_service()

        # Find the unregistered Template we want to register:
        if module.params.get('unregistered'):
            templates = templates_service.list(unregistered=True)
        else:
            templates = templates_service.list(max=module.params['max'])
        result = dict(ovirt_storage_templates=[
            get_dict_of_struct(
                struct=c,
                connection=connection,
                fetch_nested=module.params.get('fetch_nested'),
                attributes=module.params.get('nested_attributes'),
            ) for c in templates
        ], )
        if is_old_facts:
            module.exit_json(changed=False, ansible_facts=result)
        else:
            module.exit_json(changed=False, **result)
    except Exception as e:
        module.fail_json(msg=str(e), exception=traceback.format_exc())
    finally:
        connection.close(logout=auth.get('token') is None)
def main():
    argument_spec = ovirt_info_full_argument_spec(
        host=dict(required=True),
        iscsi=dict(default=None, type='dict'),
        fcp=dict(default=None, type='dict'),
    )
    module = AnsibleModule(argument_spec)
    is_old_facts = module._name in (
        'ovirt_host_storage_facts',
        'community.general.ovirt_host_storage_facts')
    if is_old_facts:
        module.deprecate(
            "The 'ovirt_host_storage_facts' module has been renamed to 'ovirt_host_storage_info', "
            "and the renamed one no longer returns ansible_facts",
            version='3.0.0',
            collection_name='community.general')  # was Ansible 2.13
    check_sdk(module)

    try:
        auth = module.params.pop('auth')
        connection = create_connection(auth)

        # Get Host
        hosts_service = connection.system_service().hosts_service()
        host_id = get_id_by_name(hosts_service, module.params['host'])
        storage_type = _get_storage_type(module.params)
        host_service = hosts_service.host_service(host_id)

        if storage_type == 'iscsi':
            # Login
            iscsi = module.params.get('iscsi')
            _login(host_service, iscsi)

        # Get LUNs exposed from the specified target
        host_storages = host_service.storage_service().list()

        if storage_type == 'iscsi':
            filterred_host_storages = [
                host_storage for host_storage in host_storages
                if host_storage.type == otypes.StorageType.ISCSI
            ]
            if 'target' in iscsi:
                filterred_host_storages = [
                    host_storage for host_storage in filterred_host_storages if
                    iscsi.get('target') == host_storage.logical_units[0].target
                ]
        elif storage_type == 'fcp':
            filterred_host_storages = [
                host_storage for host_storage in host_storages
                if host_storage.type == otypes.StorageType.FCP
            ]

        result = dict(ovirt_host_storages=[
            get_dict_of_struct(
                struct=c,
                connection=connection,
                fetch_nested=module.params.get('fetch_nested'),
                attributes=module.params.get('nested_attributes'),
            ) for c in filterred_host_storages
        ], )
        if is_old_facts:
            module.exit_json(changed=False, ansible_facts=result)
        else:
            module.exit_json(changed=False, **result)
    except Exception as e:
        module.fail_json(msg=str(e), exception=traceback.format_exc())
    finally:
        connection.close(logout=auth.get('token') is None)