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

OC Compliance Changes #53

Merged
merged 21 commits into from
Nov 23, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(self, **kwargs):
pass

argument_spec = {'config': {'elements': 'dict',
'options': {'members': {'elements': 'str',
'options': {'permit': {'required': False, 'type': 'bool'},
'members': {'elements': 'str',
'required': False,
'type': 'list'},
'name': {'required': True, 'type': 'str'}},
Expand Down
6 changes: 3 additions & 3 deletions plugins/module_utils/network/sonic/config/aaa/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def build_create_aaa_payload(self, commands):
auth_method = commands["authentication"]["data"]["group"]
payload['openconfig-system:aaa']['authentication']['config']['authentication-method'].append(auth_method)
if "fail_through" in commands["authentication"]["data"]:
cfg = {'openconfig-system-ext:failthrough': str(commands["authentication"]["data"]["fail_through"])}
cfg = {'failthrough': str(commands["authentication"]["data"]["fail_through"])}
payload['openconfig-system:aaa']['authentication']['config'].update(cfg)
return payload

Expand All @@ -215,7 +215,7 @@ def remove_default_entries(self, data):
def get_delete_all_aaa_request(self, have):
requests = []
if "authentication" in have and have["authentication"]:
if "local" or "group" in have["authentication"]["data"]:
if "local" in have["authentication"]["data"] or "group" in have["authentication"]["data"]:
request = self.get_authentication_method_delete_request()
requests.append(request)
if "fail_through" in have["authentication"]["data"]:
Expand All @@ -230,7 +230,7 @@ def get_authentication_method_delete_request(self):
return request

def get_failthrough_delete_request(self):
path = 'data/openconfig-system:system/aaa/authentication/config/openconfig-system-ext:failthrough'
path = 'data/openconfig-system:system/aaa/authentication/config/failthrough'
method = DELETE
request = {'path': path, 'method': method}
return request
44 changes: 22 additions & 22 deletions plugins/module_utils/network/sonic/config/bgp/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class Bgp(ConfigBase):

network_instance_path = '/data/openconfig-network-instance:network-instances/network-instance'
protocol_bgp_path = 'protocols/protocol=BGP,bgp/bgp'
log_neighbor_changes_path = 'openconfig-bgp-ext:logging-options/config/log-neighbor-state-changes'
holdtime_path = 'config/openconfig-bgp-ext:hold-time'
keepalive_path = 'config/openconfig-bgp-ext:keepalive-interval'
log_neighbor_changes_path = 'logging-options/config/log-neighbor-state-changes'
holdtime_path = 'config/hold-time'
keepalive_path = 'config/keepalive-interval'

def __init__(self, module):
super(Bgp, self).__init__(module)
Expand Down Expand Up @@ -208,8 +208,8 @@ def get_delete_max_med_requests(self, vrf_name, max_med, match):

match_max_med_on_startup = match.get('max_med', {}).get('on_startup')
if match_max_med_on_startup:
requests.append({'path': generic_del_path + "openconfig-bgp-ext:max-med/config/time", 'method': DELETE})
requests.append({'path': generic_del_path + "openconfig-bgp-ext:max-med/config/max-med-val", 'method': DELETE})
requests.append({'path': generic_del_path + "max-med/config/time", 'method': DELETE})
requests.append({'path': generic_del_path + "max-med/config/max-med-val", 'method': DELETE})

return requests

Expand All @@ -236,25 +236,25 @@ def get_delete_bestpath_requests(self, vrf_name, bestpath, match):
as_path = bestpath.get('as_path', None)
if as_path and match_as_path:
if as_path.get('confed', None) is not None and match_as_path.get('confed', None):
requests.append({'path': route_selection_del_path + "openconfig-bgp-ext:compare-confed-as-path", 'method': DELETE})
requests.append({'path': route_selection_del_path + "compare-confed-as-path", 'method': DELETE})
if as_path.get('ignore', None) is not None and match_as_path.get('ignore', None):
requests.append({'path': route_selection_del_path + "ignore-as-path-length", 'method': DELETE})
if as_path.get('multipath_relax', None) is not None and match_as_path.get('multipath_relax', None):
requests.append({'path': multi_paths_del_path + "allow-multiple-as", 'method': DELETE})
if as_path.get('multipath_relax_as_set', None) is not None and match_as_path.get('multipath_relax_as_set', None):
requests.append({'path': multi_paths_del_path + "openconfig-bgp-ext:as-set", 'method': DELETE})
requests.append({'path': multi_paths_del_path + "as-set", 'method': DELETE})

match_med = match_bestpath.get('med', None)
med = bestpath.get('med', None)
if med and match_med:
if med.get('confed', None) is not None and match_med.get('confed', None):
requests.append({'path': route_selection_del_path + "openconfig-bgp-ext:med-confed", 'method': DELETE})
requests.append({'path': route_selection_del_path + "med-confed", 'method': DELETE})
if med.get('missing_as_worst', None) is not None and match_med.get('missing_as_worst', None):
requests.append({'path': route_selection_del_path + "openconfig-bgp-ext:med-missing-as-worst", 'method': DELETE})
requests.append({'path': route_selection_del_path + "med-missing-as-worst", 'method': DELETE})
if med.get('always_compare_med', None) is not None and match_med.get('always_compare_med', None):
requests.append({'path': route_selection_del_path + "always-compare-med", 'method': DELETE})
if med.get('max_med_val', None) is not None and match_med.get('max_med_val', None):
requests.append({'path': generic_del_path + "openconfig-bgp-ext:max-med/config/admin-max-med-val", 'method': DELETE})
requests.append({'path': generic_del_path + "max-med/config/admin-max-med-val", 'method': DELETE})

return requests

Expand Down Expand Up @@ -283,11 +283,11 @@ def get_delete_specific_bgp_param_request(self, command, match):
requests.append({"path": url, "method": DELETE})

if holdtime and match['timers'].get('holdtime', None) != 180:
url = '%s=%s/%s/global/config/openconfig-bgp-ext:hold-time' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url = '%s=%s/%s/global/config/hold-time' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
requests.append({"path": url, "method": DELETE})

if keepalive and match['timers'].get('keepalive_interval', None) != 60:
url = '%s=%s/%s/global/config/openconfig-bgp-ext:keepalive-interval' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url = '%s=%s/%s/global/config/keepalive-interval' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
requests.append({"path": url, "method": DELETE})

# Delete the log_neighbor_changes only when existing values is True.
Expand Down Expand Up @@ -355,7 +355,7 @@ def get_modify_multi_paths_req(self, vrf_name, as_path):
if as_path_multipath_relax is not None:
multipath_cfg['allow-multiple-as'] = as_path_multipath_relax
if as_path_multipath_relax_as_set is not None:
multipath_cfg['openconfig-bgp-ext:as-set'] = as_path_multipath_relax_as_set
multipath_cfg['as-set'] = as_path_multipath_relax_as_set

payload = {"openconfig-network-instance:config": multipath_cfg}
if payload:
Expand Down Expand Up @@ -385,7 +385,7 @@ def get_modify_route_selection_req(self, vrf_name, compare_routerid, as_path, me
as_path_confed = as_path.get('confed', None)
as_path_ignore = as_path.get('ignore', None)
if as_path_confed is not None:
route_selection_cfg['openconfig-bgp-ext:compare-confed-as-path'] = as_path_confed
route_selection_cfg['compare-confed-as-path'] = as_path_confed
if as_path_ignore is not None:
route_selection_cfg['ignore-as-path-length'] = as_path_ignore

Expand All @@ -394,9 +394,9 @@ def get_modify_route_selection_req(self, vrf_name, compare_routerid, as_path, me
med_missing_as_worst = med.get('missing_as_worst', None)
always_compare_med = med.get('always_compare_med', None)
if med_confed is not None:
route_selection_cfg['openconfig-bgp-ext:med-confed'] = med_confed
route_selection_cfg['med-confed'] = med_confed
if med_missing_as_worst is not None:
route_selection_cfg['openconfig-bgp-ext:med-missing-as-worst'] = med_missing_as_worst
route_selection_cfg['med-missing-as-worst'] = med_missing_as_worst
if always_compare_med is not None:
route_selection_cfg['always-compare-med'] = always_compare_med
method = PATCH
Expand Down Expand Up @@ -437,7 +437,7 @@ def get_modify_max_med_requests(self, vrf_name, max_med):

if on_startup_med is not None:
payload = {
'openconfig-bgp-ext:max-med': {
'max-med': {
'config': {
'max-med-val': on_startup_med,
'time': on_startup_time
Expand All @@ -446,7 +446,7 @@ def get_modify_max_med_requests(self, vrf_name, max_med):
}

if payload:
url = '%s=%s/%s/global/openconfig-bgp-ext:max-med' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url = '%s=%s/%s/global/max-med' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
request = {"path": url, "method": method, "data": payload}

return [request]
Expand All @@ -457,7 +457,7 @@ def get_modify_log_change_request(self, vrf_name, log_neighbor_changes):
payload = {}

if log_neighbor_changes is not None:
payload['openconfig-bgp-ext:log-neighbor-state-changes'] = log_neighbor_changes
payload['log-neighbor-state-changes'] = log_neighbor_changes

if payload:
url = '%s=%s/%s/global/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path, self.log_neighbor_changes_path)
Expand All @@ -471,7 +471,7 @@ def get_modify_holdtime_request(self, vrf_name, holdtime):
payload = {}

if holdtime is not None:
payload['openconfig-bgp-ext:hold-time'] = str(holdtime)
payload['hold-time'] = str(holdtime)

if payload:
url = '%s=%s/%s/global/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path, self.holdtime_path)
Expand All @@ -485,7 +485,7 @@ def get_modify_keepalive_request(self, vrf_name, keepalive_interval):
payload = {}

if keepalive_interval is not None:
payload['openconfig-bgp-ext:keepalive-interval'] = str(keepalive_interval)
payload['keepalive-interval'] = str(keepalive_interval)

if payload:
url = '%s=%s/%s/global/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path, self.keepalive_path)
Expand Down Expand Up @@ -564,7 +564,7 @@ def get_modify_bgp_requests(self, commands, have):
if 'keepalive_interval' in conf['timers']:
keepalive_interval = conf['timers']['keepalive_interval']

if not any([cfg for cfg in have if cfg['vrf_name'] == vrf_name and (cfg['bgp_as'] == as_val)]):
if not any(cfg for cfg in have if cfg['vrf_name'] == vrf_name and (cfg['bgp_as'] == as_val)):
new_bgp_req = self.get_new_bgp_request(vrf_name, as_val)
if new_bgp_req:
requests.append(new_bgp_req)
Expand Down
16 changes: 8 additions & 8 deletions plugins/module_utils/network/sonic/config/bgp_af/bgp_af.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def get_modify_redistribute_requests(self, vrf_name, conf_afi, conf_safi, conf_r
cfg_data['src-protocol'] = "openconfig-policy-types:%s" % (conf_protocol)
cfg_data['config'] = {'address-family': afi_cfg}
if conf_metric is not None:
cfg_data['config']['openconfig-network-instance-ext:metric'] = conf_metric
cfg_data['config']['metric'] = conf_metric

conf_route_map = conf_redis.get('route_map', None)
if conf_route_map:
Expand Down Expand Up @@ -292,14 +292,14 @@ def get_modify_network_request(self, vrf_name, conf_afi, conf_safi, conf_network
request = None
afi_safi = ("%s_%s" % (conf_afi, conf_safi)).upper()
url = '%s=%s/%s/' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url += '%s=%s/openconfig-bgp-ext:network-config' % (self.afi_safi_path, afi_safi)
url += '%s=%s/network-config' % (self.afi_safi_path, afi_safi)
network_payload = []
for each in conf_network:
payload = {}
payload = {'config': {'prefix': each}, 'prefix': each}
network_payload.append(payload)
if network_payload:
new_payload = {'openconfig-bgp-ext:network-config': {'network': network_payload}}
new_payload = {'network-config': {'network': network_payload}}

request = {"path": url, "method": PATCH, "data": new_payload}
return request
Expand All @@ -308,8 +308,8 @@ def get_modify_dampening_request(self, vrf_name, conf_afi, conf_safi, conf_dampe
request = None
afi_safi = ("%s_%s" % (conf_afi, conf_safi)).upper()
url = '%s=%s/%s/' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url += '%s=%s/openconfig-bgp-ext:route-flap-damping' % (self.afi_safi_path, afi_safi)
damp_payload = {'openconfig-bgp-ext:route-flap-damping': {'config': {'enabled': conf_dampening}}}
url += '%s=%s/route-flap-damping' % (self.afi_safi_path, afi_safi)
damp_payload = {'route-flap-damping': {'config': {'enabled': conf_dampening}}}
if damp_payload:
request = {"path": url, "method": PATCH, "data": damp_payload}
return request
Expand Down Expand Up @@ -499,7 +499,7 @@ def get_delete_advertise_default_gw_request(self, vrf_name, conf_afi, conf_safi)
def get_delete_dampening_request(self, vrf_name, conf_afi, conf_safi):
afi_safi = ("%s_%s" % (conf_afi, conf_safi)).upper()
url = '%s=%s/%s' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url += '/%s=%s/openconfig-bgp-ext:route-flap-damping/config/enabled' % (self.afi_safi_path, afi_safi)
url += '/%s=%s/route-flap-damping/config/enabled' % (self.afi_safi_path, afi_safi)

return({"path": url, "method": DELETE})

Expand Down Expand Up @@ -629,7 +629,7 @@ def get_delete_network_request(self, vrf_name, conf_afi, conf_safi, conf_network
requests = []
afi_safi = ("%s_%s" % (conf_afi, conf_safi)).upper()
url = '%s=%s/%s/' % (self.network_instance_path, vrf_name, self.protocol_bgp_path)
url += '%s=%s/openconfig-bgp-ext:network-config/network=' % (self.afi_safi_path, afi_safi)
url += '%s=%s/network-config/network=' % (self.afi_safi_path, afi_safi)
mat_list = []
for conf in conf_network:
if mat_network:
Expand Down Expand Up @@ -726,7 +726,7 @@ def get_delete_redistribute_requests(self, vrf_name, conf_afi, conf_safi, conf_r
continue

if new_metric_flag and ext_metric_flag:
url += '%s,%s,%s/config/openconfig-network-instance-ext:metric' % (src_protocol, dst_protocol, addr_family)
url += '%s,%s,%s/config/metric' % (src_protocol, dst_protocol, addr_family)
requests.append({'path': url, 'method': DELETE})

if new_route_flag and ext_route_flag:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,16 @@ def _state_deleted(self, want, have, diff):
def get_new_add_request(self, conf):
request = None
members = conf.get('members', None)
permit = conf.get('permit', None)
permit_str = ""
if permit:
permit_str = "PERMIT"
else:
permit_str = "DENY"
if members:
url = "data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/as-path-sets"
method = "PATCH"
cfg = {'as-path-set-name': conf['name'], 'as-path-set-member': members}
cfg = {'as-path-set-name': conf['name'], 'as-path-set-member': members, 'openconfig-bgp-policy-ext:action': permit_str}
as_path_set = {'as-path-set-name': conf['name'], 'config': cfg}
payload = {'openconfig-bgp-policy:as-path-sets': {'as-path-set': [as_path_set]}}
request = {"path": url, "method": method, "data": payload}
Expand Down Expand Up @@ -248,6 +254,13 @@ def get_delete_single_as_path_requests(self, name):
request = {"path": url.format(name), "method": method}
return request

def get_delete_single_as_path_action_requests(self, name):
url = "data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/as-path-sets/as-path-set={}"
url = url + "/openconfig-bgp-policy-ext:action"
method = "DELETE"
request = {"path": url.format(name), "method": method}
return request

def get_delete_as_path_requests(self, commands, have, is_delete_all):
requests = []
if is_delete_all:
Expand All @@ -256,6 +269,7 @@ def get_delete_as_path_requests(self, commands, have, is_delete_all):
for cmd in commands:
name = cmd['name']
members = cmd['members']
permit = cmd['permit']
if members:
diff_members = []
for item in have:
Expand All @@ -266,6 +280,11 @@ def get_delete_as_path_requests(self, commands, have, is_delete_all):
diff_members.append(member_want)
if diff_members:
requests.append(self.get_delete_single_as_path_member_requests(name, diff_members))

elif permit:
for item in have:
if item['name'] == name:
requests.append(self.get_delete_single_as_path_action_requests(name))
else:
for item in have:
if item['name'] == name:
Expand Down
Loading