I hope this is not an impossibility but Im looking for a way to remove a VM from the list in VC automatically using some sort of task or script. I can unregister a VM with vmware-cmd but it shows as orphaned on the list. I'd like to remove it alltogether from VC, is there any automated way or doing that?
There sure is.
Check out the VIPerlToolkit:
http://www.vmware.com/beta/viperltoolkit/index.html
Specifically, they include a script that already does what you want:
http://www.vmware.com/support/pubs/beta/viperltoolkit/doc/perl_toolkit_utilities_idx.html
(see vmregister, which performs both register/unregister ops)
I originally grabbed the viperltoolkit off sourceforge.net, and I recommend that only if you'll be compiling it on your own. However, from the above page, you can access downloads of a Windows installer, or a viperltoolkit virtual appliance instead.
Enjoy! There's LOTS of great stuff you can do with viperltoolkit. Personally, I use it to generate several automated reports on snapshots, connected devices, etc. Things we just can't get out of Virtual Center directly without lots of manual review.
J
You might need to restart the VC service so the orphaned VM will go away.
I tried restarting the service but the orphaned VM still showed in the list.
If you right click on the VM does it show an option to "Remove from Inventory"? If that works and you want to automate things you could take a look at the VirtualCenter SDK.
Yes I do the remove from inventory when using the client but I was hoping for a command line based way of doing that without going into the SDK.
There sure is.
Check out the VIPerlToolkit:
http://www.vmware.com/beta/viperltoolkit/index.html
Specifically, they include a script that already does what you want:
http://www.vmware.com/support/pubs/beta/viperltoolkit/doc/perl_toolkit_utilities_idx.html
(see vmregister, which performs both register/unregister ops)
I originally grabbed the viperltoolkit off sourceforge.net, and I recommend that only if you'll be compiling it on your own. However, from the above page, you can access downloads of a Windows installer, or a viperltoolkit virtual appliance instead.
Enjoy! There's LOTS of great stuff you can do with viperltoolkit. Personally, I use it to generate several automated reports on snapshots, connected devices, etc. Things we just can't get out of Virtual Center directly without lots of manual review.
J
I was hoping for a command line based way
of doing that without going into the SDK.
Command line at the Virtual Center service is non-existant. I think the SDK or viperltoolkit are your only options. With the windows installer for viperltoolkit, you could install it on the VC server so you would then be able to call the script from the local command line if you wish.
Note: I have NOT read any release notes on the windows version, so I do not know if VMware has any recommendations for or against installing this on the VC server.
Thanks for the reply, I download the viperltoolkit and read through the documentation but I noticed that the unregister script only unregisters the VM but does not remove it from the list. I can unregister the VM through vmware-cmd as well but my problem is that it still shows up on the list in VC. I need a way to remove that reference to the VM in virtualcenter.
I just tested it out and it worked perfectly...
perl vmregister.pl --url https://virtualcenter/sdk/webService --username <user> --password <pass> --operation unregister --vmname <vmname>
Unregister of VM '' successfully completed
And I saw the task in Virtual Center go active, complete, and the inventory view automatically refreshed and the system was gone.
Did you actually try it? This doesn't perform a standard vmware-cmd...
Regards,
J
Message was edited by:
hicksj
NOTE: You MUST run this against the Virtual Center service, not the ESX host. If you run the unregister process against ESX, it will end up orphaned because VC doesn't know what happened to it when the host stops reporting its existence.
Thanks for the help, I just tried it and I get the following message:
>perl vmregister.pl --url https://virtualcenter/sdk/webService --username --operation unregister --vmname dev-vm
Unknown option: operation
Unknown option: vmname
Im looking through the command hoping I just missed something real simple.
Does your username or password contain any special characters?
If so, you need to 'escape' them with a '\' or enclose the entire word with quotes.
I was not able to run it using the vmregister.pl script becuase the --operation argument was not supported. I did see a vmunregister.pl script so I ran that one without the --operation argument and it works great. Thanks for you help, now I can script this to run nightly so we can P2V critical servers on a schedule. Your comments were very helpful.
Below is the command I used to get it to work:
perl vmunregister.pl --url https://vcenter/sdk/webService --username <user> --password <pass> --vmname dev-vm
Message was edited by:
arcom
Ah.... now I see what's happening!
The viperltoolkit distribution has 2 sets of scripts... one set under "samples" and another set under "apps."
The one under apps is a combined register/unregister script, as opposed to the separate ones under samples! Sorry about the confusion - i didn't realize there were conflicting scripts. My example was based on the apps version.
FYI, the "apps" version does have additional checks for powerState. (it verifies the VM is powered off prior to unregistering)
HTH,
J
I got so caught up in trying to get it work I didnt even think to look anywhere else. The p2vtool puts its sample xml files under the samples folder so I figured the perl toolkit did the same. I just tried it your way and it works just as good. Ill do that one in the final implementation. Thanks again.