VMware {code} Community
mdvlinguest
Contributor
Contributor

Incompatible device backing error when changing network adapter address type

Hello Expert Developer,

I am working on an automatic VM deployment project for vSphere. I am trying to reconfigure deployed VM and change the MAC address of its network adapter. Device type which is being edited is Vmxnet3. I am using the following code snippet to reconfigure the VM in php using VMWarephp library.

[code]

   $deviceConfigSpec = new VirtualDeviceConfigSpec();

    $deviceConfigSpec->operation = 'edit';

    $deviceConfigSpec->device = new VirtualVmxnet3();

     foreach ($configInfo->hardware->device as $device) {

      if (get_class($device) == 'VirtualVmxnet3') {

          $deviceConfigSpec->device->key = $device->key;

          $deviceConfigSpec->device->controllerKey = $device->controllerKey;

          $deviceConfigSpec->device->unitNumber = $device->unitNumber;;

          $deviceConfigSpec->device->addressType = 'Manual';

          $deviceConfigSpec->device->macAddress = $mac;

      }

    } 

    $configSpec = array('deviceChange' => array($deviceConfigSpec));

    $vm->ReconfigVM_Task(array('_this'=>$vm->reference, 'spec'=>$co

[/code]

When this code is ran, I get the following error in vSphere Client's task list:

Incompatible device backing specified for device '0'

I will appreciate if you can help me

Thanks in advance.

[code]
    $deviceConfigSpec = new VirtualDeviceConfigSpec();
    $deviceConfigSpec->operation = 'edit';
    $deviceConfigSpec->device = new VirtualVmxnet3();
 
    foreach ($configInfo->hardware->device as $device) {
      if (get_class($device) == 'VirtualVmxnet3') {
          $deviceConfigSpec->device->key = $device->key;
          $deviceConfigSpec->device->controllerKey = $device->controllerKey;
          $deviceConfigSpec->device->unitNumber = $device->unitNumber;;
          $deviceConfigSpec->device->addressType = 'Manual';
          $deviceConfigSpec->device->macAddress = $mac;
      }
    }
 
    $configSpec = array('deviceChange' => array($deviceConfigSpec));
    $vm->ReconfigVM_Task(array('_this'=>$vm->reference, 'spec'=>$co
[/code]
Reply
0 Kudos
5 Replies
joshames
Enthusiast
Enthusiast

Ok you almost have it but you are missing a couple things:

A network adapter consists of three things:

Ethernet adapter (VirtualVmxnet3 in your case) - - you have this. 

Backing (VirtualEthernetCardNetworkBackingInfo in your case) - - you don't have this.

Connect Info (VirtualDeviceConnectInfo in your case) - - you don't have this.

So you need to include the last two objects in your vmxnet3 configuration.  You have two options to do this:

1.  Use the existing configuration.  If you just want the MAC  changed and nothing else, this is the best as it requires the least code.  Here are the locations of the two objects:

VirtualVmxnet3.Backing === This is type virtualdevicebackinginfo (VirtualEthernetCardNetworkBackingInfo)

VirtualVmxnet3.Connectable === This is type VirtualDeviceConnectInfo

So, you can just use $device->Backing and $device->Connectable for your new configurations to pull over the settings from the existing object.  Sorry if the code is wrong, I don't use php.

2.  Create new objects from scratch.  This is easy, but requires much more code and therefore, many more chances for you to make a mistake.  I have given you the two objects above and you can search for the needed properties if you want to do it this way.

That should get over your issues and solve your problem.  Let me know if you need anything else.

Josh

Reply
0 Kudos
mdvlinguest
Contributor
Contributor

I changed my code in a way that instead of creating new VirtualVmxnet3 object, assign the device object directly to deviceConfigSpec->device and just cxhange two addressType and macAddress properties. However this time, I get the following SOAP error when running the code:

Fatal error: Uncaught exception 'Vmwarephp\Exception\Soap' with message 'ServerFaultCode: . InvalidProperty: InvalidProperty Object

{

    [name] => _

}

' in /var/www/html/Vmwarephp/Service.php:74

The new code is:

code]

   $deviceConfigSpec = new VirtualDeviceConfigSpec();

    $deviceConfigSpec->operation = 'edit';

    //$deviceConfigSpec->device = new VirtualVmxnet3();

 

    foreach ($configInfo->hardware->device as $device) {

      if (get_class($device) == 'VirtualVmxnet3') {

          //$deviceConfigSpec->device->key = $device->key;

          //$deviceConfigSpec->device->controllerKey = $device->controllerKey;

          //$deviceConfigSpec->device->unitNumber = $device->unitNumber;;

          $deviceConfigSpec->device->addressType = 'Manual';

          $deviceConfigSpec->device->macAddress = $mac;

      }

    } 

 

    $configSpec = array('deviceChange' => array($deviceConfigSpec));

    $vm->ReconfigVM_Task(array('_this'=>$vm->reference, 'spec'=>$co

[/code]

Reply
0 Kudos
mdvlinguest
Contributor
Contributor

The assignment was missing in the post:

[code]

     foreach ($configInfo->hardware->device as $device) {

      if (get_class($device) == 'VirtualVmxnet3') { 

        $deviceConfigSpec->device= $device;

        ...

Reply
0 Kudos
joshames
Enthusiast
Enthusiast

Ok so let's break this down a little more.  I want you do try doing just three things:

1.  create a new vmxnet3 device and save the current configuration in this new device.  You already did that in this code you wrote:

[code]

     $deviceConfigSpec->device= $device;

[/code]

2.  ONLY change the mac type and address:

[code]

     $deviceConfigSpec->device->addressType = 'Manual';

     $deviceConfigSpec->device->macAddress = $mac;

[/code]

If you are reusing the nic and just changing the ip there is no reason to reset other properites like "key", "controller".

Try to change your script to just do these couple of things and let me know how it goes.

I am doing a very similar thing in my program except letting vSphere generate a MAC but other than using "generated" it's the same and I'm not having issues.

Let's water it down to these and see what happens.

Josh

Reply
0 Kudos
mdvlinguest
Contributor
Contributor

I am currently doing the same. Reusing the nic and just change addressType and macAddress properties but I get the following fault:

Fatal error: Uncaught exception 'Vmwarephp\Exception\Soap' with message 'ServerFaultCode: . InvalidProperty: InvalidProperty Object

{

    [name] => _

}

' in /var/www/html/Vmwarephp/Service.php:74

 

I cannot find which property is generating the error. The "_" is only available in ManagedObjectReference object which are untouched in my code.

 
Reply
0 Kudos