Sunday, March 31, 2013

Removing orphaned replicas in VMware View 4.6 with sviconfig.exe

I recently had to perform some maintenance with a client’s VMware View 4.6 prior to migrating them to a newly built 5.1 environment and one of the items on my list to do was to clean up their existing VMware View LUNs on their SAN.  This environment has had quite a few issues over the last few months with pools not being removed properly either due to lack of space on the SAN or some type of corruption so not to my surprise, there were 20 replicas listed in vCenter even though there was only 2 VMware View desktop pools where each master template only had 2 snapshots:


It’s obvious that most of them are no longer used so I went ahead and used the following KB in an attempt to identify them:

Finding and removing unused replica virtual machines in VMware View (2009844)

What was unfortunate was that the unused-replica-1.txt file generated with the procedure shown was empty which meant I was left to manually identify which replicas were orphaned.  What turned out to be in my favour was that the only 2 pools in the environment were newly created 2 weeks ago which meant I could identify which ones are old by manually browsing the datastore that contained the replicas and checking the date.  If the date of the files were older than the day that the pools were created, the replicas were probably not being used.  Note how the Modified field in the following screenshot above is dated 9/5/2012 which goes back about 6 months from today:


The problem with VMware View replicas is that all of them are protected so if you make an attempt to delete them in vCenter, you will see the Remove from Inventory and Delete from Disk options grayed out:


The following VMware KB provides instructions on how to use the sviconfig.exe executable to unprotect the replicas so that you can delete them:

Cannot remove source and replica virtual machines associated with View Composer desktop pools (1008704)

It’s important to note that the parameter requirements are different for View Composer 2.7 (View 5 and earlier) and 3.0 (View 5.1).  The environment in this example is VMware 4.6 so I will use the following command:

sviconfig -operation=UnprotectEntity -VcUrl=https://<VirtualCenter address>/sdk -Username=<VirtualCenter account name> -Password=<VirtualCenter account password> -InventoryPath=/<Datacenter name>/vm/VMwareViewComposerReplicaFolder/<Replica Name> -Recursive=true

The items required to be modified are highlighted in RED and after substituting the requirement parameters, your command should look something like the following:

sviconfig -operation=UnprotectEntity -VcUrl= -Username=domain\lukterence -Password=Tah23a-5 -InventoryPath=/DC1/vm/VMwareViewComposerReplicaFolder/replica-509dd5c1-1e66-4f84-ab9a-a79c89a05fb8 -Recursive=true

You should receive an output similar to the following upon successfully executing the cmdlet with the correct substitution:

C:\Program Files (x86)\VMware\VMware View Composer>sviconfig -operation=UnprotectEntity -VcUrl= -Username=domain\lukterence -Password=Tah23a-5 -InventoryPath=/DC1/vm/VMwareViewComposerReplicaFolder/replica-509dd5c1-1e66-4f84-ab9a-a79c89a05fb8 -Recursive=true

WARNING: Unprotecting VC managed entities will allow operations

(power on, delete, migrate) that can cause existing linked clones connected

to those managed entities to fail to work correctly.

Establishing connection to the VC server.

VC server connection established successfully.

Looking for the entity on the VC server.

VirtualMachine found.

VirtualMachine with MoId vm-19032 sucessfully unprotected.

SviConfig finished successfully.

Successfully unprotected entities: 1

Fail to unprotect entities: 0

C:\Program Files (x86)\VMware\VMware View Composer>


With the command successfully executed, you should now be able to delete the replica:



Note that if you make a typo or provided an incorrect parameter when using the sviconfig.exe command, you won’t get an explanation pointing out the mistake you made.  The following is a mistake I made when originally executing the command where I accidentally used the / for my domain\user credentials:

C:\Program Files (x86)\VMware\VMware View Composer>sviconfig -operation=UnprotectEntity -VcUrl= -Username=domain/lukterence -Password=Tah23a-5 -InventoryPath=/DC1/vm/VMwareViewComposerReplicaFolder/replica-509dd5c1-1e66-4f84-ab9a-a79c89a05fb8 -Recursive=true

This operation will remove the protection from a VC entity.
Currently only VirtualMachine and Folder entities are supported.

WARNING: Unprotecting VC entities will allow operations
(power on, delete, migrate) that can cause existing linked clones connected
to those managed entities to fail to work correctly. Use this operation with

  -VcUrl=<Virtual Center service URL>
  -Username=<VC account name>
  -Password=<VC account password>
  -InventoryPath=<Entity inventory path>

All parameters are not allowed to be an empty string.
The following parameters are required:
   VcUrl - The URL of the Virtual Center server, where the protected
           virtual machine is located.
   Username - The username that will be used to connect to the VC server.
   Password - The password for the username to connect to the VC server.
   InventoryPath - The VC entity inventory path.
The following parameters are optional:
   Recursive - If the entity is folder, setting this parameter to 'true' will
               unprotect recursively folder's content (VMs and folders). If
               the entity is VM, this parameter will be ignored. Default value
               is 'false'.

A virtual machine can be created under the default vmFolder or under user
specified folder (vmFolder subfolder).
A folder can be created under vmFolder (to organize VMs) or under hostFolder
(to organize hosts).

InventoryPath syntax is the following:
1. To unprotect a VM, that is in the vmFolder:
2. To unprotect a VM, that is in a folder:
3. To unprotect a folder, created under vmFolder:
4. To unprotect a folder, created under hostFolder

<datacenter_name> - the name of the datacenter
<folder_name> - the name of the folder
<vm_name> - the name of the virtual machine
/vm/ - represents vmFolder and is mandatory
/host/ - represents hostFolder and is mandatory

If one of the above names contains space, the whole path should be enclosed in
quotation marks.

For more information regarding VC inventory, see "VMware Infrastructure SDK
Programming Guide".

1. To unprotect a VM, that is in the vmFolder:
   SviConfig -operation=UnprotectEntity -VcUrl=
     -Username=User1 -Password=123 -InventoryPath=
     "/My Datacenter/vm/SVI-clone-1"

2. To unprotect a replica, that is in the 'MyReplicaFolder' folder:
   SviConfig -operation=UnprotectEntity -VcUrl=
     -Username=User1 -Password=123 -InventoryPath="/My Datacenter/vm/

3. To unprotect the replica folder 'MyReplicaFolder':
   SviConfig -operation=UnprotectEntity -VcUrl=
     -Username=User1 -Password=123 -InventoryPath=
     "/My Datacenter/vm/MyReplicaFolder"

4. To unprotect the replica folder 'MyReplicaFolder' and all the replica VMs
in it:
   SviConfig -operation=UnprotectEntity -VcUrl=
     -Username=User1 -Password=123 -InventoryPath=
     "/My Datacenter/vm/MyReplicaFolder" -Recursive=True

5. To unprotect a folder 'Dev hosts', created under hostFolder:
   SviConfig -operation=UnprotectEntity -VcUrl=
     -Username=User1 -Password=123 -InventoryPath=
     "/My Datacenter/host/Dev hosts"

  0  - operation ends successfully.
  2  - invalid credentials.
  9  - invalid URL.
  10 - VC can not be accessed.
  11 - entity is not found.
  12 - unknown entity type.
  13 - release failed.

C:\Program Files (x86)\VMware\VMware View Composer>

Notice how the output displays the instructions for how to use sviconfig.exe but not tell you the mistake made.

1 comment:

Blogger said...

Order a professional Sparkling White Smiles Custom Teeth Whitening System online and enjoy BIG SAVINGS!
* Up to 10 shades whiter in days!
* Results Are Guaranteed.
* Better than your dentist.
* Same Teeth Whitening Gel as dentists use.