|
|
@ -52,7 +52,7 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Enable/disable sparse-mode on the interface.
|
|
|
|
- Enable/disable sparse-mode on the interface.
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: true
|
|
|
|
default: false
|
|
|
|
choices: ['true', 'false']
|
|
|
|
choices: ['true', 'false']
|
|
|
|
dr_prio:
|
|
|
|
dr_prio:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -94,7 +94,7 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Configures interface to be a boundary of a PIM domain.
|
|
|
|
- Configures interface to be a boundary of a PIM domain.
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
default: false
|
|
|
|
choices: ['true', 'false']
|
|
|
|
choices: ['true', 'false']
|
|
|
|
neighbor_policy:
|
|
|
|
neighbor_policy:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -172,6 +172,14 @@ PARAM_TO_COMMAND_KEYMAP = {
|
|
|
|
'neighbor_type': '',
|
|
|
|
'neighbor_type': '',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PARAM_TO_DEFAULT_KEYMAP = {
|
|
|
|
|
|
|
|
'dr_prio': '1',
|
|
|
|
|
|
|
|
'hello_interval': '30000',
|
|
|
|
|
|
|
|
'sparse': False,
|
|
|
|
|
|
|
|
'border': False,
|
|
|
|
|
|
|
|
'hello_auth_key': False,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def execute_show_command(command, module, text=False):
|
|
|
|
def execute_show_command(command, module, text=False):
|
|
|
|
if text:
|
|
|
|
if text:
|
|
|
@ -249,156 +257,68 @@ def get_interface_mode(interface, intf_type, module):
|
|
|
|
return mode
|
|
|
|
return mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_jp_policy_out(module, interface):
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
This is a workaround for an nxos structured output problem.
|
|
|
|
|
|
|
|
The 'show ip pim interface' command does not display jp_policy_out
|
|
|
|
|
|
|
|
information properly for all supported nxos platforms when using
|
|
|
|
|
|
|
|
structured output. This method uses the show running information to
|
|
|
|
|
|
|
|
mitigate the problem.
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
command = 'sh run interface {0} all | grep \"jp.*out\"'.format(interface)
|
|
|
|
|
|
|
|
name = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
body = execute_show_command(command, module, text=True)[0]
|
|
|
|
|
|
|
|
except IndexError:
|
|
|
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if body:
|
|
|
|
|
|
|
|
mo = re.search(r'ip pim jp-policy\s+(\S+)\s+out', body)
|
|
|
|
|
|
|
|
if mo:
|
|
|
|
|
|
|
|
name = mo.group(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_pim_interface(module, interface):
|
|
|
|
def get_pim_interface(module, interface):
|
|
|
|
pim_interface = {}
|
|
|
|
pim_interface = {}
|
|
|
|
command = 'show ip pim interface {0}'.format(interface)
|
|
|
|
body = get_config(module, flags=['interface {0}'.format(interface)])
|
|
|
|
body = execute_show_command(command, module, text=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if body:
|
|
|
|
|
|
|
|
if 'not running' not in body[0]:
|
|
|
|
|
|
|
|
body = execute_show_command(command, module)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Some nxos platforms have the TABLE_vrf/ROW_vrf key and some don't
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
get_data = body[0]['TABLE_vrf']['ROW_vrf']['TABLE_iod']['ROW_iod']
|
|
|
|
|
|
|
|
except (KeyError, AttributeError, TypeError, IndexError):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
get_data = body[0]['TABLE_iod']['ROW_iod']
|
|
|
|
|
|
|
|
except (KeyError, AttributeError, TypeError, IndexError):
|
|
|
|
|
|
|
|
return pim_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(get_data.get('dr-priority'), list):
|
|
|
|
|
|
|
|
pim_interface['dr_prio'] = get_data.get('dr-priority')[0]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
pim_interface['dr_prio'] = str(get_data.get('dr-priority'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hello_interval = get_data.get('hello-interval-sec')
|
|
|
|
|
|
|
|
if hello_interval:
|
|
|
|
|
|
|
|
hello_interval_msec = int(get_data.get('hello-interval-sec')) * 1000
|
|
|
|
|
|
|
|
pim_interface['hello_interval'] = str(hello_interval_msec)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
border = get_data.get('is-border')
|
|
|
|
|
|
|
|
border = border.lower() if border else border
|
|
|
|
|
|
|
|
if border == 'true':
|
|
|
|
|
|
|
|
pim_interface['border'] = True
|
|
|
|
|
|
|
|
elif border == 'false':
|
|
|
|
|
|
|
|
pim_interface['border'] = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isauth = get_data.get('isauth-config')
|
|
|
|
|
|
|
|
isauth = isauth.lower() if isauth else isauth
|
|
|
|
|
|
|
|
if isauth == 'true':
|
|
|
|
|
|
|
|
pim_interface['isauth'] = True
|
|
|
|
|
|
|
|
elif isauth == 'false':
|
|
|
|
|
|
|
|
pim_interface['isauth'] = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pim_interface['neighbor_policy'] = get_data.get('nbr-policy-name')
|
|
|
|
pim_interface['neighbor_type'] = None
|
|
|
|
if pim_interface['neighbor_policy'] == 'none configured':
|
|
|
|
|
|
|
|
pim_interface['neighbor_policy'] = None
|
|
|
|
pim_interface['neighbor_policy'] = None
|
|
|
|
|
|
|
|
|
|
|
|
jp_in_policy = get_data.get('jp-in-policy-name')
|
|
|
|
|
|
|
|
pim_interface['jp_policy_in'] = jp_in_policy
|
|
|
|
|
|
|
|
if jp_in_policy == 'none configured':
|
|
|
|
|
|
|
|
pim_interface['jp_policy_in'] = None
|
|
|
|
pim_interface['jp_policy_in'] = None
|
|
|
|
|
|
|
|
pim_interface['jp_policy_out'] = None
|
|
|
|
|
|
|
|
pim_interface['jp_type_in'] = None
|
|
|
|
|
|
|
|
pim_interface['jp_type_out'] = None
|
|
|
|
|
|
|
|
pim_interface['jp_bidir'] = False
|
|
|
|
|
|
|
|
pim_interface['isauth'] = False
|
|
|
|
|
|
|
|
|
|
|
|
pim_interface['jp_policy_out'] = get_jp_policy_out(module, interface)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body = get_config(module, flags=['interface {0}'.format(interface)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jp_configs = []
|
|
|
|
|
|
|
|
neigh = None
|
|
|
|
|
|
|
|
if body:
|
|
|
|
if body:
|
|
|
|
all_lines = body.splitlines()
|
|
|
|
all_lines = body.splitlines()
|
|
|
|
|
|
|
|
|
|
|
|
for each in all_lines:
|
|
|
|
for each in all_lines:
|
|
|
|
if 'jp-policy' in each:
|
|
|
|
if 'jp-policy' in each:
|
|
|
|
jp_configs.append(str(each.strip()))
|
|
|
|
policy_name = \
|
|
|
|
elif 'neighbor-policy' in each:
|
|
|
|
re.search(r'ip pim jp-policy(?: prefix-list)? (\S+)(?: \S+)?', each).group(1)
|
|
|
|
neigh = str(each)
|
|
|
|
|
|
|
|
elif 'sparse-mode' in each:
|
|
|
|
|
|
|
|
pim_interface['sparse'] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pim_interface['neighbor_type'] = None
|
|
|
|
|
|
|
|
neigh_type = None
|
|
|
|
|
|
|
|
if neigh:
|
|
|
|
|
|
|
|
if 'prefix-list' in neigh:
|
|
|
|
|
|
|
|
neigh_type = 'prefix'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
neigh_type = 'routemap'
|
|
|
|
|
|
|
|
pim_interface['neighbor_type'] = neigh_type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
len_existing = len(jp_configs)
|
|
|
|
|
|
|
|
list_of_prefix_type = len([x for x in jp_configs if 'prefix-list' in x])
|
|
|
|
|
|
|
|
jp_type_in = None
|
|
|
|
|
|
|
|
jp_type_out = None
|
|
|
|
|
|
|
|
jp_bidir = False
|
|
|
|
|
|
|
|
if len_existing == 1:
|
|
|
|
|
|
|
|
# determine type
|
|
|
|
|
|
|
|
last_word = jp_configs[0].split(' ')[-1]
|
|
|
|
|
|
|
|
if last_word == 'in':
|
|
|
|
|
|
|
|
if list_of_prefix_type:
|
|
|
|
|
|
|
|
jp_type_in = 'prefix'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
jp_type_in = 'routemap'
|
|
|
|
|
|
|
|
elif last_word == 'out':
|
|
|
|
|
|
|
|
if list_of_prefix_type:
|
|
|
|
|
|
|
|
jp_type_out = 'prefix'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
jp_type_out = 'routemap'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
jp_bidir = True
|
|
|
|
|
|
|
|
if list_of_prefix_type:
|
|
|
|
|
|
|
|
jp_type_in = 'prefix'
|
|
|
|
|
|
|
|
jp_type_out = 'routemap'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
jp_type_in = 'routemap'
|
|
|
|
|
|
|
|
jp_type_out = 'routemap'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
for each in jp_configs:
|
|
|
|
|
|
|
|
last_word = each.split(' ')[-1]
|
|
|
|
|
|
|
|
if last_word == 'in':
|
|
|
|
|
|
|
|
if 'prefix-list' in each:
|
|
|
|
if 'prefix-list' in each:
|
|
|
|
jp_type_in = 'prefix'
|
|
|
|
ptype = 'prefix'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
jp_type_in = 'routemap'
|
|
|
|
ptype = 'routemap'
|
|
|
|
elif last_word == 'out':
|
|
|
|
if 'out' in each:
|
|
|
|
|
|
|
|
pim_interface['jp_policy_out'] = policy_name
|
|
|
|
|
|
|
|
pim_interface['jp_type_out'] = ptype
|
|
|
|
|
|
|
|
elif 'in' in each:
|
|
|
|
|
|
|
|
pim_interface['jp_policy_in'] = policy_name
|
|
|
|
|
|
|
|
pim_interface['jp_type_in'] = ptype
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
pim_interface['jp_policy_in'] = policy_name
|
|
|
|
|
|
|
|
pim_interface['jp_policy_out'] = policy_name
|
|
|
|
|
|
|
|
pim_interface['jp_bidir'] = True
|
|
|
|
|
|
|
|
elif 'neighbor-policy' in each:
|
|
|
|
|
|
|
|
pim_interface['neighbor_policy'] = \
|
|
|
|
|
|
|
|
re.search(r'ip pim neighbor-policy(?: prefix-list)? (\S+)', each).group(1)
|
|
|
|
if 'prefix-list' in each:
|
|
|
|
if 'prefix-list' in each:
|
|
|
|
jp_type_out = 'prefix'
|
|
|
|
pim_interface['neighbor_type'] = 'prefix'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
jp_type_out = 'routemap'
|
|
|
|
pim_interface['neighbor_type'] = 'routemap'
|
|
|
|
|
|
|
|
elif 'ah-md5' in each:
|
|
|
|
pim_interface['jp_type_in'] = jp_type_in
|
|
|
|
pim_interface['isauth'] = True
|
|
|
|
pim_interface['jp_type_out'] = jp_type_out
|
|
|
|
elif 'sparse-mode' in each:
|
|
|
|
pim_interface['jp_bidir'] = jp_bidir
|
|
|
|
pim_interface['sparse'] = True
|
|
|
|
|
|
|
|
elif 'border' in each:
|
|
|
|
|
|
|
|
pim_interface['border'] = True
|
|
|
|
|
|
|
|
elif 'hello-interval' in each:
|
|
|
|
|
|
|
|
pim_interface['hello_interval'] = \
|
|
|
|
|
|
|
|
re.search(r'ip pim hello-interval (\d+)', body).group(1)
|
|
|
|
|
|
|
|
elif 'dr-priority' in each:
|
|
|
|
|
|
|
|
pim_interface['dr_prio'] = \
|
|
|
|
|
|
|
|
re.search(r'ip pim dr-priority (\d+)', body).group(1)
|
|
|
|
|
|
|
|
|
|
|
|
return pim_interface
|
|
|
|
return pim_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fix_delta(delta, existing):
|
|
|
|
def fix_delta(delta, existing):
|
|
|
|
if delta.get('sparse') is False and existing.get('sparse') is None:
|
|
|
|
for key in list(delta):
|
|
|
|
delta.pop('sparse')
|
|
|
|
if key in ['dr_prio', 'hello_interval', 'sparse', 'border']:
|
|
|
|
|
|
|
|
if delta.get(key) == PARAM_TO_DEFAULT_KEYMAP.get(key) and existing.get(key) is None:
|
|
|
|
|
|
|
|
delta.pop(key)
|
|
|
|
return delta
|
|
|
|
return delta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -473,14 +393,12 @@ def config_pim_interface(delta, existing, jp_bidir, isauth):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_pim_interface_defaults():
|
|
|
|
def get_pim_interface_defaults():
|
|
|
|
dr_prio = '1'
|
|
|
|
|
|
|
|
border = False
|
|
|
|
|
|
|
|
hello_interval = '30000'
|
|
|
|
|
|
|
|
hello_auth_key = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
args = dict(dr_prio=dr_prio, border=border,
|
|
|
|
args = dict(dr_prio=PARAM_TO_DEFAULT_KEYMAP.get('dr_prio'),
|
|
|
|
hello_interval=hello_interval,
|
|
|
|
border=PARAM_TO_DEFAULT_KEYMAP.get('border'),
|
|
|
|
hello_auth_key=hello_auth_key)
|
|
|
|
sparse=PARAM_TO_DEFAULT_KEYMAP.get('sparse'),
|
|
|
|
|
|
|
|
hello_interval=PARAM_TO_DEFAULT_KEYMAP.get('hello_interval'),
|
|
|
|
|
|
|
|
hello_auth_key=PARAM_TO_DEFAULT_KEYMAP.get('hello_auth_key'))
|
|
|
|
|
|
|
|
|
|
|
|
default = dict((param, value) for (param, value) in args.items()
|
|
|
|
default = dict((param, value) for (param, value) in args.items()
|
|
|
|
if value is not None)
|
|
|
|
if value is not None)
|
|
|
@ -554,7 +472,7 @@ def config_pim_interface_defaults(existing, jp_bidir, isauth):
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
interface=dict(required=True),
|
|
|
|
interface=dict(required=True),
|
|
|
|
sparse=dict(type='bool', default=True),
|
|
|
|
sparse=dict(type='bool', default=False),
|
|
|
|
dr_prio=dict(type='str'),
|
|
|
|
dr_prio=dict(type='str'),
|
|
|
|
hello_auth_key=dict(type='str'),
|
|
|
|
hello_auth_key=dict(type='str'),
|
|
|
|
hello_interval=dict(type='int'),
|
|
|
|
hello_interval=dict(type='int'),
|
|
|
@ -562,7 +480,7 @@ def main():
|
|
|
|
jp_policy_in=dict(type='str'),
|
|
|
|
jp_policy_in=dict(type='str'),
|
|
|
|
jp_type_out=dict(choices=['prefix', 'routemap']),
|
|
|
|
jp_type_out=dict(choices=['prefix', 'routemap']),
|
|
|
|
jp_type_in=dict(choices=['prefix', 'routemap']),
|
|
|
|
jp_type_in=dict(choices=['prefix', 'routemap']),
|
|
|
|
border=dict(type='bool'),
|
|
|
|
border=dict(type='bool', default=False),
|
|
|
|
neighbor_policy=dict(type='str'),
|
|
|
|
neighbor_policy=dict(type='str'),
|
|
|
|
neighbor_type=dict(choices=['prefix', 'routemap']),
|
|
|
|
neighbor_type=dict(choices=['prefix', 'routemap']),
|
|
|
|
state=dict(choices=['present', 'absent', 'default'], default='present'),
|
|
|
|
state=dict(choices=['present', 'absent', 'default'], default='present'),
|
|
|
@ -617,22 +535,11 @@ def main():
|
|
|
|
command = config_pim_interface(delta, existing, jp_bidir, isauth)
|
|
|
|
command = config_pim_interface(delta, existing, jp_bidir, isauth)
|
|
|
|
if command:
|
|
|
|
if command:
|
|
|
|
commands.append(command)
|
|
|
|
commands.append(command)
|
|
|
|
elif state == 'default':
|
|
|
|
elif state == 'default' or state == 'absent':
|
|
|
|
defaults = config_pim_interface_defaults(existing, jp_bidir, isauth)
|
|
|
|
defaults = config_pim_interface_defaults(existing, jp_bidir, isauth)
|
|
|
|
if defaults:
|
|
|
|
if defaults:
|
|
|
|
commands.append(defaults)
|
|
|
|
commands.append(defaults)
|
|
|
|
|
|
|
|
|
|
|
|
elif state == 'absent':
|
|
|
|
|
|
|
|
if existing.get('sparse') is True:
|
|
|
|
|
|
|
|
delta['sparse'] = False
|
|
|
|
|
|
|
|
# defaults is a list of commands
|
|
|
|
|
|
|
|
defaults = config_pim_interface_defaults(existing, jp_bidir, isauth)
|
|
|
|
|
|
|
|
if defaults:
|
|
|
|
|
|
|
|
commands.append(defaults)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
command = config_pim_interface(delta, existing, jp_bidir, isauth)
|
|
|
|
|
|
|
|
commands.append(command)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if commands:
|
|
|
|
if commands:
|
|
|
|
commands.insert(0, ['interface {0}'.format(interface)])
|
|
|
|
commands.insert(0, ['interface {0}'.format(interface)])
|
|
|
|
|
|
|
|
|
|
|
|