diff options
author | Victor Mocanu | 2017-10-09 12:40:08 +0200 |
---|---|---|
committer | Victor Mocanu | 2017-10-09 12:40:08 +0200 |
commit | 32bfb4c81b026522781c8e3cfd31b3f37565461a (patch) | |
tree | 75ec7d75c79c1b1ab218674a68bd4c4e3fa04161 /src/main/java/org/openslx/util/vm/VboxMetaData.java | |
parent | [VBox] improved the way the new uuid is written in the vdi file (diff) | |
download | master-sync-shared-32bfb4c81b026522781c8e3cfd31b3f37565461a.tar.gz master-sync-shared-32bfb4c81b026522781c8e3cfd31b3f37565461a.tar.xz master-sync-shared-32bfb4c81b026522781c8e3cfd31b3f37565461a.zip |
[VBox] improved download part
the getInstance of the VmMetaData class now delivers the right type of object
the DiskImage class needs a way to return the type of image
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VboxMetaData.java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxMetaData.java | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index 44a2179..5115248 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -110,63 +110,34 @@ public class VboxMetaData extends VmMetaData String diskImagePath = diskImage.getName(); config.changeAttribute( "HardDisk", "location", diskImagePath ); - UUID newuuid = UUID.randomUUID(); - LOGGER.debug( newuuid ); + UUID newhdduuid = UUID.randomUUID(); + LOGGER.debug( newhdduuid ); // patching the new uuid in the vbox config file here - String vboxUUid = "{" + newuuid.toString() + "}"; + String vboxUUid = "{" + newhdduuid.toString() + "}"; config.changeAttribute( "HardDisk", "uuid", vboxUUid ); config.changeAttribute( "Image", "uuid", vboxUUid ); - /*Long longl = newuuid.getLeastSignificantBits(); - Long longr = newuuid.getMostSignificantBits();*/ - - // TODO test this + // write the new hdd uuid in the vdi file byte[] bytesToWrite = new byte[ 16 ]; - int[] numberOfBytes = {32, 40, 48, 56, 16, 24, 0, 8, 56, 48, 40, 32, 24, 16, 8, 0}; + 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++) { Long uuidlong = null; if ( i == 0 ) { - uuidlong = newuuid.getMostSignificantBits(); + uuidlong = newhdduuid.getMostSignificantBits(); } else { - uuidlong = newuuid.getLeastSignificantBits(); + uuidlong = newhdduuid.getLeastSignificantBits(); } for ( int j = 0; j < 8; j++) { int index = j + offset; - bytesToWrite[index] = (byte) (uuidlong >>> numberOfBytes[index]); + bytesToWrite[index] = (byte) (uuidlong >>> bytesOffset[index]); } offset = 8; } - - - /* - byte l56 = (byte) (longl >>> 56); - byte l48 = (byte) (longl >>> 48); - byte l40 = (byte) (longl >>> 40); - byte l32 = (byte) (longl >>> 32); - byte l24 = (byte) (longl >>> 24); - byte l16 = (byte) (longl >>> 16); - byte l8 = (byte) (longl >>> 8); - byte l0 = (byte) (longl >>> 0); - - // switcharoo next 4 - byte r56 = (byte) (longr >>> 32); - byte r48 = (byte) (longr >>> 40); - byte r40 = (byte) (longr >>> 48); - byte r32 = (byte) (longr >>> 56); - // switcharoo next 2 - byte r24 = (byte) (longr >>> 16); - byte r16 = (byte) (longr >>> 24); - // switcharoo next 2 - byte r8 = (byte) (longr >>> 0); - byte r0 = (byte) (longr >>> 8); - - byte[] bytesToWrite = {r56, r48, r40, r32, r24, r16, r8, r0, l56, l48, l40, l32, l24, l16, l8, l0}; */ - try ( RandomAccessFile file = new RandomAccessFile( diskImage, "rw" ) ) { file.seek( 392 ); @@ -174,6 +145,15 @@ public class VboxMetaData extends VmMetaData } 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" ); + newMachineUuid = UUID.randomUUID(); + } + String machineUUid = "{" + newMachineUuid.toString() + "}"; + config.changeAttribute( "Machine", "uuid", machineUUid ); return true; } @@ -237,4 +217,11 @@ public class VboxMetaData extends VmMetaData { typeOf = TypeOf.VBOX; } + + @Override + public boolean addCpuCoreCount( int nrOfCores ) + { + config.changeAttribute( "CPU", "count", "1" ); + return true; + } } |