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

host.Compare returns true if one of the variables match #6

Closed
arpanadhikari opened this issue Feb 20, 2022 · 2 comments
Closed

host.Compare returns true if one of the variables match #6

arpanadhikari opened this issue Feb 20, 2022 · 2 comments

Comments

@arpanadhikari
Copy link

Hi there!

Not sure if this is a intended behaviour in the sdk, but when comparing two hosts, the sdk returns true if one of the Id, Pool or NameLabel match.

This can be an issue if we're comparing two hosts in the same pool?

code-ref:

func (h Host) Compare(obj interface{}) bool {
	otherHost := obj.(Host)
	if otherHost.Id == h.Id {
		return true
	}
	if h.Pool == otherHost.Pool {
		return true
	}
	if h.NameLabel != "" && h.NameLabel == otherHost.NameLabel {
		return true
	}
	return false
}

Happy to make a pull request if this is considered a potential opportunity for improvement.

@ddelnano
Copy link
Collaborator

ddelnano commented Mar 2, 2022

@arpanadhikari sorry for the late reply! I was traveling the past few weeks.

This code was written with that particular purpose in mind. The only consumer of this client that I'm aware of is the terraform-provider-xenorchestra, where this client code was initially developed.

The idea behind designing it this way was to treat the argument to Client.FindFromGetAllObjects as a filter. Depending on the fields set on the struct (such as the Pool field), it will return anything that matches. The terraform provider needs to filter on all hosts that are within a pool in this way here.

I am planning to rethink how this xo-sdk-go client code works soon (in vatesfr/terraform-provider-xenorchestra#189). So I would love to hear more about how you'd like to use this client and how its existing design isn't solving your use case.

@arpanadhikari
Copy link
Author

I see, thanks!

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

No branches or pull requests

2 participants