Exemplo n.º 1
0
def main():
    argument_spec = dict(
        interface=dict(required=True, type='str'),
        description=dict(required=False, type='str'),
        host_reachability=dict(required=False, type='bool'),
        shutdown=dict(required=False, type='bool'),
        source_interface=dict(required=False, type='str'),
        source_interface_hold_down_time=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'],
                   default='present',
                   required=False),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    result = {'changed': False, 'commands': [], 'warnings': warnings}
    check_args(module, warnings)

    state = module.params['state']

    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'interface':
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key)
                if value is None:
                    if key in BOOL_PARAMS:
                        value = False
                    else:
                        value = 'default'
            if str(existing.get(key)).lower() != str(value).lower():
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        if not existing:
            warnings.append("The proposed NVE interface did not exist. "
                            "It's recommended to use nxos_interface to create "
                            "all logical interfaces.")
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 2
0
def main():
    argument_spec = dict(ssm_range=dict(required=True, type='str'), )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    splitted_ssm_range = module.params['ssm_range'].split('.')
    if len(splitted_ssm_range) != 4 and module.params['ssm_range'] != 'none':
        module.fail_json(msg="Valid ssm_range values are multicast addresses "
                         "or the keyword 'none'.")

    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed = dict((k, v) for k, v in module.params.items()
                    if k in args and v != existing[k])

    candidate = CustomNetworkConfig(indent=3)
    get_commands(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 3
0
def main():
    argument_spec = dict(anycast_gateway_mac=dict(required=True, type='str'), )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed = dict((k, v) for k, v in module.params.items()
                    if v is not None and k in args)

    candidate = CustomNetworkConfig(indent=3)
    get_commands(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate

        if not module.check_mode:
            load_config(module, candidate)
            result['changed'] = True

    module.exit_json(**result)
Exemplo n.º 4
0
def main():
    argument_spec = dict(
        bfd=dict(required=False, type='str', choices=['enable', 'disable']),
        ssm_range=dict(required=False, type='list', default=[]),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)
    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    params = module.params
    args = [k for k in PARAM_TO_COMMAND_KEYMAP.keys() if params[k] is not None]

    # SSM syntax check
    if 'ssm_range' in args:
        for item in params['ssm_range']:
            if re.search('none|default', item):
                break
            if len(item.split('.')) != 4:
                module.fail_json(
                    msg="Valid ssm_range values are multicast addresses "
                    "or the keyword 'none' or the keyword 'default'.")

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in params.items() if k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key == 'ssm_range':
            if value and value[0] == 'default':
                if existing.get(key):
                    proposed[key] = 'default'
            else:
                v = sorted(set([str(i) for i in value]))
                ex = sorted(set([str(i) for i in existing.get(key, [])]))
                if v != ex:
                    proposed[key] = ' '.join(str(s) for s in v)

        elif key == 'bfd':
            if value != existing.get('bfd', 'disable'):
                proposed[key] = value

        elif value != existing.get(key):
            proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    get_commands(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 5
0
def main():
    argument_spec = dict(
        vrf=dict(required=False, type='str', default='default'),
        ospf=dict(required=True, type='str'),
        router_id=dict(required=False, type='str'),
        default_metric=dict(required=False, type='str'),
        log_adjacency=dict(required=False, type='str', choices=['log', 'detail', 'default']),
        timer_throttle_lsa_start=dict(required=False, type='str'),
        timer_throttle_lsa_hold=dict(required=False, type='str'),
        timer_throttle_lsa_max=dict(required=False, type='str'),
        timer_throttle_spf_start=dict(required=False, type='str'),
        timer_throttle_spf_hold=dict(required=False, type='str'),
        timer_throttle_spf_max=dict(required=False, type='str'),
        auto_cost=dict(required=False, type='str'),
        bfd=dict(required=False, type='str', choices=['enable', 'disable']),
        passive_interface=dict(required=False, type='bool'),
        state=dict(choices=['present', 'absent'], default='present', required=False)
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    result = dict(changed=False, commands=[], warnings=warnings)

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'interface':
            if str(value).lower() == 'true':
                value = True
            elif str(value).lower() == 'false':
                value = False
            elif str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key)
                if value is None:
                    value = 'default'
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    if state == 'absent' and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        if not module.check_mode:
            load_config(module, candidate)
            result['changed'] = True
    module.exit_json(**result)
Exemplo n.º 6
0
def main():
    argument_spec = dict(
        rp_address=dict(required=True, type='str'),
        group_list=dict(required=False, type='str'),
        prefix_list=dict(required=False, type='str'),
        route_map=dict(required=False, type='str'),
        bidir=dict(required=False, type='bool'),
        state=dict(choices=['present', 'absent'], default='present', required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           mutually_exclusive=[['group_list', 'route_map'],
                                               ['group_list', 'prefix_list'],
                                               ['route_map', 'prefix_list']],
                           supports_check_mode=True)

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    state = module.params['state']

    args = [
        'rp_address',
        'group_list',
        'prefix_list',
        'route_map',
        'bidir'
    ]

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'rp_address':
            if str(value).lower() == 'true':
                value = True
            elif str(value).lower() == 'false':
                value = False

            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present' and (proposed or not existing):
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 7
0
def main():
    argument_spec = dict(
        bfd=dict(required=False, type="str", choices=["enable", "disable"]),
        ssm_range=dict(required=False, type="list", default=[]),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)
    warnings = list()
    result = {"changed": False, "commands": [], "warnings": warnings}

    params = module.params
    args = [k for k in PARAM_TO_COMMAND_KEYMAP.keys() if params[k] is not None]

    # SSM syntax check
    if "ssm_range" in args:
        for item in params["ssm_range"]:
            if re.search("none|default", item):
                break
            if len(item.split(".")) != 4:
                module.fail_json(
                    msg="Valid ssm_range values are multicast addresses "
                    "or the keyword 'none' or the keyword 'default'.")

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in params.items() if k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key == "ssm_range":
            if value and value[0] == "default":
                if existing.get(key):
                    proposed[key] = "default"
            else:
                v = sorted(set([str(i) for i in value]))
                ex = sorted(set([str(i) for i in existing.get(key, [])]))
                if v != ex:
                    proposed[key] = " ".join(str(s) for s in v)

        elif key == "bfd":
            if value != existing.get("bfd", "disable"):
                proposed[key] = value

        elif value != existing.get(key):
            proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    get_commands(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result["commands"] = candidate
        result["changed"] = True
        load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 8
0
def main():
    argument_spec = dict(
        interface=dict(required=True, type='str'),
        description=dict(required=False, type='str'),
        host_reachability=dict(required=False, type='bool'),
        shutdown=dict(required=False, type='bool'),
        source_interface=dict(required=False, type='str'),
        source_interface_hold_down_time=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'], default='present', required=False),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    result = {'changed': False, 'commands': [], 'warnings': warnings}
    check_args(module, warnings)

    state = module.params['state']

    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'interface':
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key)
                if value is None:
                    if key in BOOL_PARAMS:
                        value = False
                    else:
                        value = 'default'
            if str(existing.get(key)).lower() != str(value).lower():
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        if not existing:
            warnings.append("The proposed NVE interface did not exist. "
                            "It's recommended to use nxos_interface to create "
                            "all logical interfaces.")
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 9
0
def main():
    argument_spec = dict(
        vni=dict(required=True, type="str"),
        route_distinguisher=dict(required=False, type="str"),
        route_target_both=dict(required=False, type="list"),
        route_target_import=dict(required=False, type="list"),
        route_target_export=dict(required=False, type="list"),
        state=dict(choices=["present", "absent"],
                   default="present",
                   required=False),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    results = dict(changed=False, warnings=warnings)

    state = module.params["state"]
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    commands = []
    parents = []

    proposed = {}
    for key, value in proposed_args.items():
        if key != "vni":
            if value == "true":
                value = True
            elif value == "false":
                value = False
            if existing.get(key) != value:
                proposed[key] = value

    if state == "present":
        commands, parents = state_present(module, existing, proposed)
    elif state == "absent" and existing:
        commands, parents = state_absent(module, existing, proposed)

    if commands:
        candidate = CustomNetworkConfig(indent=3)
        candidate.add(commands, parents=parents)
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
            results["changed"] = True
        results["commands"] = candidate
    else:
        results["commands"] = []
    module.exit_json(**results)
Exemplo n.º 10
0
def main():
    argument_spec = dict(vni=dict(required=True, type='str'),
                         route_distinguisher=dict(required=False, type='str'),
                         route_target_both=dict(required=False, type='list'),
                         route_target_import=dict(required=False, type='list'),
                         route_target_export=dict(required=False, type='list'),
                         state=dict(choices=['present', 'absent'],
                                    default='present',
                                    required=False))

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    results = dict(changed=False, warnings=warnings)

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    commands = []
    parents = []

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'vni':
            if value == 'true':
                value = True
            elif value == 'false':
                value = False
            if existing.get(key) != value:
                proposed[key] = value

    if state == 'present':
        commands, parents = state_present(module, existing, proposed)
    elif state == 'absent' and existing:
        commands, parents = state_absent(module, existing, proposed)

    if commands:
        candidate = CustomNetworkConfig(indent=3)
        candidate.add(commands, parents=parents)
        candidate = candidate.items_text()
        load_config(module, candidate)
        results['changed'] = True
        results['commands'] = candidate
    else:
        results['commands'] = []
    module.exit_json(**results)
Exemplo n.º 11
0
def main():
    argument_spec = dict(
        vni=dict(required=True, type='str'),
        route_distinguisher=dict(required=False, type='str'),
        route_target_both=dict(required=False, type='list'),
        route_target_import=dict(required=False, type='list'),
        route_target_export=dict(required=False, type='list'),
        state=dict(choices=['present', 'absent'], default='present', required=False)
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    results = dict(changed=False, warnings=warnings)

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    commands = []
    parents = []

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'vni':
            if value == 'true':
                value = True
            elif value == 'false':
                value = False
            if existing.get(key) != value:
                proposed[key] = value

    if state == 'present':
        commands, parents = state_present(module, existing, proposed)
    elif state == 'absent' and existing:
        commands, parents = state_absent(module, existing, proposed)

    if commands:
            candidate = CustomNetworkConfig(indent=3)
            candidate.add(commands, parents=parents)
            candidate = candidate.items_text()
            load_config(module, candidate)
            results['changed'] = True
            results['commands'] = candidate
    else:
        results['commands'] = []
    module.exit_json(**results)
Exemplo n.º 12
0
def main():
    element_spec = dict(
        prefix=dict(type='str', aliases=['address']),
        next_hop=dict(type='str'),
        vrf=dict(type='str', default='default'),
        tag=dict(type='str'),
        route_name=dict(type='str'),
        pref=dict(type='str', aliases=['admin_distance']),
        state=dict(choices=['absent', 'present'], default='present'),
    )

    aggregate_spec = deepcopy(element_spec)
    aggregate_spec['prefix'] = dict(required=True)
    aggregate_spec['next_hop'] = dict(required=True)

    # remove default in aggregate spec, to handle common arguments
    remove_default_spec(aggregate_spec)

    argument_spec = dict(
        aggregate=dict(type='list', elements='dict', options=aggregate_spec)
    )

    argument_spec.update(element_spec)
    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    result = {'changed': False, 'commands': []}
    if warnings:
        result['warnings'] = warnings

    want = map_params_to_obj(module)
    for w in want:
        prefix = normalize_prefix(module, w['prefix'])
        candidate = CustomNetworkConfig(indent=3)
        reconcile_candidate(module, candidate, prefix, w)

        if candidate:
            candidate = candidate.items_text()
            load_config(module, candidate)
            result['commands'].extend(candidate)
            result['changed'] = True
        else:
            result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 13
0
def main():
    element_spec = dict(
        prefix=dict(type='str', aliases=['address']),
        next_hop=dict(type='str'),
        vrf=dict(type='str', default='default'),
        tag=dict(type='str'),
        route_name=dict(type='str'),
        pref=dict(type='str', aliases=['admin_distance']),
        state=dict(choices=['absent', 'present'], default='present'),
    )

    aggregate_spec = deepcopy(element_spec)
    aggregate_spec['prefix'] = dict(required=True)
    aggregate_spec['next_hop'] = dict(required=True)

    # remove default in aggregate spec, to handle common arguments
    remove_default_spec(aggregate_spec)

    argument_spec = dict(
        aggregate=dict(type='list', elements='dict', options=aggregate_spec)
    )

    argument_spec.update(element_spec)
    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    result = {'changed': False, 'commands': []}
    if warnings:
        result['warnings'] = warnings

    want = map_params_to_obj(module)
    for w in want:
        prefix = normalize_prefix(module, w['prefix'])
        candidate = CustomNetworkConfig(indent=3)
        reconcile_candidate(module, candidate, prefix, w)

        if candidate:
            candidate = candidate.items_text()
            load_config(module, candidate)
            result['commands'].extend(candidate)
            result['changed'] = True
        else:
            result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 14
0
def main():
    argument_spec = dict(
        ssm_range=dict(required=True, type='list'),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    ssm_range_list = module.params['ssm_range']
    for item in ssm_range_list:
        splitted_ssm_range = item.split('.')
        if len(splitted_ssm_range) != 4 and item != 'none' and item != 'default':
            module.fail_json(msg="Valid ssm_range values are multicast addresses "
                                 "or the keyword 'none' or the keyword 'default'.")

    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items() if k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key == 'ssm_range':
            if value[0] == 'default':
                if existing.get(key):
                    proposed[key] = 'default'
            else:
                v = sorted(set([str(i) for i in value]))
                ex = sorted(set([str(i) for i in existing.get(key)]))
                if v != ex:
                    proposed[key] = ' '.join(str(s) for s in v)

    candidate = CustomNetworkConfig(indent=3)
    get_commands(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 15
0
def main():
    argument_spec = dict(
        ssm_range=dict(required=True, type='list'),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    ssm_range_list = module.params['ssm_range']
    for item in ssm_range_list:
        splitted_ssm_range = item.split('.')
        if len(splitted_ssm_range) != 4 and item != 'none' and item != 'default':
            module.fail_json(msg="Valid ssm_range values are multicast addresses "
                                 "or the keyword 'none' or the keyword 'default'.")

    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items() if k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key == 'ssm_range':
            if value[0] == 'default':
                if existing.get(key):
                    proposed[key] = 'default'
            else:
                v = sorted(set([str(i) for i in value]))
                ex = sorted(set([str(i) for i in existing.get(key)]))
                if v != ex:
                    proposed[key] = ' '.join(str(s) for s in v)

    candidate = CustomNetworkConfig(indent=3)
    get_commands(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        load_config(module, candidate)

    module.exit_json(**result)
def main():
    element_spec = dict(
        prefix=dict(type="str", aliases=["address"]),
        next_hop=dict(type="str"),
        vrf=dict(type="str", default="default"),
        tag=dict(type="str"),
        route_name=dict(type="str"),
        pref=dict(type="str", aliases=["admin_distance"]),
        state=dict(choices=["absent", "present"], default="present"),
        track=dict(type="int"),
    )

    aggregate_spec = deepcopy(element_spec)
    aggregate_spec["prefix"] = dict(required=True)
    aggregate_spec["next_hop"] = dict(required=True)

    # remove default in aggregate spec, to handle common arguments
    remove_default_spec(aggregate_spec)

    argument_spec = dict(
        aggregate=dict(type="list", elements="dict", options=aggregate_spec))

    argument_spec.update(element_spec)
    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    result = {"changed": False, "commands": []}
    if warnings:
        result["warnings"] = warnings

    want = map_params_to_obj(module)
    for w in want:
        prefix = normalize_prefix(module, w["prefix"])
        candidate = CustomNetworkConfig(indent=3)
        reconcile_candidate(module, candidate, prefix, w)

        if not module.check_mode and candidate:
            candidate = candidate.items_text()
            load_config(module, candidate)
            result["commands"].extend(candidate)
            result["changed"] = True

    module.exit_json(**result)
Exemplo n.º 17
0
def main():
    argument_spec = dict(ospf=dict(required=True, type='str'),
                         state=dict(choices=['present', 'absent'],
                                    default='present',
                                    required=False),
                         include_defaults=dict(default=True),
                         config=dict(),
                         save=dict(type='bool', default=False))

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']
    ospf = str(module.params['ospf'])

    existing = get_existing(module)
    proposed = dict(ospf=ospf)

    if not existing:
        existing_list = []
    else:
        existing_list = existing['ospf']

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present' and ospf not in existing_list:
        state_present(module, proposed, candidate)
    if state == 'absent' and ospf in existing_list:
        state_absent(module, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate

    else:
        result['commands'] = []
    module.exit_json(**result)
Exemplo n.º 18
0
def main():
    argument_spec = dict(
        ospf=dict(required=True, type="str"),
        state=dict(
            choices=["present", "absent"], default="present", required=False
        ),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    result = dict(changed=False, warnings=warnings)

    state = module.params["state"]
    ospf = str(module.params["ospf"])

    existing = get_existing(module)
    proposed = dict(ospf=ospf)

    if not existing:
        existing_list = []
    else:
        existing_list = existing["ospf"]

    candidate = CustomNetworkConfig(indent=3)
    if state == "present" and ospf not in existing_list:
        state_present(module, proposed, candidate)
    if state == "absent" and ospf in existing_list:
        state_absent(module, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result["changed"] = True
        result["commands"] = candidate

    else:
        result["commands"] = []
    module.exit_json(**result)
Exemplo n.º 19
0
def main():
    argument_spec = dict(
        ospf=dict(required=True, type='str'),
        state=dict(choices=['present', 'absent'], default='present', required=False)
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']
    ospf = str(module.params['ospf'])

    existing = get_existing(module)
    proposed = dict(ospf=ospf)

    if not existing:
        existing_list = []
    else:
        existing_list = existing['ospf']

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present' and ospf not in existing_list:
        state_present(module, proposed, candidate)
    if state == 'absent' and ospf in existing_list:
        state_absent(module, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate

    else:
        result['commands'] = []
    module.exit_json(**result)
Exemplo n.º 20
0
def main():
    argument_spec = dict(
        prefix=dict(required=True, type='str'),
        next_hop=dict(required=True, type='str'),
        vrf=dict(type='str', default='default'),
        tag=dict(type='str'),
        route_name=dict(type='str'),
        pref=dict(type='str'),
        state=dict(choices=['absent', 'present'], default='present'),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    prefix = normalize_prefix(module, module.params['prefix'])

    candidate = CustomNetworkConfig(indent=3)
    reconcile_candidate(module, candidate, prefix)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['commands'] = candidate
        result['changed'] = True
    else:
        result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 21
0
def main():
    argument_spec = dict(
        interface=dict(required=True, type='str'),
        vni=dict(required=True, type='str'),
        assoc_vrf=dict(required=False, type='bool'),
        multicast_group=dict(required=False, type='str'),
        peer_list=dict(required=False, type='list'),
        suppress_arp=dict(required=False, type='bool'),
        ingress_replication=dict(required=False, type='str', choices=['bgp', 'static', 'default']),
        state=dict(choices=['present', 'absent'], default='present', required=False),
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    if module.params['assoc_vrf']:
        mutually_exclusive_params = ['multicast_group',
                                     'suppress_arp',
                                     'ingress_replication']
        for param in mutually_exclusive_params:
            if module.params[param]:
                module.fail_json(msg='assoc_vrf cannot be used with '
                                     '{0} param'.format(param))
    if module.params['peer_list']:
        if module.params['peer_list'][0] != 'default' and module.params['ingress_replication'] != 'static':
            module.fail_json(msg='ingress_replication=static is required '
                                 'when using peer_list param')
        else:
            peer_list = module.params['peer_list']
            if peer_list[0] == 'default':
                module.params['peer_list'] = 'default'
            else:
                stripped_peer_list = map(str.strip, peer_list)
                module.params['peer_list'] = stripped_peer_list

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing, interface_exist = get_existing(module, args)

    if state == 'present':
        if not interface_exist:
            module.fail_json(msg="The proposed NVE interface does not exist. Use nxos_interface to create it first.")
        elif interface_exist != module.params['interface']:
            module.fail_json(msg='Only 1 NVE interface is allowed on the switch.')
    elif state == 'absent':
        if interface_exist != module.params['interface']:
            module.exit_json(**result)
        elif existing and existing['vni'] != module.params['vni']:
            module.fail_json(
                msg="ERROR: VNI delete failed: Could not find vni node for {0}".format(module.params['vni']),
                existing_vni=existing['vni']
            )

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key in ['multicast_group', 'peer_list', 'ingress_replication']:
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
        if key != 'interface' and existing.get(key) != value:
            proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif existing and state == 'absent':
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['changed'] = True
        result['commands'] = candidate
        if not module.check_mode:
            load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 22
0
def main():
    argument_spec = dict(
        interface=dict(required=True, type='str'),
        ospf=dict(required=True, type='str'),
        area=dict(required=True, type='str'),
        cost=dict(required=False, type='str'),
        hello_interval=dict(required=False, type='str'),
        dead_interval=dict(required=False, type='str'),
        passive_interface=dict(required=False, type='bool'),
        message_digest=dict(required=False, type='bool'),
        message_digest_key_id=dict(required=False, type='str'),
        message_digest_algorithm_type=dict(required=False, type='str', choices=['md5', 'default']),
        message_digest_encryption_type=dict(required=False, type='str', choices=['cisco_type_7', '3des', 'default']),
        message_digest_password=dict(required=False, type='str', no_log=True),
        state=dict(choices=['present', 'absent'], default='present', required=False)
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           required_together=[['message_digest_key_id',
                                               'message_digest_algorithm_type',
                                               'message_digest_encryption_type',
                                               'message_digest_password']],
                           supports_check_mode=True)

    # Normalize interface input data.
    #
    # * For port-channel and loopback interfaces expection is all lower case names.
    # * All other interfaces the expectation is an uppercase leading character
    #   followed by lower case characters.
    #
    if re.match(r'(port-channel|loopback)', module.params['interface'], re.I):
        module.params['interface'] = module.params['interface'].lower()
    else:
        module.params['interface'] = module.params['interface'].capitalize()

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    for param in ['message_digest_encryption_type',
                  'message_digest_algorithm_type',
                  'message_digest_password']:
        if module.params[param] == 'default' and module.params['message_digest_key_id'] != 'default':
            module.exit_json(msg='Use message_digest_key_id=default to remove an existing authentication configuration')

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'interface':
            if str(value).lower() == 'true':
                value = True
            elif str(value).lower() == 'false':
                value = False
            elif str(value).lower() == 'default':
                value = 'default'
            if existing.get(key) or (not existing.get(key) and value):
                proposed[key] = value

    proposed['area'] = normalize_area(proposed['area'], module)
    if 'hello_interval' in proposed and proposed['hello_interval'] == '10':
        proposed['hello_interval'] = 'default'

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing.get('ospf') == proposed['ospf'] and existing.get('area') == proposed['area']:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate

    module.exit_json(**result)
Exemplo n.º 23
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type='str'),
        vrf=dict(required=False, type='str', default='default'),
        neighbor=dict(required=True, type='str'),
        afi=dict(required=True, type='str'),
        safi=dict(required=True, type='str'),
        additional_paths_receive=dict(required=False, type='str', choices=['enable', 'disable', 'inherit']),
        additional_paths_send=dict(required=False, type='str', choices=['enable', 'disable', 'inherit']),
        advertise_map_exist=dict(required=False, type='list'),
        advertise_map_non_exist=dict(required=False, type='list'),
        allowas_in=dict(required=False, type='bool'),
        allowas_in_max=dict(required=False, type='str'),
        as_override=dict(required=False, type='bool'),
        default_originate=dict(required=False, type='bool'),
        default_originate_route_map=dict(required=False, type='str'),
        disable_peer_as_check=dict(required=False, type='bool'),
        filter_list_in=dict(required=False, type='str'),
        filter_list_out=dict(required=False, type='str'),
        max_prefix_limit=dict(required=False, type='str'),
        max_prefix_interval=dict(required=False, type='str'),
        max_prefix_threshold=dict(required=False, type='str'),
        max_prefix_warning=dict(required=False, type='bool'),
        next_hop_self=dict(required=False, type='bool'),
        next_hop_third_party=dict(required=False, type='bool'),
        prefix_list_in=dict(required=False, type='str'),
        prefix_list_out=dict(required=False, type='str'),
        route_map_in=dict(required=False, type='str'),
        route_map_out=dict(required=False, type='str'),
        route_reflector_client=dict(required=False, type='bool'),
        send_community=dict(required=False, choices=['none', 'both', 'extended', 'standard', 'default']),
        soft_reconfiguration_in=dict(required=False, type='str', choices=['enable', 'always', 'inherit']),
        soo=dict(required=False, type='str'),
        suppress_inactive=dict(required=False, type='bool'),
        unsuppress_map=dict(required=False, type='str'),
        weight=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'], default='present', required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[['advertise_map_exist', 'advertise_map_non_exist'],
                            ['max_prefix_interval', 'max_prefix_warning'],
                            ['default_originate', 'default_originate_route_map'],
                            ['allowas_in', 'allowas_in_max']],
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']
    for key in ['max_prefix_interval', 'max_prefix_warning', 'max_prefix_threshold']:
        if module.params[key] and not module.params['max_prefix_limit']:
            module.fail_json(
                msg='max_prefix_limit is required when using %s' % key
            )
    if module.params['vrf'] == 'default' and module.params['soo']:
        module.fail_json(msg='SOO is only allowed in non-default VRF')

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get('asn') and state == 'present':
        if existing.get('asn') != module.params['asn']:
            module.fail_json(msg='Another BGP ASN already exists.',
                             proposed_asn=module.params['asn'],
                             existing_asn=existing.get('asn'))

    for param in ['advertise_map_exist', 'advertise_map_non_exist']:
        if module.params[param] == ['default']:
            module.params[param] = 'default'

    proposed_args = dict((k, v) for k, v in module.params.items() if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key not in ['asn', 'vrf', 'neighbor']:
            if not isinstance(value, list):
                if str(value).lower() == 'true':
                    value = True
                elif str(value).lower() == 'false':
                    value = False
                elif str(value).lower() == 'default':
                    if key in BOOL_PARAMS:
                        value = False
                    else:
                        value = 'default'
                elif key == 'send_community' and str(value).lower() == 'none':
                    value = 'default'
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate
    else:
        result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 24
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type="str"),
        vrf=dict(required=False, type="str", default="default"),
        neighbor=dict(required=True, type="str"),
        afi=dict(required=True, type="str"),
        safi=dict(required=True, type="str"),
        additional_paths_receive=dict(
            required=False,
            type="str",
            choices=["enable", "disable", "inherit"],
        ),
        additional_paths_send=dict(
            required=False,
            type="str",
            choices=["enable", "disable", "inherit"],
        ),
        advertise_map_exist=dict(required=False, type="list"),
        advertise_map_non_exist=dict(required=False, type="list"),
        allowas_in=dict(required=False, type="bool"),
        allowas_in_max=dict(required=False, type="str"),
        as_override=dict(required=False, type="bool"),
        default_originate=dict(required=False, type="bool"),
        default_originate_route_map=dict(required=False, type="str"),
        disable_peer_as_check=dict(required=False, type="bool"),
        filter_list_in=dict(required=False, type="str"),
        filter_list_out=dict(required=False, type="str"),
        max_prefix_limit=dict(required=False, type="str"),
        max_prefix_interval=dict(required=False, type="str"),
        max_prefix_threshold=dict(required=False, type="str"),
        max_prefix_warning=dict(required=False, type="bool"),
        next_hop_self=dict(required=False, type="bool"),
        next_hop_third_party=dict(required=False, type="bool"),
        prefix_list_in=dict(required=False, type="str"),
        prefix_list_out=dict(required=False, type="str"),
        route_map_in=dict(required=False, type="str"),
        route_map_out=dict(required=False, type="str"),
        route_reflector_client=dict(required=False, type="bool"),
        send_community=dict(
            required=False,
            choices=["none", "both", "extended", "standard", "default"],
        ),
        soft_reconfiguration_in=dict(required=False,
                                     type="str",
                                     choices=["enable", "always", "inherit"]),
        soo=dict(required=False, type="str"),
        suppress_inactive=dict(required=False, type="bool"),
        unsuppress_map=dict(required=False, type="str"),
        weight=dict(required=False, type="str"),
        state=dict(choices=["present", "absent"],
                   default="present",
                   required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[
            ["advertise_map_exist", "advertise_map_non_exist"],
            ["max_prefix_interval", "max_prefix_warning"],
            ["default_originate", "default_originate_route_map"],
            ["allowas_in", "allowas_in_max"],
        ],
        supports_check_mode=True,
    )

    warnings = list()
    result = dict(changed=False, warnings=warnings)

    state = module.params["state"]
    for key in [
            "max_prefix_interval",
            "max_prefix_warning",
            "max_prefix_threshold",
    ]:
        if module.params[key] and not module.params["max_prefix_limit"]:
            module.fail_json(msg="max_prefix_limit is required when using %s" %
                             key)
    if module.params["vrf"] == "default" and module.params["soo"]:
        module.fail_json(msg="SOO is only allowed in non-default VRF")

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get("asn") and state == "present":
        if existing.get("asn") != module.params["asn"]:
            module.fail_json(
                msg="Another BGP ASN already exists.",
                proposed_asn=module.params["asn"],
                existing_asn=existing.get("asn"),
            )

    for param in ["advertise_map_exist", "advertise_map_non_exist"]:
        if module.params[param] == ["default"]:
            module.params[param] = "default"

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key not in ["asn", "vrf", "neighbor"]:
            if not isinstance(value, list):
                if str(value).lower() == "true":
                    value = True
                elif str(value).lower() == "false":
                    value = False
                elif str(value).lower() == "default":
                    if key in BOOL_PARAMS:
                        value = False
                    else:
                        value = "default"
                elif key == "send_community" and str(value).lower() == "none":
                    value = "default"
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == "present":
        state_present(module, existing, proposed, candidate)
    elif state == "absent" and existing:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
        result["changed"] = True
        result["commands"] = candidate
    else:
        result["commands"] = []

    module.exit_json(**result)
Exemplo n.º 25
0
def main():
    argument_spec = dict(
        vrf=dict(required=False, type='str', default='default'),
        ospf=dict(required=True, type='str'),
        router_id=dict(required=False, type='str'),
        default_metric=dict(required=False, type='str'),
        log_adjacency=dict(required=False, type='str', choices=['log', 'detail', 'default']),
        timer_throttle_lsa_start=dict(required=False, type='str'),
        timer_throttle_lsa_hold=dict(required=False, type='str'),
        timer_throttle_lsa_max=dict(required=False, type='str'),
        timer_throttle_spf_start=dict(required=False, type='str'),
        timer_throttle_spf_hold=dict(required=False, type='str'),
        timer_throttle_spf_max=dict(required=False, type='str'),
        auto_cost=dict(required=False, type='str'),
        passive_interface=dict(required=False, type='bool'),
        state=dict(choices=['present', 'absent'], default='present', required=False)
    )

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'interface':
            if str(value).lower() == 'true':
                value = True
            elif str(value).lower() == 'false':
                value = False
            elif str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key)
                if value is None:
                    value = 'default'
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    if state == 'absent' and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate

    else:
        result['commands'] = []
    module.exit_json(**result)
Exemplo n.º 26
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type='str'),
        vrf=dict(required=False, type='str', default='default'),
        safi=dict(required=True,
                  type='str',
                  choices=['unicast', 'multicast', 'evpn']),
        afi=dict(required=True,
                 type='str',
                 choices=['ipv4', 'ipv6', 'vpnv4', 'vpnv6', 'l2vpn']),
        additional_paths_install=dict(required=False, type='bool'),
        additional_paths_receive=dict(required=False, type='bool'),
        additional_paths_selection=dict(required=False, type='str'),
        additional_paths_send=dict(required=False, type='bool'),
        advertise_l2vpn_evpn=dict(required=False, type='bool'),
        client_to_client=dict(required=False, type='bool'),
        dampen_igp_metric=dict(required=False, type='str'),
        dampening_state=dict(required=False, type='bool'),
        dampening_half_time=dict(required=False, type='str'),
        dampening_max_suppress_time=dict(required=False, type='str'),
        dampening_reuse_time=dict(required=False, type='str'),
        dampening_routemap=dict(required=False, type='str'),
        dampening_suppress_time=dict(required=False, type='str'),
        default_information_originate=dict(required=False, type='bool'),
        default_metric=dict(required=False, type='str'),
        distance_ebgp=dict(required=False, type='str'),
        distance_ibgp=dict(required=False, type='str'),
        distance_local=dict(required=False, type='str'),
        inject_map=dict(required=False, type='list'),
        maximum_paths=dict(required=False, type='str'),
        maximum_paths_ibgp=dict(required=False, type='str'),
        networks=dict(required=False, type='list'),
        next_hop_route_map=dict(required=False, type='str'),
        redistribute=dict(required=False, type='list'),
        suppress_inactive=dict(required=False, type='bool'),
        table_map=dict(required=False, type='str'),
        table_map_filter=dict(required=False, type='bool'),
        state=dict(choices=['present', 'absent'],
                   default='present',
                   required=False),
    )

    argument_spec.update(nxos_argument_spec)

    mutually_exclusive = [('dampening_state', 'dampening_routemap'),
                          ('dampening_state', 'dampening_half_time'),
                          ('dampening_state', 'dampening_suppress_time'),
                          ('dampening_state', 'dampening_reuse_time'),
                          ('dampening_state', 'dampening_max_suppress_time'),
                          ('dampening_routemap', 'dampening_half_time'),
                          ('dampening_routemap', 'dampening_suppress_time'),
                          ('dampening_routemap', 'dampening_reuse_time'),
                          ('dampening_routemap', 'dampening_max_suppress_time')
                          ]

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=mutually_exclusive,
        required_together=[
            DAMPENING_PARAMS,
            ['distance_ibgp', 'distance_ebgp', 'distance_local']
        ],
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']

    if module.params['advertise_l2vpn_evpn']:
        if module.params['vrf'] == 'default':
            module.fail_json(msg='It is not possible to advertise L2VPN '
                             'EVPN in the default VRF. Please specify '
                             'another one.',
                             vrf=module.params['vrf'])

    if module.params['table_map_filter'] and not module.params['table_map']:
        module.fail_json(msg='table_map param is needed when using'
                         ' table_map_filter filter.')

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get('asn') and state == 'present':
        if existing.get('asn') != module.params['asn']:
            module.fail_json(msg='Another BGP ASN already exists.',
                             proposed_asn=module.params['asn'],
                             existing_asn=existing.get('asn'))

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    for arg in ['networks', 'inject_map', 'redistribute']:
        if proposed_args.get(arg):
            if proposed_args[arg][0] == 'default':
                proposed_args[arg] = 'default'

    proposed = {}
    for key, value in proposed_args.items():
        if key not in ['asn', 'vrf']:
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, candidate)

    if candidate:
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate
    else:
        result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 27
0
def main():
    argument_spec = dict(
        rp_address=dict(required=True, type='str'),
        group_list=dict(required=False, type='str'),
        prefix_list=dict(required=False, type='str'),
        route_map=dict(required=False, type='str'),
        bidir=dict(required=False, type='bool'),
        state=dict(choices=['present', 'absent'],
                   default='present',
                   required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           mutually_exclusive=[['group_list', 'route_map'],
                                               ['group_list', 'prefix_list'],
                                               ['route_map', 'prefix_list']],
                           supports_check_mode=True)

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    state = module.params['state']

    args = ['rp_address', 'group_list', 'prefix_list', 'route_map', 'bidir']

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    if module.params['group_list']:
        existing = get_existing(module, args, True)
        proposed = get_proposed(proposed_args, existing)

    else:
        existing = get_existing(module, args, False)
        proposed = get_proposed(proposed_args, existing)

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present' and (proposed or not existing):
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['commands'] = candidate
        result['changed'] = True
        msgs = load_config(module, candidate, True)
        if msgs:
            for item in msgs:
                if item:
                    if isinstance(item, dict):
                        err_str = item['clierror']
                    else:
                        err_str = item
                    if 'No policy was configured' in err_str:
                        if state == 'absent':
                            addr = module.params['rp_address']
                            new_cmd = 'no ip pim rp-address {0}'.format(addr)
                            load_config(module, new_cmd)

    module.exit_json(**result)
Exemplo n.º 28
0
def main():
    argument_spec = dict(
        interface=dict(required=True, type='str'),
        vni=dict(required=True, type='str'),
        assoc_vrf=dict(required=False, type='bool'),
        multicast_group=dict(required=False, type='str'),
        peer_list=dict(required=False, type='list'),
        suppress_arp=dict(required=False, type='bool'),
        suppress_arp_disable=dict(required=False, type='bool'),
        ingress_replication=dict(required=False,
                                 type='str',
                                 choices=['bgp', 'static', 'default']),
        state=dict(choices=['present', 'absent'],
                   default='present',
                   required=False),
    )

    argument_spec.update(nxos_argument_spec)

    mutually_exclusive = [('suppress_arp', 'suppress_arp_disable'),
                          ('assoc_vrf', 'multicast_group'),
                          ('assoc_vrf', 'suppress_arp'),
                          ('assoc_vrf', 'suppress_arp_disable'),
                          ('assoc_vrf', 'ingress_replication')]
    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=mutually_exclusive,
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    if module.params['peer_list']:
        if module.params['peer_list'][0] != 'default' and module.params[
                'ingress_replication'] != 'static':
            module.fail_json(msg='ingress_replication=static is required '
                             'when using peer_list param')
        else:
            peer_list = module.params['peer_list']
            if peer_list[0] == 'default':
                module.params['peer_list'] = 'default'
            else:
                stripped_peer_list = list(map(str.strip, peer_list))
                module.params['peer_list'] = stripped_peer_list

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing, interface_exist = get_existing(module, args)

    if state == 'present':
        if not interface_exist:
            module.fail_json(
                msg=
                "The proposed NVE interface does not exist. Use nxos_interface to create it first."
            )
        elif interface_exist != module.params['interface']:
            module.fail_json(
                msg='Only 1 NVE interface is allowed on the switch.')
    elif state == 'absent':
        if interface_exist != module.params['interface']:
            module.exit_json(**result)
        elif existing and existing['vni'] != module.params['vni']:
            module.fail_json(
                msg="ERROR: VNI delete failed: Could not find vni node for {0}"
                .format(module.params['vni']),
                existing_vni=existing['vni'])

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key in ['multicast_group', 'peer_list', 'ingress_replication']:
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
        if key != 'interface' and existing.get(key) != value:
            proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif existing and state == 'absent':
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result['changed'] = True
        result['commands'] = candidate
        if not module.check_mode:
            load_config(module, candidate)

    module.exit_json(**result)
def main():
    argument_spec = dict(
        interface=dict(required=True, type="str"),
        vni=dict(required=True, type="str"),
        assoc_vrf=dict(required=False, type="bool"),
        multicast_group=dict(required=False, type="str"),
        peer_list=dict(required=False, type="list"),
        suppress_arp=dict(required=False, type="bool"),
        suppress_arp_disable=dict(required=False, type="bool"),
        ingress_replication=dict(
            required=False, type="str", choices=["bgp", "static", "default"]
        ),
        state=dict(
            choices=["present", "absent"], default="present", required=False
        ),
    )

    argument_spec.update(nxos_argument_spec)

    mutually_exclusive = [
        ("suppress_arp", "suppress_arp_disable"),
        ("assoc_vrf", "multicast_group"),
        ("assoc_vrf", "suppress_arp"),
        ("assoc_vrf", "suppress_arp_disable"),
        ("assoc_vrf", "ingress_replication"),
    ]
    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=mutually_exclusive,
        supports_check_mode=True,
    )

    warnings = list()
    result = {"changed": False, "commands": [], "warnings": warnings}

    if module.params["peer_list"]:
        if (
            module.params["peer_list"][0] != "default"
            and module.params["ingress_replication"] != "static"
        ):
            module.fail_json(
                msg="ingress_replication=static is required "
                "when using peer_list param"
            )
        else:
            peer_list = module.params["peer_list"]
            if peer_list[0] == "default":
                module.params["peer_list"] = "default"
            else:
                stripped_peer_list = map(str.strip, peer_list)
                module.params["peer_list"] = stripped_peer_list

    state = module.params["state"]
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing, interface_exist = get_existing(module, args)

    if state == "present":
        if not interface_exist:
            module.fail_json(
                msg="The proposed NVE interface does not exist. Use nxos_interface to create it first."
            )
        elif interface_exist != module.params["interface"]:
            module.fail_json(
                msg="Only 1 NVE interface is allowed on the switch."
            )
    elif state == "absent":
        if interface_exist != module.params["interface"]:
            module.exit_json(**result)
        elif existing and existing["vni"] != module.params["vni"]:
            module.fail_json(
                msg="ERROR: VNI delete failed: Could not find vni node for {0}".format(
                    module.params["vni"]
                ),
                existing_vni=existing["vni"],
            )

    proposed_args = dict(
        (k, v) for k, v in module.params.items() if v is not None and k in args
    )

    proposed = {}
    for key, value in proposed_args.items():
        if key in ["multicast_group", "peer_list", "ingress_replication"]:
            if str(value).lower() == "default":
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, "default")
        if key != "interface" and existing.get(key) != value:
            proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == "present":
        state_present(module, existing, proposed, candidate)
    elif existing and state == "absent":
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result["changed"] = True
        result["commands"] = candidate
        if not module.check_mode:
            load_config(module, candidate)

    module.exit_json(**result)
Exemplo n.º 30
0
def main():
    argument_spec = dict(vni=dict(required=True, type='str'),
                         route_distinguisher=dict(required=False, type='str'),
                         route_target_both=dict(required=False, type='list'),
                         route_target_import=dict(required=False, type='list'),
                         route_target_export=dict(required=False, type='list'),
                         state=dict(choices=['present', 'absent'],
                                    default='present',
                                    required=False))

    argument_spec.update(nxos_argument_spec)

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

    warnings = list()
    check_args(module, warnings)
    results = dict(changed=False, warnings=warnings)

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    commands = []
    parents = []

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'vni':
            if value == 'true':
                value = True
            elif value == 'false':
                value = False
            if existing.get(key) != value:
                proposed[key] = value

    if state == 'present':
        commands, parents = state_present(module, existing, proposed)
    elif state == 'absent' and existing:
        commands, parents = state_absent(module, existing, proposed)

    if commands:
        if (existing.get('route_distinguisher')
                and proposed.get('route_distinguisher')):
            if (existing['route_distinguisher'] !=
                    proposed['route_distinguisher']
                    and proposed['route_distinguisher'] != 'default'):
                warnings.append('EVPN RD {0} was automatically removed. '
                                'It is highly recommended to use a task '
                                '(with default as value) to explicitly '
                                'unconfigure it.'.format(
                                    existing['route_distinguisher']))
                remove_commands = [
                    'no rd {0}'.format(existing['route_distinguisher'])
                ]

                candidate = CustomNetworkConfig(indent=3)
                candidate.add(remove_commands, parents=parents)
                load_config(module, candidate)
                results['changed'] = True
                results['commands'] = candidate.items_text()
                time.sleep(30)

        else:
            candidate = CustomNetworkConfig(indent=3)
            candidate.add(commands, parents=parents)
            candidate = candidate.items_text()
            load_config(module, candidate)
            results['changed'] = True
            results['commands'] = candidate
    else:
        results['commands'] = []
    module.exit_json(**results)
Exemplo n.º 31
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type='str'),
        vrf=dict(required=False, type='str', default='default'),
        neighbor=dict(required=True, type='str'),
        description=dict(required=False, type='str'),
        capability_negotiation=dict(required=False, type='bool'),
        connected_check=dict(required=False, type='bool'),
        dynamic_capability=dict(required=False, type='bool'),
        ebgp_multihop=dict(required=False, type='str'),
        local_as=dict(required=False, type='str'),
        log_neighbor_changes=dict(required=False, type='str', choices=['enable', 'disable', 'inherit']),
        low_memory_exempt=dict(required=False, type='bool'),
        maximum_peers=dict(required=False, type='str'),
        pwd=dict(required=False, type='str'),
        pwd_type=dict(required=False, type='str', choices=['3des', 'cisco_type_7', 'default']),
        remote_as=dict(required=False, type='str'),
        remove_private_as=dict(required=False, type='str', choices=['enable', 'disable', 'all', 'replace-as']),
        shutdown=dict(required=False, type='bool'),
        suppress_4_byte_as=dict(required=False, type='bool'),
        timers_keepalive=dict(required=False, type='str'),
        timers_holdtime=dict(required=False, type='str'),
        transport_passive_only=dict(required=False, type='bool'),
        update_source=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'], default='present', required=False)
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_together=[['timers_holdtime', 'timers_keepalive'], ['pwd', 'pwd_type']],
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']

    if module.params['pwd_type'] == 'default':
        module.params['pwd_type'] = '0'

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get('asn') and state == 'present':
        if existing['asn'] != module.params['asn']:
            module.fail_json(msg='Another BGP ASN already exists.',
                             proposed_asn=module.params['asn'],
                             existing_asn=existing.get('asn'))

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    proposed = {}
    for key, value in proposed_args.items():
        if key not in ['asn', 'vrf', 'neighbor', 'pwd_type']:
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate
    else:
        result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 32
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type="str"),
        vrf=dict(required=False, type="str", default="default"),
        neighbor=dict(required=True, type="str"),
        description=dict(required=False, type="str"),
        bfd=dict(required=False, type="str", choices=["enable", "disable"]),
        capability_negotiation=dict(required=False, type="bool"),
        connected_check=dict(required=False, type="bool"),
        dynamic_capability=dict(required=False, type="bool"),
        ebgp_multihop=dict(required=False, type="str"),
        local_as=dict(required=False, type="str"),
        log_neighbor_changes=dict(
            required=False,
            type="str",
            choices=["enable", "disable", "inherit"],
        ),
        low_memory_exempt=dict(required=False, type="bool"),
        maximum_peers=dict(required=False, type="str"),
        pwd=dict(required=False, type="str"),
        pwd_type=dict(
            required=False,
            type="str",
            choices=["3des", "cisco_type_7", "default"],
        ),
        remote_as=dict(required=False, type="str"),
        remove_private_as=dict(
            required=False,
            type="str",
            choices=["enable", "disable", "all", "replace-as"],
        ),
        shutdown=dict(required=False, type="bool"),
        suppress_4_byte_as=dict(required=False, type="bool"),
        timers_keepalive=dict(required=False, type="str"),
        timers_holdtime=dict(required=False, type="str"),
        transport_passive_only=dict(required=False, type="bool"),
        update_source=dict(required=False, type="str"),
        state=dict(
            choices=["present", "absent"], default="present", required=False
        ),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_together=[
            ["timers_holdtime", "timers_keepalive"],
            ["pwd", "pwd_type"],
        ],
        supports_check_mode=True,
    )

    warnings = list()
    result = dict(changed=False, warnings=warnings)

    state = module.params["state"]

    if module.params["pwd_type"] == "default":
        module.params["pwd_type"] = "0"

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get("asn") and state == "present":
        if existing["asn"] != module.params["asn"]:
            module.fail_json(
                msg="Another BGP ASN already exists.",
                proposed_asn=module.params["asn"],
                existing_asn=existing.get("asn"),
            )

    proposed_args = dict(
        (k, v) for k, v in module.params.items() if v is not None and k in args
    )
    proposed = {}
    for key, value in proposed_args.items():
        if key not in ["asn", "vrf", "neighbor", "pwd_type"]:
            if str(value).lower() == "default":
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, "default")
            if key == "bfd":
                if existing.get("bfd", "disable") != value:
                    proposed[key] = value
            elif existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == "present":
        state_present(module, existing, proposed, candidate)
    elif state == "absent" and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
        result["changed"] = True
        result["commands"] = candidate
    else:
        result["commands"] = []

    module.exit_json(**result)
Exemplo n.º 33
0
def main():
    argument_spec = dict(
        rp_address=dict(required=True, type="str"),
        group_list=dict(required=False, type="str"),
        prefix_list=dict(required=False, type="str"),
        route_map=dict(required=False, type="str"),
        bidir=dict(required=False, type="bool"),
        state=dict(choices=["present", "absent"],
                   default="present",
                   required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[
            ["group_list", "route_map"],
            ["group_list", "prefix_list"],
            ["route_map", "prefix_list"],
        ],
        supports_check_mode=True,
    )

    warnings = list()
    result = {"changed": False, "commands": [], "warnings": warnings}

    state = module.params["state"]

    args = ["rp_address", "group_list", "prefix_list", "route_map", "bidir"]

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    if module.params["group_list"]:
        existing = get_existing(module, args, True)
        proposed = get_proposed(proposed_args, existing)

    else:
        existing = get_existing(module, args, False)
        proposed = get_proposed(proposed_args, existing)

    candidate = CustomNetworkConfig(indent=3)
    if state == "present" and (proposed or not existing):
        state_present(module, existing, proposed, candidate)
    elif state == "absent" and existing:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        result["commands"] = candidate
        result["changed"] = True
        msgs = load_config(module, candidate, True)
        if msgs:
            for item in msgs:
                if item:
                    if isinstance(item, dict):
                        err_str = item["clierror"]
                    else:
                        err_str = item
                    if "No policy was configured" in err_str:
                        if state == "absent":
                            addr = module.params["rp_address"]
                            new_cmd = "no ip pim rp-address {0}".format(addr)
                            load_config(module, new_cmd)

    module.exit_json(**result)
Exemplo n.º 34
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type='str'),
        vrf=dict(required=False, type='str', default='default'),
        neighbor=dict(required=True, type='str'),
        afi=dict(required=True, type='str'),
        safi=dict(required=True, type='str'),
        additional_paths_receive=dict(required=False,
                                      type='str',
                                      choices=['enable', 'disable',
                                               'inherit']),
        additional_paths_send=dict(required=False,
                                   type='str',
                                   choices=['enable', 'disable', 'inherit']),
        advertise_map_exist=dict(required=False, type='list'),
        advertise_map_non_exist=dict(required=False, type='list'),
        allowas_in=dict(required=False, type='bool'),
        allowas_in_max=dict(required=False, type='str'),
        as_override=dict(required=False, type='bool'),
        default_originate=dict(required=False, type='bool'),
        default_originate_route_map=dict(required=False, type='str'),
        disable_peer_as_check=dict(required=False, type='bool'),
        filter_list_in=dict(required=False, type='str'),
        filter_list_out=dict(required=False, type='str'),
        max_prefix_limit=dict(required=False, type='str'),
        max_prefix_interval=dict(required=False, type='str'),
        max_prefix_threshold=dict(required=False, type='str'),
        max_prefix_warning=dict(required=False, type='bool'),
        next_hop_self=dict(required=False, type='bool'),
        next_hop_third_party=dict(required=False, type='bool'),
        prefix_list_in=dict(required=False, type='str'),
        prefix_list_out=dict(required=False, type='str'),
        route_map_in=dict(required=False, type='str'),
        route_map_out=dict(required=False, type='str'),
        route_reflector_client=dict(required=False, type='bool'),
        send_community=dict(
            required=False,
            choices=['none', 'both', 'extended', 'standard', 'default']),
        soft_reconfiguration_in=dict(required=False,
                                     type='str',
                                     choices=['enable', 'always', 'inherit']),
        soo=dict(required=False, type='str'),
        suppress_inactive=dict(required=False, type='bool'),
        unsuppress_map=dict(required=False, type='str'),
        weight=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'],
                   default='present',
                   required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[['advertise_map_exist', 'advertise_map_non_exist'],
                            ['max_prefix_interval', 'max_prefix_warning'],
                            [
                                'default_originate',
                                'default_originate_route_map'
                            ], ['allowas_in', 'allowas_in_max']],
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']
    for key in [
            'max_prefix_interval', 'max_prefix_warning', 'max_prefix_threshold'
    ]:
        if module.params[key] and not module.params['max_prefix_limit']:
            module.fail_json(msg='max_prefix_limit is required when using %s' %
                             key)
    if module.params['vrf'] == 'default' and module.params['soo']:
        module.fail_json(msg='SOO is only allowed in non-default VRF')

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get('asn') and state == 'present':
        if existing.get('asn') != module.params['asn']:
            module.fail_json(msg='Another BGP ASN already exists.',
                             proposed_asn=module.params['asn'],
                             existing_asn=existing.get('asn'))

    for param in ['advertise_map_exist', 'advertise_map_non_exist']:
        if module.params[param] == ['default']:
            module.params[param] = 'default'

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key not in ['asn', 'vrf', 'neighbor']:
            if not isinstance(value, list):
                if str(value).lower() == 'true':
                    value = True
                elif str(value).lower() == 'false':
                    value = False
                elif str(value).lower() == 'default':
                    if key in BOOL_PARAMS:
                        value = False
                    else:
                        value = 'default'
                elif key == 'send_community' and str(value).lower() == 'none':
                    value = 'default'
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate
    else:
        result['commands'] = []

    module.exit_json(**result)
def main():
    argument_spec = dict(
        interface=dict(required=True, type="str"),
        ospf=dict(required=True, type="str"),
        area=dict(required=True, type="str"),
        bfd=dict(
            choices=["enable", "disable", "default"],
            required=False,
            type="str",
        ),
        cost=dict(required=False, type="str"),
        hello_interval=dict(required=False, type="str"),
        dead_interval=dict(required=False, type="str"),
        passive_interface=dict(required=False, type="bool"),
        network=dict(
            required=False, type="str", choices=["broadcast", "point-to-point"]
        ),
        message_digest=dict(required=False, type="bool"),
        message_digest_key_id=dict(required=False, type="str"),
        message_digest_algorithm_type=dict(
            required=False, type="str", choices=["md5", "default"]
        ),
        message_digest_encryption_type=dict(
            required=False,
            type="str",
            choices=["cisco_type_7", "3des", "default"],
        ),
        message_digest_password=dict(required=False, type="str", no_log=True),
        state=dict(
            choices=["present", "absent"], default="present", required=False
        ),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_together=[
            [
                "message_digest_key_id",
                "message_digest_algorithm_type",
                "message_digest_encryption_type",
                "message_digest_password",
            ]
        ],
        supports_check_mode=True,
    )

    # Normalize interface input data.
    #
    # * For port-channel and loopback interfaces expection is all lower case names.
    # * All other interfaces the expectation is an uppercase leading character
    #   followed by lower case characters.
    #
    if re.match(r"(port-channel|loopback)", module.params["interface"], re.I):
        module.params["interface"] = module.params["interface"].lower()
    else:
        module.params["interface"] = module.params["interface"].capitalize()

    warnings = list()
    result = {"changed": False, "commands": [], "warnings": warnings}

    for param in [
        "message_digest_encryption_type",
        "message_digest_algorithm_type",
        "message_digest_password",
    ]:
        if (
            module.params[param] == "default"
            and module.params["message_digest_key_id"] != "default"
        ):
            module.exit_json(
                msg="Use message_digest_key_id=default to remove an existing authentication configuration"
            )

    state = module.params["state"]
    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict(
        (k, v) for k, v in module.params.items() if v is not None and k in args
    )

    proposed = {}
    for key, value in proposed_args.items():
        if key != "interface":
            if str(value).lower() == "true":
                value = True
            elif str(value).lower() == "false":
                value = False
            elif str(value).lower() == "default":
                value = "default"
            elif key == "bfd":
                value = str(value).lower()
            if existing.get(key) or (not existing.get(key) and value):
                proposed[key] = value
            elif (
                "passive_interface" in key
                and existing.get(key) is None
                and value is False
            ):
                proposed[key] = value

    proposed["area"] = normalize_area(proposed["area"], module)
    if "hello_interval" in proposed and proposed["hello_interval"] == "10":
        proposed["hello_interval"] = "default"

    candidate = CustomNetworkConfig(indent=3)
    if state == "present":
        state_present(module, existing, proposed, candidate)
    elif (
        state == "absent"
        and existing.get("ospf") == proposed["ospf"]
        and existing.get("area") == proposed["area"]
    ):
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
        result["changed"] = True
        result["commands"] = candidate

    module.exit_json(**result)
Exemplo n.º 36
0
def main():
    argument_spec = dict(
        interface=dict(required=True, type='str'),
        ospf=dict(required=True, type='str'),
        area=dict(required=True, type='str'),
        cost=dict(required=False, type='str'),
        hello_interval=dict(required=False, type='str'),
        dead_interval=dict(required=False, type='str'),
        passive_interface=dict(required=False, type='bool'),
        message_digest=dict(required=False, type='bool'),
        message_digest_key_id=dict(required=False, type='str'),
        message_digest_algorithm_type=dict(required=False, type='str', choices=['md5', 'default']),
        message_digest_encryption_type=dict(required=False, type='str', choices=['cisco_type_7', '3des', 'default']),
        message_digest_password=dict(required=False, type='str', no_log=True),
        state=dict(choices=['present', 'absent'], default='present', required=False)
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           required_together=[['message_digest_key_id',
                                               'message_digest_algorithm_type',
                                               'message_digest_encryption_type',
                                               'message_digest_password']],
                           supports_check_mode=True)

    # Normalize interface input data.
    #
    # * For port-channel and loopback interfaces expection is all lower case names.
    # * All other interfaces the expectation is an uppercase leading character
    #   followed by lower case characters.
    #
    if re.match(r'(port-channel|loopback)', module.params['interface'], re.I):
        module.params['interface'] = module.params['interface'].lower()
    else:
        module.params['interface'] = module.params['interface'].capitalize()

    warnings = list()
    check_args(module, warnings)
    result = {'changed': False, 'commands': [], 'warnings': warnings}

    for param in ['message_digest_encryption_type',
                  'message_digest_algorithm_type',
                  'message_digest_password']:
        if module.params[param] == 'default' and module.params['message_digest_key_id'] != 'default':
            module.exit_json(msg='Use message_digest_key_id=default to remove an existing authentication configuration')

    state = module.params['state']
    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    proposed = {}
    for key, value in proposed_args.items():
        if key != 'interface':
            if str(value).lower() == 'true':
                value = True
            elif str(value).lower() == 'false':
                value = False
            elif str(value).lower() == 'default':
                value = 'default'
            if existing.get(key) or (not existing.get(key) and value):
                proposed[key] = value
            elif 'passive_interface' in key and existing.get(key) is None and value is False:
                proposed[key] = value

    proposed['area'] = normalize_area(proposed['area'], module)
    if 'hello_interval' in proposed and proposed['hello_interval'] == '10':
        proposed['hello_interval'] = 'default'

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing.get('ospf') == proposed['ospf'] and existing.get('area') == proposed['area']:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate

    module.exit_json(**result)
Exemplo n.º 37
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type='str'),
        vrf=dict(required=False, type='str', default='default'),
        bestpath_always_compare_med=dict(required=False, type='bool'),
        bestpath_aspath_multipath_relax=dict(required=False, type='bool'),
        bestpath_compare_neighborid=dict(required=False, type='bool'),
        bestpath_compare_routerid=dict(required=False, type='bool'),
        bestpath_cost_community_ignore=dict(required=False, type='bool'),
        bestpath_med_confed=dict(required=False, type='bool'),
        bestpath_med_missing_as_worst=dict(required=False, type='bool'),
        bestpath_med_non_deterministic=dict(required=False, type='bool'),
        cluster_id=dict(required=False, type='str'),
        confederation_id=dict(required=False, type='str'),
        confederation_peers=dict(required=False, type='list'),
        disable_policy_batching=dict(required=False, type='bool'),
        disable_policy_batching_ipv4_prefix_list=dict(required=False, type='str'),
        disable_policy_batching_ipv6_prefix_list=dict(required=False, type='str'),
        enforce_first_as=dict(required=False, type='bool'),
        event_history_cli=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        event_history_detail=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        event_history_events=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        event_history_periodic=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        fast_external_fallover=dict(required=False, type='bool'),
        flush_routes=dict(required=False, type='bool'),
        graceful_restart=dict(required=False, type='bool'),
        graceful_restart_helper=dict(required=False, type='bool'),
        graceful_restart_timers_restart=dict(required=False, type='str'),
        graceful_restart_timers_stalepath_time=dict(required=False, type='str'),
        isolate=dict(required=False, type='bool'),
        local_as=dict(required=False, type='str'),
        log_neighbor_changes=dict(required=False, type='bool'),
        maxas_limit=dict(required=False, type='str'),
        neighbor_down_fib_accelerate=dict(required=False, type='bool'),
        reconnect_interval=dict(required=False, type='str'),
        router_id=dict(required=False, type='str'),
        shutdown=dict(required=False, type='bool'),
        suppress_fib_pending=dict(required=False, type='bool'),
        timer_bestpath_limit=dict(required=False, type='str'),
        timer_bgp_hold=dict(required=False, type='str'),
        timer_bgp_keepalive=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'], default='present', required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           required_together=[['timer_bgp_hold', 'timer_bgp_keepalive']],
                           supports_check_mode=True)

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']

    if module.params['vrf'] != 'default':
        for param in GLOBAL_PARAMS:
            if module.params[param]:
                module.fail_json(msg='Global params can be modified only under "default" VRF.',
                                 vrf=module.params['vrf'],
                                 global_param=param)

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get('asn') and state == 'present':
        if existing.get('asn') != module.params['asn']:
            module.fail_json(msg='Another BGP ASN already exists.',
                             proposed_asn=module.params['asn'],
                             existing_asn=existing.get('asn'))

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    proposed = {}
    for key, value in proposed_args.items():
        if key not in ['asn', 'vrf']:
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
            if key == 'confederation_peers':
                if value[0] == 'default':
                    if existing.get(key):
                        proposed[key] = 'default'
                else:
                    v = set([int(i) for i in value])
                    ex = set([int(i) for i in existing.get(key)])
                    if v != ex:
                        proposed[key] = ' '.join(str(s) for s in v)
            else:
                if existing.get(key) != value:
                    proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif existing.get('asn') == module.params['asn']:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate
    else:
        result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 38
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type='str'),
        vrf=dict(required=False, type='str', default='default'),
        neighbor=dict(required=True, type='str'),
        description=dict(required=False, type='str'),
        bfd=dict(required=False, type='str', choices=['enable', 'disable']),
        capability_negotiation=dict(required=False, type='bool'),
        connected_check=dict(required=False, type='bool'),
        dynamic_capability=dict(required=False, type='bool'),
        ebgp_multihop=dict(required=False, type='str'),
        local_as=dict(required=False, type='str'),
        log_neighbor_changes=dict(required=False,
                                  type='str',
                                  choices=['enable', 'disable', 'inherit']),
        low_memory_exempt=dict(required=False, type='bool'),
        maximum_peers=dict(required=False, type='str'),
        pwd=dict(required=False, type='str'),
        pwd_type=dict(required=False,
                      type='str',
                      choices=['3des', 'cisco_type_7', 'default']),
        remote_as=dict(required=False, type='str'),
        remove_private_as=dict(
            required=False,
            type='str',
            choices=['enable', 'disable', 'all', 'replace-as']),
        shutdown=dict(required=False, type='bool'),
        suppress_4_byte_as=dict(required=False, type='bool'),
        timers_keepalive=dict(required=False, type='str'),
        timers_holdtime=dict(required=False, type='str'),
        transport_passive_only=dict(required=False, type='bool'),
        update_source=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'],
                   default='present',
                   required=False))
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        required_together=[['timers_holdtime', 'timers_keepalive'],
                           ['pwd', 'pwd_type']],
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']

    if module.params['pwd_type'] == 'default':
        module.params['pwd_type'] = '0'

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get('asn') and state == 'present':
        if existing['asn'] != module.params['asn']:
            module.fail_json(msg='Another BGP ASN already exists.',
                             proposed_asn=module.params['asn'],
                             existing_asn=existing.get('asn'))

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    proposed = {}
    for key, value in proposed_args.items():
        if key not in ['asn', 'vrf', 'neighbor', 'pwd_type']:
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
            if key == 'bfd':
                if existing.get('bfd', 'disable') != value:
                    proposed[key] = value
            elif existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif state == 'absent' and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate
    else:
        result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 39
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type="str"),
        vrf=dict(required=False, type="str", default="default"),
        safi=dict(required=True,
                  type="str",
                  choices=["unicast", "multicast", "evpn"]),
        afi=dict(
            required=True,
            type="str",
            choices=["ipv4", "ipv6", "vpnv4", "vpnv6", "l2vpn"],
        ),
        additional_paths_install=dict(required=False, type="bool"),
        additional_paths_receive=dict(required=False, type="bool"),
        additional_paths_selection=dict(required=False, type="str"),
        additional_paths_send=dict(required=False, type="bool"),
        advertise_l2vpn_evpn=dict(required=False, type="bool"),
        client_to_client=dict(required=False, type="bool"),
        dampen_igp_metric=dict(required=False, type="str"),
        dampening_state=dict(required=False, type="bool"),
        dampening_half_time=dict(required=False, type="str"),
        dampening_max_suppress_time=dict(required=False, type="str"),
        dampening_reuse_time=dict(required=False, type="str"),
        dampening_routemap=dict(required=False, type="str"),
        dampening_suppress_time=dict(required=False, type="str"),
        default_information_originate=dict(required=False, type="bool"),
        default_metric=dict(required=False, type="str"),
        distance_ebgp=dict(required=False, type="str"),
        distance_ibgp=dict(required=False, type="str"),
        distance_local=dict(required=False, type="str"),
        inject_map=dict(required=False, type="list"),
        maximum_paths=dict(required=False, type="str"),
        maximum_paths_ibgp=dict(required=False, type="str"),
        networks=dict(required=False, type="list"),
        next_hop_route_map=dict(required=False, type="str"),
        redistribute=dict(required=False, type="list"),
        suppress_inactive=dict(required=False, type="bool"),
        table_map=dict(required=False, type="str"),
        table_map_filter=dict(required=False, type="bool"),
        state=dict(choices=["present", "absent"],
                   default="present",
                   required=False),
    )

    argument_spec.update(nxos_argument_spec)

    mutually_exclusive = [
        ("dampening_state", "dampening_routemap"),
        ("dampening_state", "dampening_half_time"),
        ("dampening_state", "dampening_suppress_time"),
        ("dampening_state", "dampening_reuse_time"),
        ("dampening_state", "dampening_max_suppress_time"),
        ("dampening_routemap", "dampening_half_time"),
        ("dampening_routemap", "dampening_suppress_time"),
        ("dampening_routemap", "dampening_reuse_time"),
        ("dampening_routemap", "dampening_max_suppress_time"),
    ]

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=mutually_exclusive,
        required_together=[
            DAMPENING_PARAMS,
            ["distance_ibgp", "distance_ebgp", "distance_local"],
        ],
        supports_check_mode=True,
    )

    warnings = list()
    result = dict(changed=False, warnings=warnings)

    state = module.params["state"]

    if module.params["advertise_l2vpn_evpn"]:
        if module.params["vrf"] == "default":
            module.fail_json(
                msg="It is not possible to advertise L2VPN "
                "EVPN in the default VRF. Please specify "
                "another one.",
                vrf=module.params["vrf"],
            )

    if module.params["table_map_filter"] and not module.params["table_map"]:
        module.fail_json(msg="table_map param is needed when using"
                         " table_map_filter filter.")

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get("asn") and state == "present":
        if existing.get("asn") != module.params["asn"]:
            module.fail_json(
                msg="Another BGP ASN already exists.",
                proposed_asn=module.params["asn"],
                existing_asn=existing.get("asn"),
            )

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)

    for arg in ["networks", "inject_map", "redistribute"]:
        if proposed_args.get(arg):
            if proposed_args[arg][0] == "default":
                proposed_args[arg] = "default"

    proposed = {}
    for key, value in proposed_args.items():
        if key not in ["asn", "vrf"]:
            if str(value).lower() == "default":
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, "default")
            if existing.get(key) != value:
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == "present":
        state_present(module, existing, proposed, candidate)
    elif state == "absent" and existing:
        state_absent(module, candidate)

    if candidate:
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
        result["changed"] = True
        result["commands"] = candidate
    else:
        result["commands"] = []

    module.exit_json(**result)
