[Esbox-commits] r1595 - in branches/work_Fabricio: org.maemo.esbox-feature org.maemo.esbox.product-feature org.maemo.esbox.product.repository-feature org.maemo.esbox.scratchbox-feature org.maemo.esbox.source-feature org.maemo.esbox.tests-feature org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox

fabricioepa at garage.maemo.org fabricioepa at garage.maemo.org
Wed May 13 16:02:07 EEST 2009


Author: fabricioepa
Date: 2009-05-13 16:02:06 +0300 (Wed, 13 May 2009)
New Revision: 1595

Added:
   branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/TestVirtualBoxUtils.java
Modified:
   branches/work_Fabricio/org.maemo.esbox-feature/feature.xml
   branches/work_Fabricio/org.maemo.esbox.product-feature/feature.xml
   branches/work_Fabricio/org.maemo.esbox.product.repository-feature/feature.xml
   branches/work_Fabricio/org.maemo.esbox.scratchbox-feature/feature.xml
   branches/work_Fabricio/org.maemo.esbox.source-feature/feature.xml
   branches/work_Fabricio/org.maemo.esbox.tests-feature/feature.xml
   branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/AllTests.java
   branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxPreferencePage.java
   branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxUtils.java
Log:
Merging with /trunk

Modified: branches/work_Fabricio/org.maemo.esbox-feature/feature.xml
===================================================================
--- branches/work_Fabricio/org.maemo.esbox-feature/feature.xml	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox-feature/feature.xml	2009-05-13 13:02:06 UTC (rev 1595)
@@ -10,7 +10,7 @@
    </description>
 
    <copyright>
-      Copyright (c) 2007-2008 INdT, (c) 2007-2008 Nokia. All rights
+      Copyright (c) 2007-2009 INdT, (c) 2007-2009 Nokia. All rights
 reserved.
    </copyright>
 
@@ -19,7 +19,7 @@
    </license>
 
    <url>
-      <update label="Update site for ESbox project" url="http://esbox.garage.maemo.org/update"/>
+      <update label="Update site for ESbox project" url="http://esbox.garage.maemo.org/update/2.0"/>
    </url>
 
    <requires>

Modified: branches/work_Fabricio/org.maemo.esbox.product-feature/feature.xml
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.product-feature/feature.xml	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.product-feature/feature.xml	2009-05-13 13:02:06 UTC (rev 1595)
@@ -20,7 +20,7 @@
    </license>
 
    <url>
-      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update"/>
+      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update/2.0"/>
    </url>
 
    <includes

Modified: branches/work_Fabricio/org.maemo.esbox.product.repository-feature/feature.xml
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.product.repository-feature/feature.xml	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.product.repository-feature/feature.xml	2009-05-13 13:02:06 UTC (rev 1595)
@@ -5,20 +5,21 @@
       version="2.0.0.qualifier"
       provider-name="INdT / NOKIA">
 
-   <description url="http://www.example.com/description">
-      [Enter Feature Description here.]
+   <description>
+      Feature that builds the P2 repository for ESbox.
    </description>
 
-   <copyright url="http://www.example.com/copyright">
-      [Enter Copyright Description here.]
+   <copyright>
+      Copyright (c) 2009 INdT, (c) 2009 Nokia. All rights
+reserved.
    </copyright>
 
-   <license url="http://www.example.com/license">
-      [Enter License Description here.]
+   <license url="http://www.eclipse.org/legal/epl-v10.html">
+      For legal terms, see the Eclipse Public License.
    </license>
 
    <url>
-      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update"/>
+      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update/2.0"/>
    </url>
 
    <includes

Modified: branches/work_Fabricio/org.maemo.esbox.scratchbox-feature/feature.xml
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.scratchbox-feature/feature.xml	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.scratchbox-feature/feature.xml	2009-05-13 13:02:06 UTC (rev 1595)
@@ -6,15 +6,15 @@
       provider-name="INdT / Nokia">
 
    <description>
-      This feature provides support for maemo SDKs using scratchbox.
-Installations of scratchbox 1 and scratchbox 2 are supported.
-
+      This feature provides support for Maemo SDKs using scratchbox.
+Installations of Scratchbox 1 and Scratchbox 2 are supported.
 This provides project templates for Maemo C/C++ or Python projects
-as well, though it does not require those languages&apos; features to be installed.
+as well, though it does not require those languages&apos; features
+to be installed.
    </description>
 
    <copyright>
