Conversation
…ven-devops/nso-oc-services into oc_to_xe_qos_class_map
| raise ValueError( | ||
| f'Interface type {interface_type} not supported by this NSO_OC_Services implementation. Please file an issue at https://github.com/model-driven-devops/nso-oc-services') | ||
|
|
||
| def modify_dscp(dscp): |
There was a problem hiding this comment.
Instead of a long winded if-else statement, just create a globally scoped object. We can then map by key-value pairs, where keys are dscp and values are those currently in new_dscp. You can still account for your if, but your else if and else can be converted to use the object.
| """ | ||
| Configure forwarding-groups | ||
| """ | ||
| if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) > 0: |
There was a problem hiding this comment.
This if statement isn't required. The loop will run if there are more than 0 elements.
SIDE NOTE: I am not aware if nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group is guaranteed to always return something (i.e. it's defined). If so, then ignore this side note. This note refers to everything under nso_props.service.oc_qos__qos.
There was a problem hiding this comment.
Changing block to:
for fg in nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group:
device_cdb.ios__policy_map.create(fg.name)
if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) == 0:
if device_cdb.ios__policy_map:
device_cdb.ios__policy_map.delete()
| if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) > 0: | ||
| for fg in nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group: | ||
| device_cdb.ios__policy_map.create(fg.name) | ||
| elif len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) == 0: |
There was a problem hiding this comment.
Change to an if statement, since we're getting rid of the if statement above. It will only run if forwarding_group is empty.
There was a problem hiding this comment.
See the reply from the previous conversation.
| """ | ||
| Configure schedulers | ||
| """ | ||
| if len(nso_props.service.oc_qos__qos.scheduler_policies.scheduler_policy) > 0: |
There was a problem hiding this comment.
This if statement isn't required. The loop will run if there are more than 0 elements.
There was a problem hiding this comment.
'if' statement removed.
| """ | ||
| Configure classifiers | ||
| """ | ||
| if len(nso_props.service.oc_qos__qos.classifiers.classifier) > 0: |
There was a problem hiding this comment.
This if statement isn't required. The loop will run if there are more than 0 elements.
There was a problem hiding this comment.
'if' statement removed.
| device_cdb.ios__class_map[c_map.name].prematch = 'match-all' | ||
| device_cdb.ios__class_map[c_map.name].match.dscp.create( | ||
| new_dscp) | ||
| elif len(nso_props.service.oc_qos__qos.classifiers.classifier) == 0: |
There was a problem hiding this comment.
Change to an if statement, since we're getting rid of the if statement above.
There was a problem hiding this comment.
Updated 'elif' to 'if'.
| """ | ||
| if len(nso_props.service.oc_qos__qos.scheduler_policies.scheduler_policy) > 0: | ||
| for sched_pol in nso_props.service.oc_qos__qos.scheduler_policies.scheduler_policy: | ||
| if len(sched_pol.schedulers.scheduler) > 0: |
There was a problem hiding this comment.
This if statement isn't required. The loop will run if there are more than 0 elements.
There was a problem hiding this comment.
'if' statement removed.
| for sequence in sched_pol.schedulers.scheduler: | ||
| # Configure policy-map | ||
| p_map = device_cdb.ios__policy_map.create(sequence.output.config.output_fwd_group) | ||
| if pmap_cmap: |
There was a problem hiding this comment.
Combine this to a single line, to prevent unnecessary tabbing
| if pmap_cmap: | |
| if pmap_cmap and p_map.name in pmap_cmap.keys(): |
There was a problem hiding this comment.
'if' statement combined.
| """ | ||
| Configure interfaces | ||
| """ | ||
| if len(nso_props.service.oc_qos__qos.interfaces.interface) > 0: |
There was a problem hiding this comment.
This if statement isn't required. The loop will run if there are more than 0 elements.
There was a problem hiding this comment.
'if' statement removed.
| if sequence.one_rate_two_color: | ||
| # Configure cir percentage | ||
| if sequence.one_rate_two_color.config.cir_pct: | ||
| device_cdb.ios__policy_map[p_map].ios__class[c_map].police_cir_percent.police.cir.percent.percentage = sequence.one_rate_two_color.config.cir_pct |
There was a problem hiding this comment.
The code can be cleaned up to make it less verbose. We can greatly remove a lot of repeated text such as device_cdb.ios__policy_map[p_map].ios__class[c_map].police_cir_percent.police.cir.percent by storing them in variables and referencing those variables instead of the long text. device_cdb.ios__policy_map[p_map].ios__class[c_map].police_cir_percent.police.cir.percent is just an example and there are a few others.
0666e8b to
a34d8de
Compare
| def modify_dscp(dscp): | ||
| if (dscp % 2) != 0: | ||
| return dscp | ||
| if dscp in dscp_dict.keys(): |
There was a problem hiding this comment.
This if statement isn't required. The get function will perform a check if that key exist, otherwise that second arg ('default') value is returned.
| if dscp in dscp_dict.keys(): | |
| return dscp_dict.get(dscp, 'default') |
There was a problem hiding this comment.
If statement removed.
| if len(nso_props.service.oc_qos__qos.classifiers.classifier) == 0: | ||
| if device_cdb.ios__class_map: |
There was a problem hiding this comment.
Minor, but you can just combine these two if statements since you're checking both for truthy.
| if len(nso_props.service.oc_qos__qos.classifiers.classifier) == 0: | |
| if device_cdb.ios__class_map: | |
| if (len(nso_props.service.oc_qos__qos.classifiers.classifier) == 0 | |
| and device_cdb.ios__class_map): |
| if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) == 0: | ||
| if device_cdb.ios__policy_map: |
There was a problem hiding this comment.
Minor, but you can just combine these two if statements since you're checking both for truthy.
| if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) == 0: | |
| if device_cdb.ios__policy_map: | |
| if (len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) == 0 | |
| and device_cdb.ios__policy_map): |
fec7a74 to
40cda2d
Compare
c3140df to
84181b3
Compare
84181b3 to
2e25df8
Compare
feat: OC to IOS-XE QoS