Skip to content

Conversation

@shrsr
Copy link
Collaborator

@shrsr shrsr commented Aug 25, 2025

No description provided.

@shrsr shrsr changed the title Addition of new network resource module for nd_multi_cluster_connectivity Addition of new network resource module for nd_multi_cluster_connectivity (DCNE-458) Aug 25, 2025
Comment on lines +330 to +334
callbacks = {
"update_callback": update_cluster,
"create_callback": create_cluster,
"delete_callback": delete_cluster,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you consider using classes/interfaces instead of callback functions? Some sort of base state manager abstraction.

I think this way we do not have to pass in callback, but we could initialise a state manager object. This object would have its own specific implementations per module of create/update/delete or whatever we want to standardise on the manage object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I had a discussion with @lhercot regarding creating an interface for the CRUD and related per module functions. I would say that would be the next step if we all decide to go this route?

Comment on lines +318 to +321
desired_clusters_map = {}
for cluster_data_input in desired_clusters_from_module_input:
normalized_payload = module_input_to_api_payload(cluster_data_input)
desired_clusters_map[get_cluster_unique_key(normalized_payload)] = normalized_payload
Copy link
Collaborator

Choose a reason for hiding this comment

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

so for my understanding, is this map reflecting the desired state of a unique id ( this case the onboardUrl from spec ) and then you get the existing configuration after and put it in another map with same format? Those two maps are then passed to the manage_state function which decides what to delete / add / update?

what is the purpose of the normalized_payload and why is this not done for existing? are you conforming the input to the existing configuration?

)

nd = NDModule(module)
desired_clusters_from_module_input = nd.params.get("config")
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we assign variables when they are only used once after in code?

desired_clusters_map = {}
for cluster_data_input in desired_clusters_from_module_input:
normalized_payload = module_input_to_api_payload(cluster_data_input)
desired_clusters_map[get_cluster_unique_key(normalized_payload)] = normalized_payload
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need this get_cluster_unique_key(normalized_payload) when you use basically use cluster_data_input.get("cluster_hostname")?

desired_clusters_map = {}
for cluster_data_input in desired_clusters_from_module_input:
normalized_payload = module_input_to_api_payload(cluster_data_input)
desired_clusters_map[get_cluster_unique_key(normalized_payload)] = normalized_payload
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should there be validations in place to avoid duplicate keys and thus overwrites of existing dict entries?

Comment on lines +325 to +328
existing_clusters_map = {}
for cluster_data_raw in existing_clusters_raw:
# normalized_payload = convert_api_response_to_payload_format(cluster_data_raw)
existing_clusters_map[get_cluster_unique_key(cluster_data_raw)] = cluster_data_raw
Copy link
Collaborator

Choose a reason for hiding this comment

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

when dict comprehension is possible should we try to use that technique?

- nm_connect_cluster_merged is changed
- nm_connect_cluster_merged.before["173.36.219.189"] == {}
- nm_connect_cluster_merged.before["173.36.219.190"] == {}
- nm_connect_cluster_merged.after["173.36.219.189"]["spec"]["clusterType"] == "APIC"
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the benefit of this spec container in the output?

return payload


# def convert_api_response_to_payload_format(api_response_cluster_data):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need this? If we do, then can we add additional comments as to why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't need this now but still waiting on answers from the larger group to make api response similar to input

Comment on lines +250 to +269
def create_cluster(nd):
path = "/api/v1/infra/clusters"
response = nd.proposed
if not nd.module.check_mode:
response = nd.request(path, method="POST", data=nd.proposed)
return response


def update_cluster(nd):
path = "/api/v1/infra/clusters"
fabric_name_for_api_path = nd.existing.get("spec", {}).get("name")
response = payload = nd.proposed
payload["spec"]["name"] = fabric_name_for_api_path
if not nd.module.check_mode:
response = nd.request("{0}/{1}".format(path, fabric_name_for_api_path), method="PUT", data=payload)
return response


def delete_cluster(nd):
path = "/api/v1/infra/clusters"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since path is same, can we move this outside?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we go this route, the plan is to create an interface where all this will be taken care of

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