Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ansible/config_sonic_basedon_testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
with_items: "{{ host_if_indexes }}"
when: ("'host_interfaces' in vm_topo_config") and ("'tor' in vm_topo_config['dut_type'] | lower")

- 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) }}"
delegate_to: localhost
when: ("'host_interfaces' in vm_topo_config") and ("'tor' in vm_topo_config['dut_type'] | lower")

- name: find all interface indexes mapping connecting to VM
set_fact:
interface_to_vms: "{{ interface_to_vms|default({}) | combine({ item.key: item.value['interface_indexes'] }) }}"
Expand Down
62 changes: 62 additions & 0 deletions ansible/library/droplet_vlan_config.py
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()
5 changes: 5 additions & 0 deletions ansible/library/topo_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def get_topo_config(self, topo_name):
else:
vm_topo_config['disabled_host_interfaces'] = []

if 'DUT' in topo_definition['topology']:
vm_topo_config['DUT'] = topo_definition['topology']['DUT']
else:
vm_topo_config['DUT'] = {}

self.vm_topo_config = vm_topo_config
return vm_topo_config

Expand Down
18 changes: 11 additions & 7 deletions ansible/templates/minigraph_dpg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@
</PortChannelInterfaces>
<VlanInterfaces>
{% if 'tor' in vm_topo_config['dut_type'] | lower %}
{% set vlan_intf_str=';'.join(vlan_intfs) %}
{% for vlan, vlan_param in vlan_configs.items() %}
<VlanInterface>
<Name>Vlan1000</Name>
<Name>{{ vlan }}</Name>
{% set vlan_intf_str=';'.join(vlan_param['intfs']) %}
<AttachTo>{{ vlan_intf_str }}</AttachTo>
<NoDhcpRelay>False</NoDhcpRelay>
<StaticDHCPRelay>0.0.0.0/0</StaticDHCPRelay>
<Type i:nil="true"/>
{% set dhcp_servers_str=';'.join(dhcp_servers) %}
<DhcpRelays>{{ dhcp_servers_str }}</DhcpRelays>
<VlanID>1000</VlanID>
<Tag>1000</Tag>
<Subnets>192.168.0.0/21</Subnets>
<VlanID>{{ vlan_param['id'] }}</VlanID>
<Tag>{{ vlan_param['tag'] }}</Tag>
<Subnets>{{ vlan_param['prefix'] | ipaddr('network') }}/{{ vlan_param['prefix'] | ipaddr('prefix') }}</Subnets>
</VlanInterface>
{% endfor %}
{% endif %}
</VlanInterfaces>
<IPInterfaces>
Expand All @@ -93,11 +95,13 @@
</IPInterface>
{% endfor %}
{% if 'tor' in vm_topo_config['dut_type'] | lower %}
{% for vlan, vlan_param in vlan_configs.items() %}
<IPInterface>
<Name i:nil="true"/>
<AttachTo>Vlan1000</AttachTo>
<Prefix>192.168.0.1/21</Prefix>
<AttachTo>{{ vlan }}</AttachTo>
<Prefix>{{ vlan_param['prefix'] }}</Prefix>
</IPInterface>
{% endfor %}
{% endif %}
</IPInterfaces>
<DataAcls/>
Expand Down
11 changes: 11 additions & 0 deletions ansible/vars/dut_droplet_vlans-1.yml
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
subnets: 192.168.100.0/21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address should be '.1'
<Prefix>192.168.0.1/21</Prefix>

Copy link
Copy Markdown
Contributor Author

@tahmed-dev tahmed-dev Jan 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad. good catch. will fix it. Now, I think subnet name is confusing too!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'd suggest to rename subnets to prefix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it is done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is part of Option A. will take it out

Vlan200:
id: 200
intfs: [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
tag: 200
subnets: 192.168.200.0/21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address should be .1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

20 changes: 20 additions & 0 deletions ansible/vars/topo_t0-116.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ topology:
- 30
- 31
vm_offset: 3
DUT:
vlan_configs:
default_vlan_config: one_vlan_a
one_vlan_a:
Vlan1000:
id: 1000
intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]
prefix: 192.168.0.1/21
tag: 1000
two_vlan_a:
Vlan100:
id: 100
intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
prefix: 192.168.100.1/21
tag: 100
Vlan200:
id: 200
intfs: [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]
prefix: 192.168.200.1/21
tag: 200

