Currently, sharing VMs across multiple Chargeback folders must be done individually. This can take some time for a large environement. This script uses the vCenter Chargeback 1.0.1 REST API to automate this task.
This example Perl script was tested using ActiveState Perl 5.8.8 as delivered with the VMware VI Perl Toolkit. However, it does not use any VI Perl specific features. It was tested against vCenter Chargeback 1.0.1.
This example is unsupported. Feel free to modify/improve for your own purposes.
The attached zip includes chshare.pl, cbshare.xml, folders.csv and vms.txt.
Set the runtime configuration parameters in the chshare.xml file. This XML file has tags for vCenter Chargeback credentials (local only), the hierarchy name, folder file and VM list file.
The folders.csv file is a comma separated value file that contains the Chargeback folder names and the sharing percentages for each folder. The Chargeback folders must exist in the Chargeback hierarchy specifed in the cbshare.xml configuration file. You must specify whole percentage numbers and the total must add up to 100. Lines that begin with a "#" are ignored. You might think of this file as a kind of "sharing template" or "sharing profile" that can be applied to a VM in Chargeback.
The vms.txt file contains one VM per line. The VMs must already be present in vCenter Chargeback in the hierarchy specified.
The VMs must reside in one of the folders listed in the folders.csv file.
Bill