Skip to content
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

Add new attributes to MCLAG resource model #145

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions plugins/module_utils/network/sonic/argspec/mclag/mclag.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(self, **kwargs):
'config': {
'options': {
'domain_id': {'required': True, 'type': 'int'},
'gateway_mac': {'type': 'str'},
'delay_restore': {'type': 'int'},
'keepalive': {'type': 'int'},
'peer_address': {'type': 'str'},
'peer_link': {'type': 'str'},
Expand All @@ -56,6 +58,18 @@ def __init__(self, **kwargs):
},
'type': 'dict'
},
'peer_gateway': {
'options': {
'vlans': {
'elements': 'dict',
'options': {
'vlan': {'type': 'str'}
},
'type': 'list'
}
},
'type': 'dict'
},
'session_timeout': {'type': 'int'},
'source_address': {'type': 'str'},
'system_mac': {'type': 'str'},
Expand Down
62 changes: 60 additions & 2 deletions plugins/module_utils/network/sonic/config/mclag/mclag.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def set_config(self, existing_mclag_facts):
vlans_list = unique_ip['vlans']
if vlans_list:
normalize_interface_name(vlans_list, self._module, 'vlan')
peer_gateway = want.get('peer_gateway', None)
if peer_gateway:
vlans_list = peer_gateway['vlans']
if vlans_list:
normalize_interface_name(vlans_list, self._module, 'vlan')
members = want.get('members', None)
if members:
portchannels_list = members['portchannels']
Expand Down Expand Up @@ -175,7 +180,7 @@ def _state_deleted(self, want, have):
requests = []
if not want:
if have:
requests = self.get_delete_all_mclag_domain_request()
requests = self.get_delete_all_mclag_domain_request(have)
if len(requests) > 0:
commands = update_states(have, "deleted")
else:
Expand All @@ -196,6 +201,7 @@ def remove_default_entries(self, data):
default_val_dict = {
'keepalive': 1,
'session_timeout': 30,
'delay_restore': 300
}
for key, val in data.items():
if not (val is None or (key in default_val_dict and val == default_val_dict[key])):
Expand Down Expand Up @@ -231,6 +237,20 @@ def get_delete_mclag_attribute_request(self, want, command):
url = url_common + '/mclag-system-mac'
request = {'path': url, 'method': method}
requests.append(request)
if 'delay_restore' in command and command['delay_restore'] is not None:
url = url_common + '/delay-restore'
request = {'path': url, 'method': method}
requests.append(request)
if 'peer_gateway' in command and command['peer_gateway'] is not None:
if command['peer_gateway']['vlans'] is None:
request = {'path': 'data/openconfig-mclag:mclag/vlan-ifs/vlan-if', 'method': method}
requests.append(request)
elif command['peer_gateway']['vlans'] is not None:
for each in command['peer_gateway']['vlans']:
if each:
peer_gateway_url = 'data/openconfig-mclag:mclag/vlan-ifs/vlan-if=%s' % (each['vlan'])
request = {'path': peer_gateway_url, 'method': method}
requests.append(request)
if 'unique_ip' in command and command['unique_ip'] is not None:
if command['unique_ip']['vlans'] is None:
request = {'path': 'data/openconfig-mclag:mclag/vlan-interfaces/vlan-interface', 'method': method}
Expand All @@ -251,14 +271,26 @@ def get_delete_mclag_attribute_request(self, want, command):
portchannel_url = 'data/openconfig-mclag:mclag/interfaces/interface=%s' % (each['lag'])
request = {'path': portchannel_url, 'method': method}
requests.append(request)
if 'gateway_mac' in command and command['gateway_mac'] is not None:
request = {'path': 'data/openconfig-mclag:mclag/mclag-gateway-macs/mclag-gateway-mac', 'method': method}
requests.append(request)
return requests

def get_delete_all_mclag_domain_request(self):
def get_delete_all_mclag_domain_request(self, have):
requests = []
path = 'data/openconfig-mclag:mclag/mclag-domains'
method = DELETE
request = {'path': path, 'method': method}
requests.append(request)
if have.get('peer_gateway'):
request = {'path': 'data/openconfig-mclag:mclag/vlan-ifs/vlan-if', 'method': method}
requests.append(request)
if have.get('unique_ip'):
request = {'path': 'data/openconfig-mclag:mclag/vlan-interfaces/vlan-interface', 'method': method}
requests.append(request)
if have.get('gateway_mac'):
request = {'path': 'data/openconfig-mclag:mclag/mclag-gateway-macs/mclag-gateway-mac', 'method': method}
requests.append(request)
return requests

