vSphere

 View Only
  • 1.  PowerCLI vs Perl SDK

    Posted Oct 14, 2015 06:26 PM

    On the PowerCLI side, I can execute:

    set-template -template <name> -tovm

    ...which will convert a template to a VM.

    On the Perl SDK side, I found the MarkAsVirtualMachine call which appears to do something similar.

    However, on the Perl SDK side the above call requires a ResourcePool be passed whereas the PowerCLI command does not require a ResourcePool.

    In our environment we are not using defined ResourcePools - we do have ClusterComputeResources, but that does not help me.

    Can anyone offer any suggestions to getting something on the Perl SDK side that performs similarly to the set-template on the PowerCLI side?

    Thanks,

    -M



  • 2.  RE: PowerCLI vs Perl SDK

    Posted Oct 14, 2015 06:31 PM

    So even without any ResourcePools in our vSphere Client UI, there are some default resource pool entities.

    You can get it from your virtual machine object with the property 'resourcePool'.  That's most likely what the PowerCLI cmdlet is doing, just using the same resource pool the template is current in (template and virtual machines are the same object, it's just a boolean flag).

    So, from Perl, assuming you got the resourcePool property from your get_view or find_entity_view calls:

    $pool_moref = $vm->{'resourcePool'};

    $pool = Vim::get_view(mo_ref => $pool_moref);

    # ...



  • 3.  RE: PowerCLI vs Perl SDK

    Posted Oct 14, 2015 07:10 PM

    Thanks for the reply, Stumpr.  This makes sense; however, I am still needing some assistance with the proof of concept.

    I have this:

    my $vm_name = "test_vm_template"

    my $vm = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {'name' => $vm_name});

    print "vm name = " . $vm->name . "\n";

    $pool_moref = $vm->{'resourcePool'};

    $pool = Vim::get_view(mo_ref => $pool_moref);

    print "resource name = " . $pool->name . "\n";

    The 1st print statement is showing me the vm name but the 2nd is returning an error of (can't call method "type" on an undefined value).

    It appears I am attempting to access the resource pool incorrectly. 



  • 4.  RE: PowerCLI vs Perl SDK

    Posted Oct 14, 2015 08:01 PM

    Upon further testing it appears the error I am receiving is with the 2nd suggested command:

    my $vm_name = "test_vm_template"

    my $vm = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {'name' => $vm_name});

    print "vm name = " . $vm->name . "\n";

    $pool_moref = $vm->{'resourcePool'};

    $pool = Vim::get_view(mo_ref => $pool_moref);

    print "resource name = " . $pool->name . "\n";

    The error is happening on line #5.



  • 5.  RE: PowerCLI vs Perl SDK
    Best Answer

    Posted Oct 14, 2015 11:12 PM

    Yeah, probably have to hop through the host.

    my $vm_name = "test_vm_template";

    my $vm = Vim::find_entity_view(view_type => 'VirtualMachine', filter => { 'name' => $vm_name });

    my $host_ref = $vm->{'runtime'}{'host'};

    my $host = Vim::get_view(mo_ref => $host_ref, properties => ['name', 'parent']);

    my $compute = Vim::get_view(mo_ref => $host->{'parent'}, properties => ['name', 'resourcePool']);

    my $pool = Vim::get_view(mo_ref => $compute->{'resourcePool'}, properties => ['name']);

    # Now use $pool as parameter to MarkAsVirtualMachine

    I'm doing this completely from the SDK doc, so I'm sure there are typos.