Exemplo n.º 40
0
def main():
    argument_spec = dict(
        asn=dict(required=True, type='str'),
        vrf=dict(required=False, type='str', default='default'),
        bestpath_always_compare_med=dict(required=False, type='bool'),
        bestpath_aspath_multipath_relax=dict(required=False, type='bool'),
        bestpath_compare_neighborid=dict(required=False, type='bool'),
        bestpath_compare_routerid=dict(required=False, type='bool'),
        bestpath_cost_community_ignore=dict(required=False, type='bool'),
        bestpath_med_confed=dict(required=False, type='bool'),
        bestpath_med_missing_as_worst=dict(required=False, type='bool'),
        bestpath_med_non_deterministic=dict(required=False, type='bool'),
        cluster_id=dict(required=False, type='str'),
        confederation_id=dict(required=False, type='str'),
        confederation_peers=dict(required=False, type='list'),
        disable_policy_batching=dict(required=False, type='bool'),
        disable_policy_batching_ipv4_prefix_list=dict(required=False, type='str'),
        disable_policy_batching_ipv6_prefix_list=dict(required=False, type='str'),
        enforce_first_as=dict(required=False, type='bool'),
        event_history_cli=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        event_history_detail=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        event_history_events=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        event_history_periodic=dict(required=False, choices=['true', 'false', 'default', 'size_small', 'size_medium', 'size_large', 'size_disable']),
        fast_external_fallover=dict(required=False, type='bool'),
        flush_routes=dict(required=False, type='bool'),
        graceful_restart=dict(required=False, type='bool'),
        graceful_restart_helper=dict(required=False, type='bool'),
        graceful_restart_timers_restart=dict(required=False, type='str'),
        graceful_restart_timers_stalepath_time=dict(required=False, type='str'),
        isolate=dict(required=False, type='bool'),
        local_as=dict(required=False, type='str'),
        log_neighbor_changes=dict(required=False, type='bool'),
        maxas_limit=dict(required=False, type='str'),
        neighbor_down_fib_accelerate=dict(required=False, type='bool'),
        reconnect_interval=dict(required=False, type='str'),
        router_id=dict(required=False, type='str'),
        shutdown=dict(required=False, type='bool'),
        suppress_fib_pending=dict(required=False, type='bool'),
        timer_bestpath_limit=dict(required=False, type='str'),
        timer_bgp_hold=dict(required=False, type='str'),
        timer_bgp_keepalive=dict(required=False, type='str'),
        state=dict(choices=['present', 'absent'], default='present', required=False),
    )
    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec,
                           required_together=[['timer_bgp_hold', 'timer_bgp_keepalive']],
                           supports_check_mode=True)

    warnings = list()
    result = dict(changed=False, warnings=warnings)

    state = module.params['state']

    if module.params['vrf'] != 'default':
        for param in GLOBAL_PARAMS:
            if module.params[param]:
                module.fail_json(msg='Global params can be modified only under "default" VRF.',
                                 vrf=module.params['vrf'],
                                 global_param=param)

    args = PARAM_TO_COMMAND_KEYMAP.keys()
    existing = get_existing(module, args, warnings)

    if existing.get('asn') and state == 'present':
        if existing.get('asn') != module.params['asn']:
            module.fail_json(msg='Another BGP ASN already exists.',
                             proposed_asn=module.params['asn'],
                             existing_asn=existing.get('asn'))

    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    proposed = {}
    for key, value in proposed_args.items():
        if key not in ['asn', 'vrf']:
            if str(value).lower() == 'default':
                value = PARAM_TO_DEFAULT_KEYMAP.get(key, 'default')
            if key == 'confederation_peers':
                if value[0] == 'default':
                    if existing.get(key):
                        proposed[key] = 'default'
                else:
                    v = set([int(i) for i in value])
                    ex = set([int(i) for i in existing.get(key)])
                    if v != ex:
                        proposed[key] = ' '.join(str(s) for s in v)
            else:
                if existing.get(key) != value:
                    proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)
    if state == 'present':
        state_present(module, existing, proposed, candidate)
    elif existing.get('asn') == module.params['asn']:
        state_absent(module, existing, candidate)

    if candidate:
        candidate = candidate.items_text()
        if not module.check_mode:
            load_config(module, candidate)
        result['changed'] = True
        result['commands'] = candidate
    else:
        result['commands'] = []

    module.exit_json(**result)
Exemplo n.º 41
0
def main():
    argument_spec = dict(
        interface=dict(required=True, type="str"),
        description=dict(required=False, type="str"),
        host_reachability=dict(required=False, type="bool"),
        global_ingress_replication_bgp=dict(required=False, type="bool"),
        global_suppress_arp=dict(required=False, type="bool"),
        global_mcast_group_L2=dict(required=False, type="str"),
        global_mcast_group_L3=dict(required=False, type="str"),
        shutdown=dict(required=False, type="bool"),
        source_interface=dict(required=False, type="str"),
        source_interface_hold_down_time=dict(required=False, type="str"),
        state=dict(choices=["present", "absent"],
                   default="present",
                   required=False),
    )

    argument_spec.update(nxos_argument_spec)

    mutually_exclusive = [("global_ingress_replication_bgp",
                           "global_mcast_group_L2")]

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=mutually_exclusive,
        supports_check_mode=True,
    )

    warnings = list()
    result = {"changed": False, "commands": [], "warnings": warnings}

    state = module.params["state"]

    args = PARAM_TO_COMMAND_KEYMAP.keys()

    existing = get_existing(module, args)
    proposed_args = dict((k, v) for k, v in module.params.items()
                         if v is not None and k in args)
    proposed = {}
    for key, value in proposed_args.items():
        if key != "interface":
            if str(value).lower() == "default":
                value = PARAM_TO_DEFAULT_KEYMAP.get(key)
                if value is None:
                    if key in BOOL_PARAMS:
                        value = False
                    else:
                        value = "default"
            if str(existing.get(key)).lower() != str(value).lower():
                proposed[key] = value

    candidate = CustomNetworkConfig(indent=3)

    if proposed.get("global_suppress_arp"):
        gsa_tcam_check(module)
    if state == "present":
        if not existing:
            warnings.append("The proposed NVE interface did not exist. "
                            "It's recommended to use nxos_interface to create "
                            "all logical interfaces.")
        state_present(module, existing, proposed, candidate)
    elif state == "absent" and existing:
        state_absent(module, existing, proposed, candidate)

    if candidate:
        candidate = candidate.items_text()
        result["commands"] = candidate
        result["changed"] = True
        load_config(module, candidate)

    module.exit_json(**result)