-      Copyright (c) 2007-2008 INdT, (c) 2007-2008 Nokia. All rights
+      Copyright (c) 2007-2009 INdT, (c) 2007-2009 Nokia. All rights
 reserved.
    </copyright>
 
@@ -23,7 +23,7 @@
    </license>
 
    <url>
-      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update"/>
+      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update/2.0"/>
    </url>
 
    <requires>

Modified: branches/work_Fabricio/org.maemo.esbox.source-feature/feature.xml
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.source-feature/feature.xml	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.source-feature/feature.xml	2009-05-13 13:02:06 UTC (rev 1595)
@@ -5,20 +5,21 @@
       version="2.0.0.qualifier"
       provider-name="INdT / NOKIA">
 
-   <description url="http://www.example.com/description">
-      [Enter Feature Description here.]
+   <description>
+      This feature builds the source plugins for ESbox.
    </description>
 
-   <copyright url="http://www.example.com/copyright">
-      [Enter Copyright Description here.]
+   <copyright>
+      Copyright (c) 2009 INdT, (c) 2009 Nokia. All rights
+reserved.
    </copyright>
 
-   <license url="http://www.example.com/license">
-      [Enter License Description here.]
+   <license url="http://www.eclipse.org/legal/epl-v10.html">
+      For legal terms, see the Eclipse Public License.
    </license>
 
    <url>
-      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update"/>
+      <update label="Update Site for ESbox project" url="http://esbox.garage.maemo.org/update/2.0"/>
    </url>
 
    <includes

Modified: branches/work_Fabricio/org.maemo.esbox.tests-feature/feature.xml
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.tests-feature/feature.xml	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.tests-feature/feature.xml	2009-05-13 13:02:06 UTC (rev 1595)
@@ -19,8 +19,7 @@
    </license>
 
    <url>
-      <update label="Update site for ESbox project" url="http://esbox.garage.mae
-mo.org/update"/>
+      <update label="Update site for ESbox project" url="http://esbox.garage.maemo.org/update/2.0"/>
    </url>
    <requires>
       <import plugin="org.eclipse.ui"/>

Modified: branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/AllTests.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/AllTests.java	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/AllTests.java	2009-05-13 13:02:06 UTC (rev 1595)
@@ -25,6 +25,7 @@
 		//$JUnit-BEGIN$
 		//$JUnit-END$
 		suite.addTest(new JUnit4TestAdapter(TestVMPreferences.class));
+		suite.addTest(new JUnit4TestAdapter(TestVirtualBoxUtils.class));
 		return suite;
 	}
 

Copied: branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/TestVirtualBoxUtils.java (from rev 1594, trunk/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/TestVirtualBoxUtils.java)
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/TestVirtualBoxUtils.java	                        (rev 0)
+++ branches/work_Fabricio/org.maemo.esbox.vm.tests/src/org/maemo/esbox/vm/tests/TestVirtualBoxUtils.java	2009-05-13 13:02:06 UTC (rev 1595)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Ed Swartz (Nokia) - initial API and implementation
+ *******************************************************************************/
+
+package org.maemo.esbox.vm.tests;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.maemo.esbox.internal.vm.virtualbox.VirtualBoxUtils;
+import org.maemo.esbox.internal.vm.virtualbox.VirtualBoxUtils.VBoxNetworkInterface;
+
+/**
+ * @author eswartz
+ *
+ */
+public class TestVirtualBoxUtils {
+	@Test
+	public void testNetworkInterfaces() {
+		Map<String, String> info = new HashMap<String, String>();
+		
+		info.put("NIC 1", "MAC: 080027C8E004, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps");
+		
+		VBoxNetworkInterface[] ifs = VirtualBoxUtils.getNetworkInterfaceInfo(info);
+		
+		assertEquals(1, ifs.length);
+		
+		VBoxNetworkInterface i = ifs[0];
+		assertEquals(VirtualBoxUtils.NETWORK_CONFIG_NAT, i.getNetworkType());
+		assertEquals("", i.getNetworkInterfaceName());
+		
+		////
+		
+		info.put("NIC 5", "MAC: 080027C8E004, Attachment: Host Interface 'en0: Ethernet', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps");
+		
+		ifs = VirtualBoxUtils.getNetworkInterfaceInfo(info);
+		
+		assertEquals(2, ifs.length);	// add NIC 5 at end
+		 i = ifs[1];
+		 
+		assertEquals(VirtualBoxUtils.NETWORK_CONFIG_BRIDGED, i.getNetworkType());
+		assertEquals("en0", i.getNetworkInterfaceName());
+		////
+		
+		info.put("NIC 5", "MAC: 080027E40803, Attachment: Bridged Interface 'Intel(R) PRO/1000 PL Network Connection', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps");
+		
+		ifs = VirtualBoxUtils.getNetworkInterfaceInfo(info);
+		
+		assertEquals(2, ifs.length);	// rewrote NIC 5
+		i = ifs[1];
+		
+		assertEquals(VirtualBoxUtils.NETWORK_CONFIG_BRIDGED, i.getNetworkType());
+		assertEquals("Intel(R) PRO/1000 PL Network Connection", i.getNetworkInterfaceName());
+		
+		////////
+		
+		info.put("NIC 2", "MAC: 0800001111, Attachment: Host-only Interface 'VirtualBox Host-Only Ethernet Adapter', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps");
+		
+		ifs = VirtualBoxUtils.getNetworkInterfaceInfo(info);
+		
+		assertEquals(3, ifs.length);	// added NIC 2 between 1 and 5
+		 i = ifs[1];
+		 
+		assertEquals(VirtualBoxUtils.NETWORK_CONFIG_HOST_ONLY, i.getNetworkType());
+		assertEquals("VirtualBox Host-Only Ethernet Adapter", i.getNetworkInterfaceName());
+	}
+}

