-
Notifications
You must be signed in to change notification settings - Fork 1k
[ansible] Adding support for multi vlans #1353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ab78b30
7a9fdae
09b9398
78ab5d2
48f23a8
6574f1e
50dd4aa
16687cb
8dfaae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import yaml | ||
| import traceback | ||
|
|
||
| DOCUMENTATION = ''' | ||
| module: droplet_vlan_config.py | ||
| Ansible_version_added: 2.0.0.2 | ||
| short_description: Gather all vlan info related to droplet interfaces | ||
| Description: | ||
| When deploy testbed topology with droplet connected to TOR SONiC, | ||
| gather droplet vlan interfaces info for generating SONiC minigraph file | ||
| arguments: | ||
| vm_topo_config: Topology file; required: True | ||
| port_alias: Port aliases of TOR SONiC; required: True | ||
| vlan_config: vlan config name to use; required: False | ||
|
|
||
| Ansible_facts: | ||
| 'vlan_configs': all Vlans Configuration | ||
| ''' | ||
|
|
||
| EXAMPLES = ''' | ||
| - name: find all vlan configurations for T0 topology | ||
| droplet_vlan_config: | ||
| vm_topo_config: "{{ vm_topo_config }}" | ||
| port_alias: "{{ port_alias }}" | ||
| vlan_config: "{{ vlan_config|default(None) }}" | ||
| ''' | ||
|
|
||
| def main(): | ||
| module = AnsibleModule( | ||
| argument_spec=dict( | ||
| vm_topo_config=dict(required=True), | ||
| port_alias=dict(required=True), | ||
| vlan_config=dict(required=False, type='str', default=None), | ||
| ), | ||
| supports_check_mode=True | ||
| ) | ||
| m_args = module.params | ||
| port_alias = m_args['port_alias'] | ||
| vlan_config = m_args['vlan_config'] | ||
|
|
||
| vlan_configs = {} | ||
| try: | ||
| if len(vlan_config) == 0: | ||
| vlan_config = m_args['vm_topo_config']['DUT']['vlan_configs']['default_vlan_config'] | ||
|
|
||
| vlans = m_args['vm_topo_config']['DUT']['vlan_configs'][vlan_config] | ||
| for vlan, vlan_param in vlans.items(): | ||
| vlan_configs.update({vlan : {}}) | ||
| vlan_configs[vlan]['id'] = vlan_param['id'] | ||
| vlan_configs[vlan]['tag'] = vlan_param['tag'] | ||
| vlan_configs[vlan]['prefix'] = vlan_param['prefix'] | ||
| vlan_configs[vlan]['intfs'] = [port_alias[i] for i in vlan_param['intfs']] | ||
| except Exception as e: | ||
| module.fail_json(msg = traceback.format_exc()) | ||
| else: | ||
| module.exit_json(ansible_facts={'vlan_configs' : vlan_configs}) | ||
|
|
||
| from ansible.module_utils.basic import * | ||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Vlans: | ||
| Vlan100: | ||
| id: 100 | ||
| intfs: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | ||
| tag: 100 | ||
pavel-shirshov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| subnets: 192.168.100.0/21 | ||
|
||
| Vlan200: | ||
| id: 200 | ||
| intfs: [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] | ||
| tag: 200 | ||
| subnets: 192.168.200.0/21 | ||
|
||
Uh oh!
There was an error while loading. Please reload this page.