def get_create_mclag_request(self, want, commands):
Expand All @@ -269,13 +301,31 @@ def get_create_mclag_request(self, want, commands):
if payload:
request = {'path': path, 'method': method, 'data': payload}
requests.append(request)
if 'gateway_mac' in commands and commands['gateway_mac'] is not None:
gateway_mac_path = 'data/openconfig-mclag:mclag/mclag-gateway-macs/mclag-gateway-mac'
gateway_mac_method = PATCH
gateway_mac_payload = {
'openconfig-mclag:mclag-gateway-mac': [{
'gateway-mac': commands['gateway_mac'],
'config': {'gateway-mac': commands['gateway_mac']}
}]
}
request = {'path': gateway_mac_path, 'method': gateway_mac_method, 'data': gateway_mac_payload}
requests.append(request)
if 'unique_ip' in commands and commands['unique_ip'] is not None:
if commands['unique_ip']['vlans'] and commands['unique_ip']['vlans'] is not None:
unique_ip_path = 'data/openconfig-mclag:mclag/vlan-interfaces/vlan-interface'
unique_ip_method = PATCH
unique_ip_payload = self.build_create_unique_ip_payload(commands['unique_ip']['vlans'])
request = {'path': unique_ip_path, 'method': unique_ip_method, 'data': unique_ip_payload}
requests.append(request)
if 'peer_gateway' in commands and commands['peer_gateway'] is not None:
if commands['peer_gateway']['vlans'] and commands['peer_gateway']['vlans'] is not None:
peer_gateway_path = 'data/openconfig-mclag:mclag/vlan-ifs/vlan-if'
peer_gateway_method = PATCH
peer_gateway_payload = self.build_create_peer_gateway_payload(commands['peer_gateway']['vlans'])
request = {'path': peer_gateway_path, 'method': peer_gateway_method, 'data': peer_gateway_payload}
requests.append(request)
if 'members' in commands and commands['members'] is not None:
if commands['members']['portchannels'] and commands['members']['portchannels'] is not None:
portchannel_path = 'data/openconfig-mclag:mclag/interfaces/interface'
Expand All @@ -299,6 +349,8 @@ def build_create_payload(self, want, commands):
temp['peer-link'] = str(commands['peer_link'])
if 'system_mac' in commands and commands['system_mac'] is not None:
temp['openconfig-mclag:mclag-system-mac'] = str(commands['system_mac'])
if 'delay_restore' in commands and commands['delay_restore'] is not None:
temp['delay-restore'] = commands['delay_restore']
mclag_dict = {}
if temp:
domain_id = {"domain-id": want["domain_id"]}
Expand All @@ -316,6 +368,12 @@ def build_create_unique_ip_payload(self, commands):
payload['openconfig-mclag:vlan-interface'].append({"name": each['vlan'], "config": {"name": each['vlan'], "unique-ip-enable": "ENABLE"}})
return payload

def build_create_peer_gateway_payload(self, commands):
payload = {"openconfig-mclag:vlan-if": []}
for each in commands:
payload['openconfig-mclag:vlan-if'].append({"name": each['vlan'], "config": {"name": each['vlan'], "peer-gateway-enable": "ENABLE"}})
return payload

def build_create_portchannel_payload(self, want, commands):
payload = {"openconfig-mclag:interface": []}
for each in commands:
Expand Down
15 changes: 15 additions & 0 deletions plugins/module_utils/network/sonic/facts/mclag/mclag.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def parse_sonic_mclag(self, spec, conf):
config['peer_link'] = domain_config['peer-link']
if domain_config.get('mclag-system-mac', None):
config['system_mac'] = domain_config['mclag-system-mac']
if domain_config.get('delay-restore', None):
config['delay_restore'] = domain_config['delay-restore']

if conf.get('vlan-interfaces', None) and conf['vlan-interfaces'].get('vlan-interface', None):
vlans_list = []
Expand All @@ -127,6 +129,14 @@ def parse_sonic_mclag(self, spec, conf):
if vlans_list:
config['unique_ip'] = {'vlans': vlans_list}

if conf.get('vlan-ifs', None) and conf['vlan-ifs'].get('vlan-if', None):
vlans_list = []
vlan_data = conf['vlan-ifs']['vlan-if']
for vlan in vlan_data:
vlans_list.append({'vlan': vlan['name']})
if vlans_list:
config['peer_gateway'] = {'vlans': vlans_list}

if conf.get('interfaces', None) and conf['interfaces'].get('interface', None):
portchannels_list = []
po_data = conf['interfaces']['interface']
Expand All @@ -136,4 +146,9 @@ def parse_sonic_mclag(self, spec, conf):
if portchannels_list:
config['members'] = {'portchannels': portchannels_list}

if conf.get('mclag-gateway-macs', None) and conf['mclag-gateway-macs'].get('mclag-gateway-mac', None):
gw_mac_data = conf['mclag-gateway-macs']['mclag-gateway-mac']
if gw_mac_data[0].get('config', None) and gw_mac_data[0]['config'].get('gateway-mac', None):
config['gateway_mac'] = gw_mac_data[0]['config']['gateway-mac']

return config
Loading