Modified: branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxPreferencePage.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxPreferencePage.java	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxPreferencePage.java	2009-05-13 13:02:06 UTC (rev 1595)
@@ -17,6 +17,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jface.dialogs.DialogSettings;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.maemo.esbox.internal.api.vm.ui.preferences.AddressProvider;
@@ -27,10 +28,13 @@
 import org.maemo.esbox.internal.api.vm.ui.preferences.IVirtualMachineSettingsPreferencePage;
 import org.maemo.esbox.internal.api.vm.ui.preferences.LocalhostTargetInterfaceAddressProvider;
 import org.maemo.esbox.internal.api.vm.ui.preferences.SameSubnetHostTargetAddressConciler;
+import org.maemo.esbox.internal.vm.virtualbox.VirtualBoxUtils.VBoxNetworkInterface;
 import org.maemo.esbox.vm.core.IVirtualMachine;
 import org.maemo.esbox.vm.core.IVirtualMachineConfiguration;
 import org.maemo.esbox.vm.virtualbox.IVirtualBoxConfiguration;
 import org.maemo.mica.common.core.IProgressReporter;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.machine.NetworkUtils;
 
 /**
  * Configure VMware preferences.  This page is NOT registered at the top level
@@ -124,37 +128,99 @@
 					reporter.log(Activator.createErrorStatus("Could not find any info on the machine " + 
 							configuration.getMachineName() +"; guessing from defaults", null));
 				} else {
-				
-					boolean hasNAT = VirtualBoxUtils.machineUsesNATNetworking(machineInfo);
+					boolean detected = false;
+
+					// find the first NAT connection or a Bridged connection
+					VBoxNetworkInterface[] intfs = VirtualBoxUtils.getNetworkInterfaceInfo(machineInfo);
 					
-					if (hasNAT) {
-						int foundPorts = 0;
-						machineInfo = VirtualBoxUtils.getVirtualMachineExtraData(configuration);
-						for (Map.Entry<String, String> entry : machineInfo.entrySet()) {
-							if (entry.getKey().endsWith("guestssh/GuestPort")) {
-								hostPort = entry.getValue();
-								foundPorts++;
-							} else if (entry.getKey().endsWith("guestssh/HostPort")) {
-								targetPort = entry.getValue();
-								foundPorts++;
+					
+					for (VBoxNetworkInterface intf : intfs) {
+						if (intf.getNetworkType().equals(VirtualBoxUtils.NETWORK_CONFIG_NAT)) {
+							int foundPorts = 0;
+							machineInfo = VirtualBoxUtils.getVirtualMachineExtraData(configuration);
+							for (Map.Entry<String, String> entry : machineInfo.entrySet()) {
+								if (entry.getKey().endsWith("guestssh/GuestPort")) {
+									hostPort = entry.getValue();
+									foundPorts++;
+								} else if (entry.getKey().endsWith("guestssh/HostPort")) {
+									targetPort = entry.getValue();
+									foundPorts++;
+								}
 							}
+							
+							if (foundPorts < 2) {
+								reporter.log(Activator.createErrorStatus("Did not find all the expected NAT info; guessing from defaults", null));
+							}
+							
+							reporter.logInfo("Using NAT configuration");
+							reporter.logInfo("Setting Target Address to " + target);
+							detected = true;
+							break;
 						}
-						
-						if (foundPorts < 2) {
-							reporter.log(Activator.createErrorStatus("Did not find all the expected NAT info; guessing from defaults", null));
+					
+						if (intf.getNetworkType().equals(VirtualBoxUtils.NETWORK_CONFIG_BRIDGED)) {
+							reporter.logInfo("Using bridged networking");
+							
+							InetAddress hostAddr = null;
+							
+							try {
+								// get the host that matches the interface mentioned in the configuration
+								InetAddress[] locals = null;
+								try {
+									locals = NetworkUtils.getInterfaceAddressesNamed(intf.getNetworkInterfaceName());
+								} catch (MicaException e) {
+									reporter.log(Activator.createErrorStatus("Could not match up NIC configuration with network interfaces", e));
+								}
+								
+								if (locals != null && locals.length > 0) {
+									hostAddr = locals[0];
+								} else {
+									// fallback
+									hostAddr = InetAddress.getLocalHost();
+									reporter.log(Activator.createErrorStatus("Could not find network adapter referenced in NIC configuration; guessing", null));
+								}
+								host = hostAddr.getHostAddress();
+								
+								// assume the target address is on the same network segment
+								InetAddress targetAddr = hostAddr;
+								if (targetAddr instanceof Inet4Address) {
+									byte[] addrBytes = targetAddr.getAddress();
+									addrBytes[3] = 0;
+									targetAddr = InetAddress.getByAddress(addrBytes);
+								}
+								target = targetAddr.getHostAddress();
+								targetPort = "22";
+		
+								reporter.logInfo("Set Target Address to likely DHCP address " + targetAddr);
+								reporter.log(Activator.createStatus(IStatus.WARNING, 
+									"You will need to manually edit the Target Address after the VM boots, by inspecting the output of 'sudo dhclient3' or '/sbin/ifconfig'."));
+							} catch (UnknownHostException e) {
+								reporter.log(Activator.createErrorStatus(
+										"Could not guess the LAN address",
+										e));							
+							}
+							
+							detected = true;
+							break;
 						}
 					}
+					
+					if (!detected) {
+						reporter.log(Activator.createErrorStatus(
+								"The machine either has no networking configured or none of the interfaces is appropriate for ESbox; please use NAT or Bridged/Host Interface networking.  Guessing from defaults...",
+								null));	
+					}
+					
 				}
 				
+				
 				try {
 					commonPrefPage.getSSHTargetAddr().setAddress(
 							InetAddress.getByName(target));
-					reporter.logInfo("Setting Target Address to " + target);
 				} catch (UnknownHostException e) {
-					reporter.log(Activator.createErrorStatus("Failed to create stock " + target + "address", e));
+					reporter.log(Activator.createErrorStatus("Failed to create " + target + "address", e));
 				}
 				
-				
 				commonPrefPage.getSSHTargetPort().setStringValue(targetPort);
 				reporter.logInfo("Setting SSH Target Port to " + targetPort);
 				
@@ -166,7 +232,7 @@
 							InetAddress.getByName(host));
 					reporter.logInfo("Setting Host Address to " + host);
 				} catch (UnknownHostException e) {
-					reporter.log(Activator.createErrorStatus("Failed to create stock " + host + " address", e));
+					reporter.log(Activator.createErrorStatus("Failed to create " + host + " address", e));
 				}
 			}
 

Modified: branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxUtils.java
===================================================================
--- branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxUtils.java	2009-05-13 12:44:17 UTC (rev 1594)
+++ branches/work_Fabricio/org.maemo.esbox.vm.virtualbox/src/org/maemo/esbox/internal/vm/virtualbox/VirtualBoxUtils.java	2009-05-13 13:02:06 UTC (rev 1595)
@@ -11,6 +11,7 @@
 
 package org.maemo.esbox.internal.vm.virtualbox;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -40,8 +41,16 @@
 	static final Pattern namePattern = Pattern.compile("Name:\\s*(.*)");
 	static final Pattern nameUUID22Pattern = Pattern.compile("\"([^\"]+)\"\\s*\\{(.*)\\}");
 	static final Pattern uuidPattern = Pattern.compile("UUID:\\s*([0-9a-fA-F-]{36})");
-	static final Pattern keyValuePattern = Pattern.compile("(.+):\\s*(.+)");
+	static final Pattern keyValuePattern = Pattern.compile("([^:]+):\\s*(.+)");
 	static final Pattern extradataPattern = Pattern.compile("Key:\\s*(.+),\\s*Value:\\s*(.+)");
+	public static final String NETWORK_CONFIG_NAT = "NAT";
+	public static final String NETWORK_CONFIG_BRIDGED = "bridged";
+	public static final String NETWORK_CONFIG_HOST_ONLY = "host-only";
+	
+	final static Pattern nicAttachmentPattern = Pattern.compile(".*Attachment:\\s*(([^,]+)('[^']+')?),?.*");
+	// "bridged" was called "Host Interface" before 2.2
+	final static Pattern nicBridgedPattern = Pattern.compile("(?:Bridged|Host Interface)[^']*'([^']*)'");
+	final static Pattern nicHostOnlyPattern = Pattern.compile("(?:Host-only)[^']*'([^']*)'");
 
 	
 	/**
@@ -203,30 +212,84 @@
 		
 		return info;
 	}
+	
+	static public class VBoxNetworkInterface {
+		private String networkType;
+		private String networkInterfaceName;
+		public VBoxNetworkInterface(String networkType, String networkInterfaceName) {
+			this.networkType = networkType;
+			this.networkInterfaceName = networkInterfaceName;
+		}
+		public String getNetworkType() {
+			return networkType;
+		}
+		public String getNetworkInterfaceName() {
+			return networkInterfaceName;
+		}
+	}
+	
 	/**
-	 * Tell if the machine appears to use NAT.
-	 * @param hasNAT
+	 * Get the information about configured network interfaces.
 	 * @param machineInfo
-	 * @return
+	 * @return non-<code>null</code> array
 	 */