configuration_properties:
common:
Expand Down
20 changes: 20 additions & 0 deletions ansible/vars/topo_t0-16.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ topology:
vlans:
- 53
vm_offset: 5
DUT:
vlan_configs:
default_vlan_config: one_vlan_a
one_vlan_a:
Vlan1000:
id: 1000
intfs: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]
prefix: 192.168.0.1/21
tag: 1000
two_vlan_a:
Vlan100:
id: 100
intfs: [32, 33, 34, 35, 36, 37, 38, 39]
prefix: 192.168.100.1/21
tag: 100
Vlan200:
id: 200
intfs: [40, 41, 42, 43, 44, 45, 46, 47]
prefix: 192.168.200.1/21
tag: 200

configuration_properties:
common:
Expand Down
20 changes: 20 additions & 0 deletions ansible/vars/topo_t0-52.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ topology:
vlans:
- 51
vm_offset: 3
DUT:
vlan_configs:
default_vlan_config: one_vlan_a
one_vlan_a:
Vlan1000:
id: 1000
intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]
prefix: 192.168.0.1/21
tag: 1000
two_vlan_a:
Vlan100:
id: 100
intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
prefix: 192.168.100.1/21
tag: 100
Vlan200:
id: 200
intfs: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]
prefix: 192.168.200.1/21
tag: 200

configuration_properties:
common:
Expand Down
20 changes: 20 additions & 0 deletions ansible/vars/topo_t0-56.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ topology:
vlans:
- 43
vm_offset: 7
DUT:
vlan_configs:
default_vlan_config: one_vlan_a
one_vlan_a:
Vlan1000:
id: 1000
intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55]
prefix: 192.168.0.1/21
tag: 1000
two_vlan_a:
Vlan100:
id: 100
intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
prefix: 192.168.100.1/21
tag: 100
Vlan200:
id: 200
intfs: [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55]
prefix: 192.168.200.1/21
tag: 200

configuration_properties:
common:
Expand Down
21 changes: 20 additions & 1 deletion ansible/vars/topo_t0-64-32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ topology:
- 20
- 21
vm_offset: 3
DUT:
vlan_configs:
default_vlan_config: one_vlan_a
one_vlan_a:
Vlan1000:
id: 1000
intfs: [2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
prefix: 192.168.0.1/21
tag: 1000
two_vlan_a:
Vlan100:
id: 100
intfs: [2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
prefix: 192.168.100.1/21
tag: 100
Vlan200:
id: 200
intfs: [18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
prefix: 192.168.200.1/21
tag: 200

configuration_properties:
common:
Expand Down Expand Up @@ -159,4 +179,3 @@ configuration:
bp_interface:
ipv4: 10.10.246.4/24
ipv6: fc0a::4/64

20 changes: 20 additions & 0 deletions ansible/vars/topo_t0-64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ topology:
- 20
- 21
vm_offset: 3
DUT:
vlan_configs:
default_vlan_config: one_vlan_a
one_vlan_a:
Vlan1000:
id: 1000
intfs: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 36, 37, 38, 39, 40, 41, 42, 48, 52, 53, 54, 55, 56, 57, 58]
prefix: 192.168.0.1/21
tag: 1000
two_vlan_a:
Vlan100:
id: 100
intfs: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 22, 23, 24, 25, 26, 27, 28, 29]
prefix: 192.168.100.1/21
tag: 100
Vlan200:
id: 200
intfs: [30, 31, 32, 36, 37, 38, 39, 40, 41, 42, 48, 52, 53, 54, 55, 56, 57, 58]
prefix: 192.168.200.1/21
tag: 200

configuration_properties:
common:
Expand Down
20 changes: 20 additions & 0 deletions ansible/vars/topo_t0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ topology:
vlans:
- 31
vm_offset: 3
DUT:
vlan_configs:
default_vlan_config: one_vlan_a
one_vlan_a:
Vlan1000:
id: 1000
intfs: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
prefix: 192.168.0.1/21
tag: 1000
two_vlan_a:
Vlan100:
id: 100
intfs: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
prefix: 192.168.100.1/21
tag: 100
Vlan200:
id: 200
intfs: [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
prefix: 192.168.200.1/21
tag: 200

configuration_properties:
common:
Expand Down