summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2021-06-29 11:54:33 +0200
committerManuel Bentele2021-06-29 11:54:33 +0200
commit4ce45a197588abfdfccfba4348b853f77dea442e (patch)
tree6b236465d81cc5f2b261357b7437e065169c88e3
parentFix usage of Enum ContainerImageType (diff)
downloadmaster-sync-shared-4ce45a197588abfdfccfba4348b853f77dea442e.tar.gz
master-sync-shared-4ce45a197588abfdfccfba4348b853f77dea442e.tar.xz
master-sync-shared-4ce45a197588abfdfccfba4348b853f77dea442e.zip
Fix handling of multiple VirtualBox network adapters
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java53
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java4
2 files changed, 50 insertions, 7 deletions
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
index 6922c8c..4715daf 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
@@ -117,10 +117,34 @@ public class VirtualizationConfigurationVirtualBox
}
}
+ private void disableEnhancedNetworkAdapters()
+ {
+ final NodeList disableAdapters = this.config.findNodes( "/VirtualBox/Machine/Hardware/Network/Adapter[not(@slot='0')]" );
+
+ if ( disableAdapters != null ) {
+ for ( int i = 0; i < disableAdapters.getLength(); i++ ) {
+ final Element disableAdapter = (Element)disableAdapters.item( i );
+ disableAdapter.setAttribute( "enabled", "false" );
+ }
+ }
+ }
+
+ private void removeEnhancedNetworkAdapters()
+ {
+ final NodeList removeAdapters = this.config.findNodes( "/VirtualBox/Machine/Hardware/Network/Adapter[not(@slot='0')]" );
+
+ if ( removeAdapters != null ) {
+ for ( int i = 0; i < removeAdapters.getLength(); i++ ) {
+ final Node removeAdapter = removeAdapters.item( i );
+ removeAdapter.getParentNode().removeChild( removeAdapter );
+ }
+ }
+ }
+
@Override
public void transformEditable() throws VirtualizationConfigurationException
{
- // TODO Auto-generated method stub
+ this.disableEnhancedNetworkAdapters();
}
@Override
@@ -201,11 +225,28 @@ public class VirtualizationConfigurationVirtualBox
@Override
public boolean addDefaultNat()
{
- if ( config.addNewNode( "/VirtualBox/Machine/Hardware/Network/Adapter", "NAT" ) == null ) {
- LOGGER.error( "Failed to set network adapter to NAT." );
- return false;
+ final boolean status;
+
+ final Node adapterSlot0 = config.findNodes( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='0']" ).item( 0 );
+ if ( adapterSlot0 != null ) {
+ // remove all child node to wipe existing networking mode
+ final NodeList adapterSlot0SettingNodes = adapterSlot0.getChildNodes();
+ while ( adapterSlot0.getChildNodes().getLength() > 0 ) {
+ adapterSlot0.removeChild( adapterSlot0SettingNodes.item( 0 ) );
+ }
+
+ // add networking mode 'NAT'
+ if ( config.addNewNode( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='0']", "NAT" ) == null ) {
+ LOGGER.error( "Failed to set network adapter to NAT." );
+ status = false;
+ } else {
+ status = config.changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='0']", "MACAddress", "080027B86D12" );
+ }
+ } else {
+ status = false;
}
- return config.changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter", "MACAddress", "080027B86D12" );
+
+ return status;
}
@Override
@@ -496,6 +537,8 @@ public class VirtualizationConfigurationVirtualBox
config.setExtraData( "GUI/PreventSnapshotOperations", "true" );
config.setExtraData( "GUI/PreventApplicationUpdate", "true" );
config.setExtraData( "GUI/RestrictedCloseActions", "SaveState,PowerOffRestoringSnapshot,Detach" );
+
+ this.removeEnhancedNetworkAdapters();
}
@Override
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
index b1c940a..b2dcd48 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
@@ -80,7 +80,7 @@ public class VirtualizationConfigurationVirtualboxFileFormat
"/VirtualBox/Machine/Hardware/HID",
"/VirtualBox/Machine/Hardware/LPT",
"/VirtualBox/Machine/Hardware/SharedFolders",
- "/VirtualBox/Machine/Hardware/Network/Adapter[@enabled='true']/*",
+ "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='0']/*",
"/VirtualBox/Machine/ExtraData",
"/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice[not(@type='HardDisk')]",
"/VirtualBox/Machine/Hardware/StorageControllers/StorageController/AttachedDevice[not(@type='HardDisk')]",
@@ -343,7 +343,7 @@ public class VirtualizationConfigurationVirtualboxFileFormat
changeAttribute( "/VirtualBox/Machine/Hardware/CPU", "count", PlaceHolder.CPU.toString() );
// placeholder for the MACAddress
- changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter", "MACAddress", PlaceHolder.NETWORKMAC.toString() );
+ changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='0']", "MACAddress", PlaceHolder.NETWORKMAC.toString() );
NodeList hdds = findNodes( "/VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk" );
for ( int i = 0; i < hdds.getLength(); i++ ) {