VMware Cloud Community
iendicott
Contributor
Contributor

Orphaned VM

I have run multiple searches in google and these communities and have found nothing that resembles the issue we are having.

There is an orphaned VM with Virtual Centre, I know it's only in Virtual Centre as if I login to the VI client directly on the host the VM no longer exists. Just to make things clear I have no need to keep the VM as it was a testing only.

I connect to the VC server again and then right click on the VM but the options are small and delete is not available. If I hit the delete key on the keyboard I get the message "You do not have the privilege to delete the selected items". I am beginning to suspect this is an issue with VC Server miss reporting the VM which I again suspect is maybe registered in the VC Server SQL database.

Has anyone come across this. I have restarted the following services mgmt_vmware \ vmware_vmkauthd \ vmware_vpxa and also reboot Virtual Centre

We are running VC Server 2.5.0 Build 119598 and ESX server 3.5.0 Build 123630.

Thanks in advanced.

0 Kudos
14 Replies
msemon1
Expert
Expert

Have you tried un-registering the VM?

Mike

0 Kudos
Troy_Clavell
Immortal
Immortal

also try to restart your vCenter Server Service.

0 Kudos
lamw
Community Manager
Community Manager

We do lots of testing and sometimes will get 20-40 orphaned VM(s) and as you said on the individual host they'll be gone but on vCenter there is still the stale orphaned instances. You could manually remove from inventory on each one or bulk them up in a folder, but I decided to write a small script to automate this if you have orphaned VM(s) showing up in vCenter.

#!/usr/bin/perl -w

use strict;
use warnings;
use VMware::VILib;
use VMware::VIRuntime;

Opts::parse();
Opts::validate();
Util::connect();

my ($hosts, $host);

$hosts = Vim::find_entity_views(view_type => 'HostSystem');

unless (defined $hosts){
        die "No hosts found.\n";
}

foreach $host(@{$hosts}) {
        print "Searching Host: ", $host->name,"\n";
        my $vm_views = Vim::get_views(mo_ref_array => $host->vm, properties => );
        foreach(sort {$a->{'summary.config.name'} cmp $b->{'summary.config.name'}} @$vm_views) {
                if($_->{'summary.runtime.connectionState'}->val eq 'orphaned') {
                        print "\t",$_->{'summary.config.name'}, " ", $_->{'summary.runtime.connectionState'}->val," & Removed from inventory!\n";
                        $_->UnregisterVM();
                }
        }
}
Util::disconnect();

This Perl script just connects to vCenter and will look for all VM(s) that have a connectionState equal to orphaned and it'll unregister and remove from inventory.

Generally you should be able to manually remove from inventory using the VI Client and if vCenter is being stubborned, you can restart the services as suggested and usually that'll do that trick.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

0 Kudos
runclear
Expert
Expert

responded to the wrong post - 😛 :smileycool:

-------------------- What the f* is the cloud?!
0 Kudos
iendicott
Contributor
Contributor

Hi William,

When you say manually remove them from the inventory I am trying to do this throught eh Vi client connected to Virtual Centre. The way I have tried is to right click on the orphan but the only options I get are the following

Snapshot, Add Alarm, Add Permission, Open Console, Report Performance, Migrate Storage.

There is no delete function available. Is supect the VM is registered in the Virtaul Centre's database but there is no instance on the host so how would I do this ?

With the script you refer to do I run this on a service console within one of the hosts ? And also do I replace theany of the variables with the name of our Vcentre Server ?

Thanks for your help.

To msemon1 I can't as the files are no longer on the Lun as in desperation I have removed to see if this would fix the issues.

To Troy Clavell yes I have rebooted the Virtual Centre server.

Thanks guys for the suggestions

0 Kudos
lamw
Community Manager
Community Manager

The script should be pointing to your vCenter server and using valid credentials to login and requires you to install the VI Perl Toolkit on either a Windows or Linux system, it's not to be executed on the Service Console of the host. The issue lies in your vCenter having stale information, to the script will query vCenter to see if it even detects those Orphaned VM(s) and check the state it thinks it's in.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

0 Kudos
msemon1
Expert
Expert

Go to the service console of the problematic ESX host. Run the following command with root privileges:

vmware-cmd -l

output looks like :

/vmfs/volumes/48341f38-2b47d258-9433-0013216bc092/vm01/vm01.vmx

Now you see the registered vm's on that esx host. To unregister them use the following command:

vmware-cmd -s unregister /vmfs/volumes/48341f38-2b47d258-9433-0013216bc092/vm01/vm01.vmx

0 Kudos
iendicott
Contributor
Contributor

William I take it you install the pearl application on the Vcentre server then ?

Thanks

0 Kudos
lamw
Community Manager
Community Manager

You can install it on the vCenter server, but it does not have to. Usually you would just install it on a desktop system that you would use to connect to vCenter/etc.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

0 Kudos
iendicott
Contributor
Contributor

William how do you tell the program what Vcentre server you are using ? Is there a line in the script that you kindly supplied that I have to change to specify the server ?

Many thanks

0 Kudos
lamw
Community Manager
Community Manager

Whatever you named your script you can provide the standard credentials format:

./script_name.pl --server <YOUR_VC_SERVER> --username <USERNAME>

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

0 Kudos
iendicott
Contributor
Contributor

Mathew thanks for the reply, I am getting the output below now (I have replaced details with xxx to hide information), I am assuming this is not right ?

"P:\&gt;P:\vc.pl --server xxxxxxxx --username xxxxxxxx

Enter password:

Searching Host: xxxx.xxxx.com

Odd number of elements in hash assignment at C:/Program Files/VMware/VMware VI P

erl Toolkit/Perl/lib/VMware/VICommon.pm line 1059, &lt;STDIN&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Use of uninitialized value in string comparison (cmp) at P:\vc.pl line 23, &lt;STDI

N&gt; line 1.

Can't call method "val" on an undefined value at P:\vc.pl line 24, &lt;STDIN&gt; line

1.

End Disconnect"

0 Kudos
lamw
Community Manager
Community Manager

What version of vCenter and ESX/ESXi are you using? This should work on ESX 3.5+ and vCenter 2.5+ using VI SDK 2.5

Here the same code working on a Windows XP system running VI Perl Toolkit 1.6

C:\Documents and Settings\Administrator\Desktop>getVMState.pl --server reflex.pr
imp-industries.com --username primp
Enter password:
Searching Host: himalaya.primp-industries.com
        Auroa connected
        Bitsy connected
        Certiorari connected
        Clifford connected
        ESX-Kickstart connected
        Fourier connected
       ......

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

iendicott
Contributor
Contributor

William,

Your not going to beleive how this was fixed. We had to contact VMware about another issue with VC update 4, whilst the guy was on he fixed this but doing the following.

Under VIRTUAL MACHINES AND TEMPLATES he created another folder called TEST then he dragged the machine into this folder and then delete the folder which deleted the stale VM inside it !!!

Now theres a piece of useful info !!!

Thanks for all your help BTW.

Ivan

0 Kudos