|
| 1 | +import sys |
| 2 | + |
| 3 | +from ipaddress import ip_interface |
1 | 4 | from natsort import natsorted
|
2 | 5 |
|
| 6 | +#TODO: Remove once Python 2 support is removed |
| 7 | +if sys.version_info.major == 3: |
| 8 | + UNICODE_TYPE = str |
| 9 | +else: |
| 10 | + UNICODE_TYPE = unicode |
| 11 | + |
3 | 12 | def generate_t1_sample_config(data):
|
4 | 13 | data['DEVICE_METADATA']['localhost']['hostname'] = 'sonic'
|
5 | 14 | data['DEVICE_METADATA']['localhost']['type'] = 'LeafRouter'
|
@@ -39,11 +48,48 @@ def generate_empty_config(data):
|
39 | 48 | return new_data
|
40 | 49 |
|
41 | 50 | def generate_l2_config(data):
|
| 51 | + if 'is_dualtor' in data and data['is_dualtor']: |
| 52 | + is_dualtor = True |
| 53 | + data.pop('is_dualtor') |
| 54 | + else: |
| 55 | + is_dualtor = False |
42 | 56 | data['VLAN'] = {'Vlan1000': {'vlanid': '1000'}}
|
43 | 57 | data['VLAN_MEMBER'] = {}
|
44 |
| - for port in natsorted(data['PORT']): |
| 58 | + if is_dualtor: |
| 59 | + data['DEVICE_METADATA']['localhost']['subtype'] = 'DualToR' |
| 60 | + data['LOOPBACK_INTERFACE'] = { |
| 61 | + 'Loopback2': {}, |
| 62 | + 'Loopback2|3.3.3.3': {} |
| 63 | + } |
| 64 | + data['MUX_CABLE'] = {} |
| 65 | + data['PEER_SWITCH'] = { |
| 66 | + "peer_switch_hostname": { |
| 67 | + "address_ipv4": "1.1.1.1" |
| 68 | + } |
| 69 | + } |
| 70 | + data['TUNNEL'] = { |
| 71 | + "MuxTunnel0": { |
| 72 | + "dscp_mode": "uniform", |
| 73 | + "dst_ip": "2.2.2.2", |
| 74 | + "ecn_mode": "copy_from_outer", |
| 75 | + "encap_ecn_mode": "standard", |
| 76 | + "ttl_mode": "pipe", |
| 77 | + "tunnel_type": "IPINIP" |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + server_ipv4_base = ip_interface(UNICODE_TYPE('192.168.0.1/32')) |
| 82 | + server_ipv6_base = ip_interface(UNICODE_TYPE('fc02:1000::1/128')) |
| 83 | + for i, port in enumerate(natsorted(data['PORT'])): |
45 | 84 | data['PORT'][port].setdefault('admin_status', 'up')
|
46 | 85 | data['VLAN_MEMBER']['Vlan1000|{}'.format(port)] = {'tagging_mode': 'untagged'}
|
| 86 | + if is_dualtor: |
| 87 | + mux_cable_entry = { |
| 88 | + 'server_ipv4': str(server_ipv4_base + i), |
| 89 | + 'server_ipv6': str(server_ipv6_base + i), |
| 90 | + 'state': 'auto' |
| 91 | + } |
| 92 | + data['MUX_CABLE'][port] = mux_cable_entry |
47 | 93 | return data
|
48 | 94 |
|
49 | 95 | _sample_generators = {
|
|
0 commit comments