示例#1
0
def main():
    """ main entry point for module execution
    """
    network_spec = {
        "prefix": dict(required=True),
        "masklen": dict(type="int"),
        "route_map": dict(),
    }
    redistribute_spec = {
        "protocol": dict(choices=REDISTRIBUTE_PROTOCOLS, required=True),
        "id": dict(),
        "metric": dict(type="int"),
        "route_map": dict(),
    }
    timer_spec = {
        "keepalive": dict(type="int", required=True),
        "holdtime": dict(type="int", required=True),
        "min_neighbor_holdtime": dict(type="int"),
    }
    neighbor_spec = {
        "neighbor": dict(required=True),
        "remote_as": dict(type="int", required=True),
        "local_as": dict(type="int"),
        "update_source": dict(),
        "password": dict(no_log=True),
        "enabled": dict(type="bool"),
        "description": dict(),
        "ebgp_multihop": dict(type="int"),
        "timers": dict(type="dict", options=timer_spec),
        "peer_group": dict(),
    }
    af_neighbor_spec = {
        "neighbor": dict(required=True),
        "activate": dict(type="bool"),
        "advertisement_interval": dict(type="int"),
        "remove_private_as": dict(type="bool"),
        "next_hop_self": dict(type="bool"),
        "next_hop_unchanged": dict(type="bool"),
        "route_reflector_client": dict(type="bool"),
        "route_server_client": dict(type="bool"),
        "maximum_prefix": dict(type="int"),
        "prefix_list_in": dict(),
        "prefix_list_out": dict(),
    }
    address_family_spec = {
        "afi": dict(choices=["ipv4", "ipv6"], required=True),
        "safi": dict(
            choices=["flowspec", "labeled-unicast", "multicast", "unicast"],
            default="unicast",
        ),
        "auto_summary": dict(type="bool"),
        "synchronization": dict(type="bool"),
        "networks": dict(type="list", elements="dict", options=network_spec),
        "redistribute": dict(
            type="list", elements="dict", options=redistribute_spec
        ),
        "neighbors": dict(
            type="list", elements="dict", options=af_neighbor_spec
        ),
    }
    config_spec = {
        "bgp_as": dict(type="int", required=True),
        "router_id": dict(),
        "log_neighbor_changes": dict(type="bool"),
        "neighbors": dict(type="list", elements="dict", options=neighbor_spec),
        "address_family": dict(
            type="list", elements="dict", options=address_family_spec
        ),
        "networks": dict(type="list", elements="dict", options=network_spec),
    }
    argument_spec = {
        "config": dict(type="dict", options=config_spec),
        "operation": dict(
            default="merge", choices=["merge", "replace", "override", "delete"]
        ),
    }
    module = NetworkModule(
        argument_spec=argument_spec, supports_check_mode=True
    )
    try:
        result = module.edit_config(config_filter="| section ^router bgp")
    except Exception as exc:
        module.fail_json(msg=to_text(exc))
    module.exit_json(**result)
示例#2
0
def main():
    """ main entry point for module execution
    """
    network_spec = {
        'prefix': dict(required=True),
        'masklen': dict(type='int'),
        'route_map': dict(),
    }

    redistribute_spec = {
        'protocol': dict(choices=REDISTRIBUTE_PROTOCOLS, required=True),
        'id': dict(),
        'metric': dict(type='int'),
        'route_map': dict(),
    }

    timer_spec = {
        'keepalive': dict(type='int', required=True),
        'holdtime': dict(type='int', required=True),
        'min_neighbor_holdtime': dict(type='int'),
    }

    neighbor_spec = {
        'neighbor': dict(required=True),
        'remote_as': dict(type='int', required=True),
        'local_as': dict(type='int'),
        'update_source': dict(),
        'password': dict(no_log=True),
        'enabled': dict(type='bool'),
        'description': dict(),
        'ebgp_multihop': dict(type='int'),
        'timers': dict(type='dict', options=timer_spec),
        'peer_group': dict(),
    }

    af_neighbor_spec = {
        'neighbor': dict(required=True),
        'activate': dict(type='bool'),
        'advertisement_interval': dict(type='int'),
        'remove_private_as': dict(type='bool'),
        'next_hop_self': dict(type='bool'),
        'route_reflector_client': dict(type='bool'),
        'route_server_client': dict(type='bool'),
        'maximum_prefix': dict(type='int'),
        'prefix_list_in': dict(),
        'prefix_list_out': dict()
    }

    address_family_spec = {
        'afi':
        dict(choices=['ipv4', 'ipv6'], required=True),
        'safi':
        dict(choices=['flowspec', 'labeled-unicast', 'multicast', 'unicast'],
             default='unicast'),
        'auto_summary':
        dict(type='bool'),
        'synchronization':
        dict(type='bool'),
        'networks':
        dict(type='list', elements='dict', options=network_spec),
        'redistribute':
        dict(type='list', elements='dict', options=redistribute_spec),
        'neighbors':
        dict(type='list', elements='dict', options=af_neighbor_spec),
    }

    config_spec = {
        'bgp_as':
        dict(type='int', required=True),
        'router_id':
        dict(),
        'log_neighbor_changes':
        dict(type='bool'),
        'neighbors':
        dict(type='list', elements='dict', options=neighbor_spec),
        'address_family':
        dict(type='list', elements='dict', options=address_family_spec),
        'networks':
        dict(type='list', elements='dict', options=network_spec)
    }

    argument_spec = {
        'config':
        dict(type='dict', options=config_spec),
        'operation':
        dict(default='merge',
             choices=['merge', 'replace', 'override', 'delete'])
    }

    module = NetworkModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    try:
        result = module.edit_config(config_filter='| section ^router bgp')
    except Exception as exc:
        module.fail_json(msg=to_text(exc))

    module.exit_json(**result)