Quantcast
Channel: VMware Communities : All Content - vSphere Management SDK
Viewing all articles
Browse latest Browse all 1860

ReconfigVM_Task - Problem reconfiguring VirtualEtheretCard.

$
0
0

Hi there!

 

I'm trying to reconfigure an existing Virtual Machine, but i'm getting an error that doesn't describe the problem very well

What i'm trying to reconfigure is the network label of the adapter.

 

here goes my code:

 

 

public static void reconfigVm(
     final UtilitiesWsStub.WsData wsData,
     final String vmPathName,
     final String dataCenterName )
     throws RemoteException
     {
          //service
          final VimBindingStub vimPort = wsData.getStub();
          final ServiceContent serviceContent = wsData.getServiceContent();
         
          //vm MOR
          final ManagedObjectReference vmRef = findByInventoryPath( wsData, vmPathName );
          //get vm config info
          final VirtualMachineConfigInfo vmConfigInfo = ( VirtualMachineConfigInfo ) getObjectProperty(
               vimPort,
               serviceContent,
               vmRef,
               "config" );
          if ( vmConfigInfo == null )
          {
               final String logMsg = String.format( "VM Config info not found" );
               throw new IllegalStateException( logMsg );
          }
          // vm hardwares
          final VirtualHardware vmHardware = vmConfigInfo.getHardware();
          final VirtualDevice[] devices = vmHardware.getDevice();
          VirtualPCNet32 defaultNetworkAdapter = null;
          // searches for network adapter 1
          for ( final VirtualDevice device : devices )
          {
               final Description deviceDesc = device.getDeviceInfo();
               if ( deviceDesc.getLabel().compareTo( "Network adapter 1" ) == 0 )
               {
                    defaultNetworkAdapter = ( VirtualPCNet32 ) device;
                    break;
               }
          }
          // if ethernet adapter not foun
          if ( defaultNetworkAdapter == null )
          {
               final String logMsg = String.format( "No default network adapter in virtual machine" );
               throw new IllegalStateException( logMsg );
          }
          final VirtualEthernetCardNetworkBackingInfo defaultBackingEthernet = ( VirtualEthernetCardNetworkBackingInfo ) defaultNetworkAdapter
               .getBacking();
         
          // datacenter
          final ManagedObjectReference datacenterRef = findByInventoryPath( wsData, dataCenterName );
          // networks
          final ManagedObjectReference[] networks = ( ManagedObjectReference[] ) getObjectProperty(
               vimPort,
               serviceContent,
               datacenterRef,
               "network" );
          ManagedObjectReference networkToUse = null;
          for ( final ManagedObjectReference network : networks )
          {
               final String networkName = ( String ) getObjectProperty( vimPort, serviceContent, network, "name" );
               if ( networkName.equals( "VM Network" ) )
               {
                    networkToUse = network;
                    break;
               }
          }
          // if network not found
          if ( networkToUse == null )
          {
               final String logMsg = String.format( "Network not found" );
               throw new IllegalStateException( logMsg );
          }
          //backing info config
          defaultBackingEthernet.setDeviceName( "VM Network" );
          defaultBackingEthernet.setNetwork( networkToUse );
          //vm device config spec
          final VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec();
          vmDeviceSpec.setDevice( defaultNetworkAdapter );
          vmDeviceSpec.setFileOperation( VirtualDeviceConfigSpecFileOperation.replace );
          vmDeviceSpec.setOperation( VirtualDeviceConfigSpecOperation.edit );
          final VirtualDeviceConfigSpec[] vetVmDeviceSpec = new VirtualDeviceConfigSpec[1];
          vetVmDeviceSpec[0] = vmDeviceSpec;
         
          //vm config spec
          final VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
          vmConfigSpec.setDeviceChange( vetVmDeviceSpec );
          vmConfigSpec.setName( vmConfigInfo.getName() );
         
           // reconfig task
          vimPort.reconfigVM_Task( vmRef, vmConfigSpec );
}
The error loged in the vCenter is the following:
Reconfigure virtual machine
teste
Invalid operation for device '0'.
Administrator
VCENTER01
2/3/2012 5:13:04 PM
2/3/2012 5:13:04 PM
2/3/2012 5:13:04 PM
anyone can help me?
thanks.

Viewing all articles
Browse latest Browse all 1860

Trending Articles



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