I have to be doins something wrong. I'm not sure what. I'm very new to the API and I'm piecing a script to create VMs together. I can't use the standard one because I have different requirements (SAN clusters, and distributed vswitches). Besides, writing scripts is fun
So, this is the first try at creating a new guest. Whenever I run it vSphere server crashes completely. My vSphere Server is version 5.0.0.29542.
Any thoughts on why it crashed? Attached is the script.
Thanks,
Scott
#!/usr/bin/perluse strict;use VMware::VIRuntime;use VMware::VILib;use Data::Dumper;# Connect to vSphere and collect informationOpts::parse();Opts::validate();Util::connect();my $dscluster = Vim::find_entity_view(view_type => 'StoragePod', filter => {'name' => "MySAN" }, properties => ['name']);if ( ! defined( $dscluster ) ) {print "Unable to locate datastore cluster: $dscluster!\n";Util::disconnect();exit 1;}my $folder = Vim::find_entity_view(view_type => 'Folder', filter => {'name' => "RandomFolder"}, properties => ['name']);if ( ! defined( $folder ) ) {print "Unable to find folder to use!\n";Util::disconnect();exit 1;}# Define the new VMmy @vm_devices;my $configSpec = VirtualMachineConfigSpec->new(name => "test-vm",memoryMB => 2048,numCPUs => 2,deviceChange => \@vm_devices);# We only have one resource pool. Use that one for the storageplacementspecmy $resourcePools = Vim::find_entity_views( view_type => "ResourcePool" );# Create a storage placement for the host to pass to recommenddatastoresmy $storageMgr = Vim::get_view(mo_ref => Vim::get_service_content()->storageResourceManager);my $podSpec = StorageDrsPodSelectionSpec->new(storagePod => $dscluster);my $storageSpec = StoragePlacementSpec->new( type => "create",podSelectionSpec => $podSpec,folder => $folder,configSpec => $configSpec,resourcePool => $resourcePools->[0]);# Figure out which datastore to put the guest on. Pick the VM that will have the# most space free at the endmy $result = $storageMgr->RecommendDatastores(storageSpec => $storageSpec);my $curRec;my $curRecFree = 100;foreach my $rec ( @{$result->recommendations} ) {if ( $rec->action->[0]->spaceUtilAfter < $curRecFree ) {$curRecFree = $rec->action->[0]->spaceUtilAfter;$curRec = $rec->key;}}# Create the VM$storageMgr->ApplyStorageDrsRecommendation_Task( key => [ $curRec ] );