Page 1 of 1

SDK issue getting the mac address of machine

Posted: 4. Jul 2010, 04:02
by athanazio
Hello all,
I'm doing an application where I need to get some data of the current machines running in a host.
but for any reason the mac address that I get from the SDK call is not correct.

here is the code that Im using to get the mac

Code: Select all

	public VirtualMachineVO[] getVMs() {

		VirtualMachineVO[] result = new VirtualMachineVO[0];

		try {

			// Call IVirtualBox::getMachines, which yields an array
			// of managed object references to all machines which have
			// been registered:
			String[] aMachines = _port.IVirtualBox_getMachines(_oVbox);
			result = new VirtualMachineVO[aMachines.length];

			for (int i = 0; i < aMachines.length; i++) {
				String oMachine = aMachines[i];
				String machinename = _port.IMachine_getHardwareUUID(oMachine);

				UnsignedInt slot = new UnsignedInt(1);
				String netWorkAdapter = _port.IMachine_getNetworkAdapter(oMachine, slot);
				logger.debug("netWorkAdapter: " + netWorkAdapter);
				String macaddress = _port.INetworkAdapter_getMACAddress(netWorkAdapter);
				logger.debug("macaddress: " + macaddress);

				UnsignedInt memorySize = _port.IMachine_getMemorySize(oMachine);

				logger.debug("Machine " + i + ": " + oMachine + " - " + machinename + " mac=" + macaddress);
				result[i] = new VirtualMachineVO();
				result[i].setUuid(machinename);
				result[i].setMacaddress(macaddress);
				result[i].setMemorySize(memorySize.intValue());
				result[i].setStatus( _port.IMachine_getState(oMachine).getValue());

				// release managed object reference
				_port.IManagedObjectRef_release(oMachine);
			}
		} catch (Exception e) {
			logger.error("getVMs()", e);
		}

		return result;
	}
even after I set the mac address fixed, like this
fixed_macaddress_setup_in_virtualbox.jpg
fixed_macaddress_setup_in_virtualbox.jpg (47.93 KiB) Viewed 853 times
and can get the correct mac address in the machine
fixed_macaddress_setup_in_virtualbox.jpg
fixed_macaddress_setup_in_virtualbox.jpg (47.93 KiB) Viewed 853 times
I still get the following list of data from the call

Code: Select all

[{"uuid":"9e161cb5-cc58-44dc-9b88-a2f0b70ed0ff","macaddress":"08002794F850","memorySize":768,"status":"Saved"},
{"uuid":"6decd679-d6ef-4445-9b23-9a989774f005","macaddress":"0800278051E8","memorySize":796,"status":"PoweredOff"},
{"uuid":"442d9002-a4ee-4884-8ccb-b3fa6a6b6269","macaddress":"0800277DF164","memorySize":1024,"status":"Saved"},
{"uuid":"b5fa6910-3b45-4666-8486-5d2109e46e41","macaddress":"080027E55D31","memorySize":128,"status":"Running"}]
where the machine that I changed the mac is the one with 128 of memory
{"uuid":"b5fa6910-3b45-4666-8486-5d2109e46e41","macaddress":"080027E55D31","memorySize":128,"status":"Running"}

note the wrong Mac address ... :shock:

any ideas ?

Re: SDK issue getting the mac address of machine

Posted: 4. Jul 2010, 04:09
by athanazio
hahahaha,
that was easy ! the force is with this forum !!
just after posting the issue, one idea come to me, what if the slot number is incorrect ?

and ...

changed from

Code: Select all

UnsignedInt slot = new UnsignedInt(1);
to

Code: Select all

UnsignedInt slot = new UnsignedInt(0);
and guess what ?? returned the correct data !! so my understanding is that, even if the slots are empty in the virtual machine, you can read trash information from it ...

the correct data
[{"uuid":"9e161cb5-cc58-44dc-9b88-a2f0b70ed0ff","macaddress":"0800271DD588","memorySize":768,"status":"Saved"},{"uuid":"6decd679-d6ef-4445-9b23-9a989774f005","macaddress":"0800279901AE","memorySize":796,"status":"PoweredOff"},{"uuid":"442d9002-a4ee-4884-8ccb-b3fa6a6b6269","macaddress":"080027F08DDE","memorySize":1024,"status":"Saved"},{"uuid":"b5fa6910-3b45-4666-8486-5d2109e46e41","macaddress":"000000000001","memorySize":128,"status":"Running"}]

I hope this helps somebody :)