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 support to fetch cluster device information from netbox. #1169

Open
wants to merge 15 commits into
base: devel
Choose a base branch
from

Conversation

joek-office
Copy link

Related Issue

#852

New Behavior

in ansible netbox inventory will exist a new hostvar with name cluster_device if corresponding information is set in netbox.

...

Contrast to Current Behavior

currently the information is missing in the netbox inventory

...

Discussion: Benefits and Drawbacks

Benefit: More Information can be used from netbox inventory
drawback: i see no one.
backwards-compatible: i think yes, but can't test how far in the past it gets.
i need this information to configure high availability and replication tasks in proxmox over api.

...

Changes to the Documentation

no changes needed in my opinion

...

Proposed Release Note Entry

add support to fetch cluster device information for virtual machine resources from netbox.

...

Double Check

  • I have read the comments and followed the CONTRIBUTING.md.
  • I have explained my PR according to the information in the comments or in a linked issue.
  • My PR targets the devel branch.

try:
# cluster device does not have a slug
return host["device"]["name"]
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a more specific exception we could use like KeyError?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could this also use a more common pattern of checking if the key exists before accessing, instead of a try/except block?

Copy link
Author

Choose a reason for hiding this comment

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

I don't know if i have understand it right, but have developed a solution without try/catch and with returning a suitable value in every case.
New version see below

def extract_cluster_device(self, host):
# cluster device does not have a slug
if host.get("device", None) is None:
return ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you certain this is the correct thing to return? This doesn't seem like a good idea to me

# cluster device does not have a slug
if host.get("device", None) is None:
return ""
return host.get("device", {"name": ""}).get("name", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks awful similar to the above return when there is no device key in the dictionary.

Overall I think this needs to be improved

Copy link
Author

Choose a reason for hiding this comment

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

What is your opinion should we return, if there is no value assigned. Should it be null/None?
Also, is there a handy way to determine the object type of the current host. Then i can only return the cluster_device variable, when the object is an virtual machine.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is your opinion should we return, if there is no value assigned. Should it be null/None?

I would follow the pattern set by the other functions in this code. Specifically it appears that most would return (which is short hand for returning None) although some return an empty list where it makes sense to.

…a none type. if value is present return this value.
Copy link
Author

@joek-office joek-office left a comment

Choose a reason for hiding this comment

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

i think now all possible errors (in my mind type error, and keys not present) of the host variable was handled.
Also only if there is a assigned cluster_device value its value is returned otherwise there is always a null value.
also i think the high level pattern of the other extractor functions is used.

please have in mind, that i'm not a programmer, possibly i don't understand your thoughts with my rare python understanding.

Copy link
Contributor

@sc68cal sc68cal left a comment

Choose a reason for hiding this comment

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

Remove the changes to gitignore and remove the install.sh script

@joek-office
Copy link
Author

@sc68cal
have cleaned up.
i can't figure out, what the errors in the integration tests of v3.6/3.7 result from.
TypeError: Object of type PrettyOrderedSet is not JSON serializable
Can you give me a hint?

Think when the errors with integration tests was solved, the pull request is ready

@sc68cal
Copy link
Contributor

sc68cal commented Feb 21, 2024

@joek-office I'll try and take a look next week, I'm a bit swamped at the moment. I agree that's an unusual error.

@joek-office
Copy link
Author

joek-office commented Mar 11, 2024

@joek-office I'll try and take a look next week, I'm a bit swamped at the moment. I agree that's an unusual error.

Any news so far?

@sc68cal
Copy link
Contributor

sc68cal commented Mar 11, 2024

It's taking me a bit of time to transfer to a new machine to do development work, bear with me

@joek-office
Copy link
Author

@sc68cal
the question comes more from my side to don't forget the PR and to track progress. Please don't feel in any hurry from my request.

@sc68cal
Copy link
Contributor

sc68cal commented Mar 15, 2024

I'm going to re-run the failing jobs and see if it was just a transient error

@joek-office
Copy link
Author

Looks like a persistent error. Any ideas to solve the errors?

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.

2 participants