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

Exception on Get RegisteredVirtualMachines with permission issue #18

Open
neilgierman opened this issue Apr 11, 2014 · 2 comments
Open

Comments

@neilgierman
Copy link
Contributor

On an ESX 5.5 system, if I log in with a user that has Read-Only access one VM on the host, a Get of RegisteredVirtualMachines will throw an exception at registeredVirtualMachines.Add(this.Open((string)runningVirtualMachine[0]));

In my use case, it is ok for me to skip VMs that I don't have access to because I am looking for a specific VM I do have access to. In my local build, I surrounded registeredVirtualMachines.Add(this.Open((string)runningVirtualMachine[0])); with an additional try block and "continue" on any exception for that one line.

I doubt this is the best solution but would like to find some solution where I can get the list of VMs without crashing the library if there is a VM in inventory that I don't have access to.

In case you are interested, the patch that works for my specific use case is:

--- VMWareTasksHead\Source\VMWareLib\VMWareVirtualHost.cs   2014-04-11 13:19:35.000000000 -0500
+++ VMWareTasksHead\Source\VMWareLib\VMWareVirtualHost.cs   2014-04-11 13:11:23.000000000 -0500
@@ -551,13 +551,20 @@
                         Constants.VIX_FIND_REGISTERED_VMS, null, -1, callback),
                         callback))
                     {
                         object[] properties = { Constants.VIX_PROPERTY_FOUND_ITEM_LOCATION };
                         foreach (object[] runningVirtualMachine in job.YieldWait(properties, VMWareInterop.Timeouts.FindItemsTimeout))
                         {
-                            registeredVirtualMachines.Add(this.Open((string)runningVirtualMachine[0]));
+                            try
+                            {
+                                registeredVirtualMachines.Add(this.Open((string)runningVirtualMachine[0]));
+                            }
+                            catch (Exception ex)
+                            {
+                                continue;
+                            }
                         }
                     }

                     return registeredVirtualMachines;
                 }
                 catch (Exception ex)
@dblock
Copy link
Owner

dblock commented Apr 11, 2014

It all depends what we think this interface should do in this case, in general. Just ignoring the VM would be wrong because from the API consumer POV they would not be getting all registered machines without any explanation why. Maybe we can replace Open by something else, ie. the VMs added here would not be "opened", but in a state that requires them to be "opened" to do something useful?

@neilgierman
Copy link
Contributor Author

I don't know the other uses of the collection returned by "RegisteredVirtualMachines" (or also Powered). My use is just get me a collection of VM's with their path and name, and I will loop through that collection until I find the member that has the name or path that I want. Maybe your idea of just return the names and paths so the caller can "Open" or whatever a specific member would be good. It also might speed things up because right now getting RegisteredVirtualMachines takes about 10 seconds to return and I only have 77 VMs. However to get the VM's name, I think I need to open() the VM.

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

No branches or pull requests

2 participants