mso_st_filter_entry: Fix various issues (#53241)

This PR includes:
- Use the correct module name in the examples
- Small improvement in logic
- Fix an issue where updating an existing entry could reset to defaults
pull/53255/head
Dag Wieers 5 years ago committed by GitHub
parent 9c2879d8e6
commit e4093fbad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -116,8 +116,8 @@ extends_documentation_fragment: mso
''' '''
EXAMPLES = r''' EXAMPLES = r'''
- name: Add a new filter - name: Add a new filter entry
mso_schema_template_filter: mso_schema_template_filter_entry:
host: mso_host host: mso_host
username: admin username: admin
password: SomeSecretPassword password: SomeSecretPassword
@ -127,8 +127,8 @@ EXAMPLES = r'''
state: present state: present
delegate_to: localhost delegate_to: localhost
- name: Remove a filter - name: Remove a filter entry
mso_schema_template_filter: mso_schema_template_filter_entry:
host: mso_host host: mso_host
username: admin username: admin
password: SomeSecretPassword password: SomeSecretPassword
@ -138,8 +138,8 @@ EXAMPLES = r'''
state: absent state: absent
delegate_to: localhost delegate_to: localhost
- name: Query a specific filters - name: Query a specific filter entry
mso_schema_template_filter: mso_schema_template_filter_entry:
host: mso_host host: mso_host
username: admin username: admin
password: SomeSecretPassword password: SomeSecretPassword
@ -150,8 +150,8 @@ EXAMPLES = r'''
delegate_to: localhost delegate_to: localhost
register: query_result register: query_result
- name: Query all filters - name: Query all filter entries
mso_schema_template_filter: mso_schema_template_filter_entry:
host: mso_host host: mso_host
username: admin username: admin
password: SomeSecretPassword password: SomeSecretPassword
@ -285,30 +285,31 @@ def main():
elif state == 'present': elif state == 'present':
if display_name is None: if not mso.existing:
display_name = mso.existing.get('displayName', entry) if display_name is None:
if description is None: display_name = entry
description = mso.existing.get('description', '') if description is None:
if ethertype is None: description = ''
ethertype = mso.existing.get('etherType', 'unspecified') if ethertype is None:
if ip_protocol is None: ethertype = 'unspecified'
ip_protocol = mso.existing.get('ipProtocol', 'unspecified') if ip_protocol is None:
if tcp_session_rules is None: ip_protocol = 'unspecified'
tcp_session_rules = mso.existing.get('tcpSessionRules', ['unspecified']) if tcp_session_rules is None:
if source_from is None: tcp_session_rules = ['unspecified']
source_from = mso.existing.get('sourceFrom', 'unspecified') if source_from is None:
if source_to is None: source_from = 'unspecified'
source_to = mso.existing.get('sourceTo', 'unspecified') if source_to is None:
if destination_from is None: source_to = 'unspecified'
destination_from = mso.existing.get('destinationFrom', 'unspecified') if destination_from is None:
if destination_to is None: destination_from = 'unspecified'
destination_to = mso.existing.get('destinationTo', 'unspecified') if destination_to is None:
if arp_flag is None: destination_to = 'unspecified'
arp_flag = mso.existing.get('arpFlag', 'unspecified') if arp_flag is None:
if stateful is None: arp_flag = 'unspecified'
stateful = mso.existing.get('stateful', False) if stateful is None:
if fragments_only is None: stateful = False
fragments_only = mso.existing.get('matchOnlyFragments', False) if fragments_only is None:
fragments_only = False
payload = dict( payload = dict(
name=entry, name=entry,
@ -347,18 +348,8 @@ def main():
else: else:
# Entry exists, we have to update it # Entry exists, we have to update it
ops.append(dict(op='replace', path=entry_path + '/displayName', value=display_name)) for (key, value) in mso.sent.items():
ops.append(dict(op='replace', path=entry_path + '/description', value=description)) ops.append(dict(op='replace', path=entry_path + '/' + key, value=value))
ops.append(dict(op='replace', path=entry_path + '/etherType', value=ethertype))
ops.append(dict(op='replace', path=entry_path + '/ipProtocol', value=ip_protocol))
ops.append(dict(op='replace', path=entry_path + '/tcpSessionRules', value=tcp_session_rules))
ops.append(dict(op='replace', path=entry_path + '/sourceFrom', value=source_from))
ops.append(dict(op='replace', path=entry_path + '/sourceTo', value=source_to))
ops.append(dict(op='replace', path=entry_path + '/destinationFrom', value=destination_from))
ops.append(dict(op='replace', path=entry_path + '/destinationTo', value=destination_to))
ops.append(dict(op='replace', path=entry_path + '/arpFlag', value=arp_flag))
ops.append(dict(op='replace', path=entry_path + '/stateful', value=stateful))
ops.append(dict(op='replace', path=entry_path + '/matchOnlyFragments', value=fragments_only))
mso.existing = mso.proposed mso.existing = mso.proposed

Loading…
Cancel
Save