-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
r/virtual_machine: Fix template UUID lookup for older vSphere versions #377
Conversation
Historically, the FindByUuid method under SearchIndex did not support looking up VMs marked as template. However, at some point in time, this was changed (possibly vSphere 6.5, based on bug reports), and any mention of the UUID search not supporting templates was removed from the API documentation, without a mention of when support for templates was introduced. Since this is the method that we use to look up both VMs and templates, this means that templates have not been functional for vSphere <= 6.0 users since the resource was re-written in 1.0. There has been a workaround in that the source template is just converted back to virtual machine, but this update fixes it so that on versions of vSphere older than 6.5, we fall back to using ContainerView with a filter on the UUID. This works for all versions of vSphere. We keep FindByUuid for 6.5 as it may possibly be more direct path.
18c73ab
to
0adde0b
Compare
Tests pass. We unfortunately can't test the
|
func virtualMachineFromSearchIndex(client *govmomi.Client, uuid string) (object.Reference, error) { | ||
log.Printf("[DEBUG] Using SearchIndex to look up UUID %q", uuid) | ||
search := object.NewSearchIndex(client.Client) | ||
ctx, cancel := context.WithTimeout(context.Background(), provider.DefaultAPITimeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be preferable to pass the ctx
in and declare the Background
up as high in the callstack as possible, in this case at lease up in FromUUID
, to make switching to StopContext
down the road easier.
defer func() { | ||
dctx, dcancel := context.WithTimeout(context.Background(), provider.DefaultAPITimeout) | ||
defer dcancel() | ||
v.Destroy(dctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't care about the error, explicitly discard it, ie: _ = v.Destroy
so it doesn't look like an oversight.
* Consolidated contexts (this will help streamline things when we add in support for exposing the provider contexts). * Added in error handling for the ContainerView destroy call. We don't expect this to error, so we panic if it does - this ensures it passes both errcheck and gas, which I am using now that I've adopted gometalinter. This may or may not be the standard going forward.
|
||
defer func() { | ||
if err = v.Destroy(ctx); err != nil { | ||
panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you would rather not panic here, you could just wrap the body in an inner func, and do this afterwards, but seems fine to me as is, as its probably an edge.
For the destroy of the container view.
wewt wewt! When does |
@johnjelinek it's out now! |
Historically, the
FindByUuid
method underSearchIndex
did not supportlooking up VMs marked as template. However, at some point in time, this
was changed (possibly vSphere 6.5, based on bug reports), and any
mention of the UUID search not supporting templates was removed from the
API documentation, without a mention of when support for templates was
introduced. Since this is the method that we use to look up both VMs and
templates, this means that templates have not been functional for
vSphere <= 6.0 users since the resource was re-written in 1.0.
There has been a workaround in that the source template is just
converted back to virtual machine, but this update fixes it so that on
versions of vSphere older than 6.5, we fall back to using
ContainerView
with a filter on the UUID. This works for all versions of vSphere. We
keep
FindByUuid
for 6.5 as it may possibly be more direct path.Fixes #271