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

feat: OC to IOS-XE QoS #246

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

feat: OC to IOS-XE QoS #246

wants to merge 9 commits into from

Conversation

jrouliez
Copy link
Contributor

@jrouliez jrouliez commented Jul 3, 2023

feat: OC to IOS-XE QoS

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updates made.

"""
Configure forwarding-groups
"""
if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

@jrouliez jrouliez Jul 7, 2023

Choose a reason for hiding this comment

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

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to an if statement, since we're getting rid of the if statement above. It will only run if forwarding_group is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the reply from the previous conversation.

"""
Configure schedulers
"""
if len(nso_props.service.oc_qos__qos.scheduler_policies.scheduler_policy) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

This if statement isn't required. The loop will run if there are more than 0 elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'if' statement removed.

"""
Configure classifiers
"""
if len(nso_props.service.oc_qos__qos.classifiers.classifier) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

This if statement isn't required. The loop will run if there are more than 0 elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Change to an if statement, since we're getting rid of the if statement above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

This if statement isn't required. The loop will run if there are more than 0 elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine this to a single line, to prevent unnecessary tabbing

Suggested change
if pmap_cmap:
if pmap_cmap and p_map.name in pmap_cmap.keys():

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'if' statement combined.

"""
Configure interfaces
"""
if len(nso_props.service.oc_qos__qos.interfaces.interface) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

This if statement isn't required. The loop will run if there are more than 0 elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'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
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updates made.

def modify_dscp(dscp):
if (dscp % 2) != 0:
return dscp
if dscp in dscp_dict.keys():
Copy link
Contributor

@m0lass3s m0lass3s Jul 12, 2023

Choose a reason for hiding this comment

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

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.

Suggested change
if dscp in dscp_dict.keys():
return dscp_dict.get(dscp, 'default')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If statement removed.

Comment on lines 66 to 67
if len(nso_props.service.oc_qos__qos.classifiers.classifier) == 0:
if device_cdb.ios__class_map:
Copy link
Contributor

@m0lass3s m0lass3s Jul 12, 2023

Choose a reason for hiding this comment

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

Minor, but you can just combine these two if statements since you're checking both for truthy.

Suggested change
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):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Comment on lines 22 to 23
if len(nso_props.service.oc_qos__qos.forwarding_groups.forwarding_group) == 0:
if device_cdb.ios__policy_map:
Copy link
Contributor

@m0lass3s m0lass3s Jul 12, 2023

Choose a reason for hiding this comment

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

Minor, but you can just combine these two if statements since you're checking both for truthy.

Suggested change
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):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

stmosher-dev
stmosher-dev previously approved these changes Jul 13, 2023
Copy link
Collaborator

@stmosher-dev stmosher-dev left a comment

Choose a reason for hiding this comment

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

run tests

@jrouliez jrouliez force-pushed the oc_to_xe_qos_class_map branch 2 times, most recently from c3140df to 84181b3 Compare July 14, 2023 04:41
stmosher-dev
stmosher-dev previously approved these changes Jul 14, 2023
Copy link
Collaborator

@stmosher-dev stmosher-dev left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants