summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VboxMetaData.java
diff options
context:
space:
mode:
authorJonathan Bauer2017-10-24 12:49:14 +0200
committerJonathan Bauer2017-10-24 12:49:14 +0200
commit2e5ca3f6fd81233ea0c07ea99ae5bf8765e1eabe (patch)
treef198a5a913ccf44da7f4f1b022e6485331f61399 /src/main/java/org/openslx/util/vm/VboxMetaData.java
parentMerge branch 'vbox' of git.openslx.org:bwlp/master-sync-shared into vbox (diff)
downloadmaster-sync-shared-2e5ca3f6fd81233ea0c07ea99ae5bf8765e1eabe.tar.gz
master-sync-shared-2e5ca3f6fd81233ea0c07ea99ae5bf8765e1eabe.tar.xz
master-sync-shared-2e5ca3f6fd81233ea0c07ea99ae5bf8765e1eabe.zip
fix code formatting
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VboxMetaData.java')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxMetaData.java139
1 files changed, 79 insertions, 60 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java
index 9ea59d2..fc34ee1 100644
--- a/src/main/java/org/openslx/util/vm/VboxMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java
@@ -19,186 +19,205 @@ import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
-public class VboxMetaData extends VmMetaData {
+public class VboxMetaData extends VmMetaData
+{
- private static final Logger LOGGER = Logger.getLogger(VboxMetaData.class);
+ private static final Logger LOGGER = Logger.getLogger( VboxMetaData.class );
- private static final Virtualizer virtualizer = new Virtualizer("virtualbox", "VirtualBox");
+ private static final Virtualizer virtualizer = new Virtualizer( "virtualbox", "VirtualBox" );
private final VboxConfig config;
- public VboxMetaData(List<OperatingSystem> osList, File file)
- throws IOException, UnsupportedVirtualizerFormatException {
+ public VboxMetaData( List<OperatingSystem> osList, File file )
+ throws IOException, UnsupportedVirtualizerFormatException
+ {
- super(osList);
- this.config = new VboxConfig(file);
+ super( osList );
+ this.config = new VboxConfig( file );
init();
}
- public VboxMetaData(List<OperatingSystem> osList, byte[] vmContent, int length)
- throws IOException, UnsupportedVirtualizerFormatException {
+ public VboxMetaData( List<OperatingSystem> osList, byte[] vmContent, int length )
+ throws IOException, UnsupportedVirtualizerFormatException
+ {
- super(osList);
- this.config = new VboxConfig(vmContent, length);
+ super( osList );
+ this.config = new VboxConfig( vmContent, length );
init();
}
- private void init() {
+ private void init()
+ {
this.config.init();
displayName = config.getDisplayName();
- setOs("virtualbox", config.getOsName());
+ setOs( "virtualbox", config.getOsName() );
- for (HardDisk hardDisk : config.getHdds()) {
- hdds.add(hardDisk);
+ for ( HardDisk hardDisk : config.getHdds() ) {
+ hdds.add( hardDisk );
}
// DEBUG Code???? mark such code please!
try {
- addFloppy(0, null, true);
+ addFloppy( 0, null, true );
WriteToFile();
- } catch (TransformerFactoryConfigurationError | TransformerException e) {
+ } catch ( TransformerFactoryConfigurationError | TransformerException e ) {
// WriteToFile exceptions here...not important for the the LOGGER
e.printStackTrace();
}
}
// --TODO will be needed later again
- private void WriteToFile() throws TransformerFactoryConfigurationError, TransformerException {
+ private void WriteToFile() throws TransformerFactoryConfigurationError, TransformerException
+ {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
- StreamResult output = new StreamResult(new File("output.xml"));
- Source input = new DOMSource(config.getConfigDoc());
- transformer.transform(input, output);
+ StreamResult output = new StreamResult( new File( "output.xml" ) );
+ Source input = new DOMSource( config.getConfigDoc() );
+ transformer.transform( input, output );
}
@Override
- public Virtualizer getVirtualizer() {
+ public Virtualizer getVirtualizer()
+ {
return virtualizer;
}
@Override
- public void enableUsb(boolean enabled) {
+ public void enableUsb( boolean enabled )
+ {
// TODO Auto-generated method stub
}
@Override
- public void applySettingsForLocalEdit() {
+ public void applySettingsForLocalEdit()
+ {
// TODO Auto-generated method stub
}
@Override
- public byte[] getFilteredDefinitionArray() {
- return config.toString().getBytes(StandardCharsets.UTF_8);
+ public byte[] getFilteredDefinitionArray()
+ {
+ return config.toString().getBytes( StandardCharsets.UTF_8 );
}
@Override
- public boolean addHddTemplate(String diskImage, String hddMode, String redoDir) {
- config.changeAttribute("HardDisk", "location", diskImage);
+ public boolean addHddTemplate( String diskImage, String hddMode, String redoDir )
+ {
+ config.changeAttribute( "HardDisk", "location", diskImage );
return true;
}
@Override
- public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) {
+ public boolean addHddTemplate( File diskImage, String hddMode, String redoDir )
+ {
String diskImagePath = diskImage.getName();
- config.changeAttribute("HardDisk", "location", diskImagePath);
+ config.changeAttribute( "HardDisk", "location", diskImagePath );
UUID newhdduuid = UUID.randomUUID();
- LOGGER.debug(newhdduuid);
+ LOGGER.debug( newhdduuid );
// patching the new uuid in the vbox config file here
String vboxUUid = "{" + newhdduuid.toString() + "}";
- config.changeAttribute("HardDisk", "uuid", vboxUUid);
- config.changeAttribute("Image", "uuid", vboxUUid);
+ config.changeAttribute( "HardDisk", "uuid", vboxUUid );
+ config.changeAttribute( "Image", "uuid", vboxUUid );
// write the new hdd uuid in the vdi file
- byte[] bytesToWrite = new byte[16];
+ byte[] bytesToWrite = new byte[ 16 ];
int[] bytesOffset = { 32, 40, 48, 56, 16, 24, 0, 8, 56, 48, 40, 32, 24, 16, 8, 0 };
int offset = 0;
- for (int i = 0; i < 2; i++) {
+ for ( int i = 0; i < 2; i++ ) {
Long uuidlong = null;
- if (i == 0) {
+ if ( i == 0 ) {
uuidlong = newhdduuid.getMostSignificantBits();
} else {
uuidlong = newhdduuid.getLeastSignificantBits();
}
- for (int j = 0; j < 8; j++) {
+ for ( int j = 0; j < 8; j++ ) {
int index = j + offset;
- bytesToWrite[index] = (byte) (uuidlong >>> bytesOffset[index]);
+ bytesToWrite[index] = (byte) ( uuidlong >>> bytesOffset[index] );
}
offset = 8;
}
- try (RandomAccessFile file = new RandomAccessFile(diskImage, "rw")) {
+ try ( RandomAccessFile file = new RandomAccessFile( diskImage, "rw" ) ) {
- file.seek(392);
- file.write(bytesToWrite, 0, 16);
- } catch (Exception e) {
- LOGGER.warn("could not patch new uuid in the vdi", e);
+ file.seek( 392 );
+ file.write( bytesToWrite, 0, 16 );
+ } catch ( Exception e ) {
+ LOGGER.warn( "could not patch new uuid in the vdi", e );
}
// we need a new machine uuid
UUID newMachineUuid = UUID.randomUUID();
- if (newMachineUuid.equals(newhdduuid)) {
- LOGGER.warn("The new Machine UUID is the same as the new HDD UUID; tying again...this vm might not start");
+ if ( newMachineUuid.equals( newhdduuid ) ) {
+ LOGGER.warn( "The new Machine UUID is the same as the new HDD UUID; tying again...this vm might not start" );
newMachineUuid = UUID.randomUUID();
}
String machineUUid = "{" + newMachineUuid.toString() + "}";
- config.changeAttribute("Machine", "uuid", machineUUid);
+ config.changeAttribute( "Machine", "uuid", machineUUid );
return true;
}
@Override
- public boolean addDefaultNat() {
- config.addNewNode("Adapter", "NAT", false);
+ public boolean addDefaultNat()
+ {
+ config.addNewNode( "Adapter", "NAT", false );
return true;
}
- public void reWrite() {
+ public void reWrite()
+ {
try {
WriteToFile();
- } catch (TransformerFactoryConfigurationError | TransformerException e) {
+ } catch ( TransformerFactoryConfigurationError | TransformerException e ) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
- public void setOs(String vendorOsId) {
+ public void setOs( String vendorOsId )
+ {
// TODO Auto-generated method stub
}
@Override
- public boolean addDisplayName(String name) {
- config.changeAttribute("Machine", "name", name);
+ public boolean addDisplayName( String name )
+ {
+ config.changeAttribute( "Machine", "name", name );
return true;
}
@Override
- public boolean addRam(int mem) {
- config.changeAttribute("Memory", "RAMSize", Integer.toString(mem));
+ public boolean addRam( int mem )
+ {
+ config.changeAttribute( "Memory", "RAMSize", Integer.toString( mem ) );
return true;
}
@Override
- public void addFloppy(int index, String image, boolean readOnly) {
+ public void addFloppy( int index, String image, boolean readOnly )
+ {
- if (image == null) {
+ if ( image == null ) {
} else {
}
}
@Override
- public boolean addCdrom(String image) {
+ public boolean addCdrom( String image )
+ {
// TODO Auto-generated method stub
return false;
}
@Override
- public boolean addCpuCoreCount(int nrOfCores) {
- config.changeAttribute("CPU", "count", "1");
+ public boolean addCpuCoreCount( int nrOfCores )
+ {
+ config.changeAttribute( "CPU", "count", "1" );
return true;
}
}