-	public static boolean machineUsesNATNetworking(Map<String, String> machineInfo) {
-		boolean hasNAT = false;
-		Pattern nicAttachmentPattern = Pattern.compile(".*Attachment:\\s*(.+),?");
+	public static VBoxNetworkInterface[] getNetworkInterfaceInfo(Map<String, String> machineInfo) {
+		List<VBoxNetworkInterface> ifs = new ArrayList<VBoxNetworkInterface>();
 		
-		for (String key : new String[] { "NIC 1", "NIC 2", "NIC 3", "NIC 4" }) {
+		for (int inum = 1; inum <= 8; inum++) {
+			String key = "NIC " + inum;
 			String nicInfo = machineInfo.get(key);
 			if (nicInfo != null) {
+				
 				Matcher matcher = nicAttachmentPattern.matcher(nicInfo);
-				if (matcher.matches() && matcher.group(1).equals("NAT")) {
-					hasNAT = true;
-					break;
+				if (matcher.matches()) {
+					String attachment = matcher.group(1);
+					if (attachment.equals("NAT")) {
+						ifs.add(new VBoxNetworkInterface(NETWORK_CONFIG_NAT, ""));
+						continue;
+					}
+					
+					Matcher matcher2 = nicBridgedPattern.matcher(attachment);
+					if (matcher2.matches()) {
+						String ifaceName = matcher2.group(1);
+						int idx = ifaceName.indexOf(':');
+						if (idx > 0)
+							ifaceName = ifaceName.substring(0, idx);
+						ifs.add(new VBoxNetworkInterface(NETWORK_CONFIG_BRIDGED, ifaceName));
+						continue;
+					} 
+					
+					matcher2 = nicHostOnlyPattern.matcher(attachment);
+					if (matcher2.matches()) {
+						String ifaceName = matcher2.group(1);
+						int idx = ifaceName.indexOf(':');
+						if (idx > 0)
+							ifaceName = ifaceName.substring(0, idx);
+						ifs.add(new VBoxNetworkInterface(NETWORK_CONFIG_HOST_ONLY, ifaceName));
+						continue;
+					} 
 				}
 			}
 		}
-		return hasNAT;
+		return (VBoxNetworkInterface[]) ifs.toArray(new VBoxNetworkInterface[ifs.size()]);
 	}
 
 	/**
+	 * Tell if the machine appears to use NAT.
+	 * @param hasNAT
+	 * @param machineInfo
+	 * @return
+	 */
+	public static boolean machineUsesNATNetworking(Map<String, String> machineInfo) {
+		VBoxNetworkInterface[] ifs = getNetworkInterfaceInfo(machineInfo);
+		for (VBoxNetworkInterface intf : ifs) {
+			if (intf.getNetworkType().equals(NETWORK_CONFIG_NAT))
+				return true;
+		}
+		return false;
+	}
+
+	/**
 	 * Get the list of registered VMs
 	 * @return collection of human-readable names
 	 */



More information about the Esbox-commits mailing list