def main():
    helper = get_connection(
        template=True,
        template_stack=True,
        with_state=True,
        with_classic_provider_spec=True,
        argument_spec=setup_args(),
    )

    module = AnsibleModule(
        argument_spec=helper.argument_spec,
        supports_check_mode=True,
        required_one_of=helper.required_one_of,
    )

    parent = helper.get_pandevice_parent(module)

    vr = VirtualRouter(module.params["vr_name"])
    parent.add(vr)
    try:
        vr.refresh()
    except PanDeviceError as e:
        module.fail_json(msg="Failed refresh: {0}".format(e))

    spec = {
        "name": module.params["name"],
        "priority": module.params["priority"],
        "action": module.params["action"],
        "filter_type": module.params["filter_type"],
        "filter_interface": module.params["filter_interface"],
        "filter_destination": module.params["filter_destination"],
        "filter_nexthop": module.params["filter_nexthop"],
        "ospf_filter_pathtype": module.params["ospf_filter_pathtype"],
        "ospf_filter_area": module.params["ospf_filter_area"],
        "ospf_filter_tag": module.params["ospf_filter_tag"],
        "bgp_filter_community": module.params["bgp_filter_community"],
        "bgp_filter_extended_community": module.params["bgp_filter_extended_community"],
    }

    if module.params["type"] == "ipv4":
        obj = RedistributionProfile(**spec)
    else:
        obj = RedistributionProfileIPv6(**spec)

    listing = vr.findall(obj.__class__)
    vr.add(obj)

    changed, diff = helper.apply_state(obj, listing, module)
    if changed and module.params["commit"]:
        helper.commit(module)

    module.exit_json(changed=changed, diff=diff, msg="done")
Beispiel #2
0
def main():
    helper = get_connection(
        template=True,
        template_stack=True,
        with_state=True,
        with_classic_provider_spec=True,
        argument_spec=setup_args(),
    )

    module = AnsibleModule(
        argument_spec=helper.argument_spec,
        supports_check_mode=True,
        required_one_of=helper.required_one_of,
    )

    parent = helper.get_pandevice_parent(module)

    vr = VirtualRouter(module.params['vr_name'])
    parent.add(vr)
    try:
        vr.refresh()
    except PanDeviceError as e:
        module.fail_json(msg='Failed refresh: {0}'.format(e))

    spec = {
        'name':
        module.params['name'],
        'priority':
        module.params['priority'],
        'action':
        module.params['action'],
        'filter_type':
        module.params['filter_type'],
        'filter_interface':
        module.params['filter_interface'],
        'filter_destination':
        module.params['filter_destination'],
        'filter_nexthop':
        module.params['filter_nexthop'],
        'ospf_filter_pathtype':
        module.params['ospf_filter_pathtype'],
        'ospf_filter_area':
        module.params['ospf_filter_area'],
        'ospf_filter_tag':
        module.params['ospf_filter_tag'],
        'bgp_filter_community':
        module.params['bgp_filter_community'],
        'bgp_filter_extended_community':
        module.params['bgp_filter_extended_community'],
    }

    if module.params['type'] == 'ipv4':
        obj = RedistributionProfile(**spec)
    else:
        obj = RedistributionProfileIPv6(**spec)

    listing = vr.findall(obj.__class__)
    vr.add(obj)

    changed, diff = helper.apply_state(obj, listing, module)
    if changed and module.params['commit']:
        helper.commit(module)

    module.exit_json(changed=changed, diff=diff, msg='done')