Quantcast
Viewing all articles
Browse latest Browse all 293210

Stumped by data structure expected by ->ReconfigVM_Task()

This piece has stumped me most all day.  I should would appreciate some more eyes on this code and particularly some advise on how to bypass these errors and get to a successful invocation of the ->ReconfigVM_Task() method.

sub _assign_vnic_to_loopback_portgroup {
  my $self = shift;
  my $vm = shift;
  my $vnic = $self->_get_vnic_object( $vm );;
  # $vnic->backing->deviceName('vsPG-LOOPBACK');
  # $vnic->backing->deviceInfo->summary('vsPG-LOOPBACK');

  # print 'The virtualNIC\'s key is: ' . $vnic->key . "\n";
  # print $vnic->backing->deviceName . "\n";
  print 'backing: ' . Dumper( $vnic->backing ) . "\n";
  # print 'network: ' . Dumper( $vnic->backing->network ) . "\n";
  print 'deviceInfo: ' . Dumper( $vnic->deviceInfo );
  # print 'vnic object: ' . Dumper( $vnic );


  my $network = ManagedObjectReference->new(
       'type' => 'Network',
      'value' => 'network-10868' );

  my $backing = VirtualEthernetCardNetworkBackingInfo->new(
           'deviceName' => 'vsPG-LOOPBACK',
    'inPassthroughMode' => '1',
              'network' => $network,
        'useAutoDetect' => '0' );

  my $device_info = Description->new(
          'label' => 'Network adapter 1',
        'summary' => 'vsPG-LOOPBACK' );

  my $spec = VirtualMachineConfigSpec->new(
 deviceChange => [
 { fileOperation => 'replace',
       operation => 'edit',
          device => {
                key => $vnic->key,
            backing => $backing, 
         deviceInfo => $device_info, },
        },
      ], );

  my %args = (
      spec => $spec
  );
  my $task_monitor = $vm->ReconfigVM_Task( %args );

  return my $task_monitor;
}

Today I have been plagued by a stack trace reading like this:

Cannot serialize deviceChange as VirtualDeviceConfigSpec at /usr/local/vmware/vsphere/lib/perl5/site_perl/5.8.8/VMware/VICommon.pm line 2430
        ComplexType::serialize('VirtualMachineConfigSpec=HASH(0xdba5b68)', 'spec') called at (eval 4962) line 111
        VimService::get_arg_string('VirtualMachineConfigSpec=HASH(0xdba5b68)', 'spec', 'VirtualMachineConfigSpec') called at (eval 4962) line 132
        VimService::build_arg_string('ARRAY(0xd82c7c4)', 'HASH(0xd82c764)') called at (eval 4962) line 2295
        VimService::ReconfigVM_Task('VimService=HASH(0xdb1b8e8)', '_this', 'ManagedObjectReference=HASH(0xdba6678)', 'spec', 'VirtualMachineConfigSpec=HASH(0xdba5b68)') called at /usr/local/vmware/vsphere/lib/perl5/site_perl/5.8.8/VMware/VICommon.pm line 1694
        ViewBase::invoke('VirtualMachine=HASH(0xdba67e0)', 'ReconfigVM_Task', 'spec', 'VirtualMachineConfigSpec=HASH(0xdba5b68)') called at (eval 4975) line 44
        VirtualMachineOperations::ReconfigVM_Task('VirtualMachine=HASH(0xdba67e0)', 'spec', 'VirtualMachineConfigSpec=HASH(0xdba5b68)') called at /home/hesco/sandbox/path/to/my/VMWare/RevertToSnapshot.pm line 225
        VWH::API::Integration::VMWare::RevertToSnapshot::_assign_vnic_to_loopback_portgroup('VWH::API::Integration::VMWare::RevertToSnapshot=HASH(0xdb86a14)', 'VirtualMachine=HASH(0xdba67e0)') called at recycle_vm.pl line 52

When I create the data structure somewhat differently, instead of the stack trace, I keep getting:

Not an ARRAY reference at /usr/local/vmware/vsphere/lib/perl5/site_perl/5.8.8/VMware/VICommon.pm line 2393.

Viewing all articles
Browse latest Browse all 293210

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>