summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VmMetaData.java
diff options
context:
space:
mode:
authorJonathan Bauer2017-10-20 17:48:24 +0200
committerJonathan Bauer2017-10-20 17:48:24 +0200
commit17a212b54f42c46f203abbbcea61a80d6f40df61 (patch)
tree338659b194a09c377cdce914719b741a285b7ea7 /src/main/java/org/openslx/util/vm/VmMetaData.java
parent[VBox] improved download part (diff)
downloadmaster-sync-shared-17a212b54f42c46f203abbbcea61a80d6f40df61.tar.gz
master-sync-shared-17a212b54f42c46f203abbbcea61a80d6f40df61.tar.xz
master-sync-shared-17a212b54f42c46f203abbbcea61a80d6f40df61.zip
formatting & first round of cleanup
removed typeOf, use instanceof
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VmMetaData.java')
-rw-r--r--src/main/java/org/openslx/util/vm/VmMetaData.java159
1 files changed, 63 insertions, 96 deletions
diff --git a/src/main/java/org/openslx/util/vm/VmMetaData.java b/src/main/java/org/openslx/util/vm/VmMetaData.java
index 200aef9..dc93dc9 100644
--- a/src/main/java/org/openslx/util/vm/VmMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VmMetaData.java
@@ -13,39 +13,25 @@ import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.Virtualizer;
/**
- * Describes a configured virtual machine. This class is parsed from a machine description, like a
- * *.vmx for VMware machines.
+ * Describes a configured virtual machine. This class is parsed from a machine
+ * description, like a *.vmx for VMware machines.
*/
-public abstract class VmMetaData
-{
- private static final Logger LOGGER = Logger.getLogger( VmMetaData.class );
+public abstract class VmMetaData {
+ private static final Logger LOGGER = Logger.getLogger(VmMetaData.class);
/*
* Helper types
*/
- public static enum TypeOf
- {
- VMX,
- VBOX;
+ public static enum DriveBusType {
+ SCSI, IDE, SATA;
}
- public static TypeOf typeOf = null;
-
- public static enum DriveBusType
- {
- SCSI,
- IDE,
- SATA;
- }
-
- public static class HardDisk
- {
+ public static class HardDisk {
public final String chipsetDriver;
public final DriveBusType bus;
public final String diskImage;
- public HardDisk( String chipsetDriver, DriveBusType bus, String diskImage )
- {
+ public HardDisk(String chipsetDriver, DriveBusType bus, String diskImage) {
this.chipsetDriver = chipsetDriver;
this.bus = bus;
this.diskImage = diskImage;
@@ -70,67 +56,64 @@ public abstract class VmMetaData
/**
* Get operating system of this VM.
*/
- public OperatingSystem getOs()
- {
+ public OperatingSystem getOs() {
return os;
}
/**
* Get all hard disks of this VM.
*/
- public List<HardDisk> getHdds()
- {
- return Collections.unmodifiableList( hdds );
+ public List<HardDisk> getHdds() {
+ return Collections.unmodifiableList(hdds);
}
/**
* Get display name of VM.
*/
- public String getDisplayName()
- {
+ public String getDisplayName() {
return displayName;
}
/**
- * This method should return a minimal representation of the input meta data. The representation
- * is platform dependent, and should be stripped of all non-essential configuration, such as
- * CD/DVD/FLoppy drives, serial or parallel ports, shared folders, or anything else that could be
- * considered sensible information (absolute paths containing the local user's name).
+ * This method should return a minimal representation of the input meta data.
+ * The representation is platform dependent, and should be stripped of all
+ * non-essential configuration, such as CD/DVD/FLoppy drives, serial or parallel
+ * ports, shared folders, or anything else that could be considered sensible
+ * information (absolute paths containing the local user's name).
*/
public abstract byte[] getFilteredDefinitionArray();
- public final ByteBuffer getFilteredDefinition()
- {
- return ByteBuffer.wrap( getFilteredDefinitionArray() );
+ public final ByteBuffer getFilteredDefinition() {
+ return ByteBuffer.wrap(getFilteredDefinitionArray());
}
/*
* Methods
*/
- public VmMetaData( List<OperatingSystem> osList )
- {
+ public VmMetaData(List<OperatingSystem> osList) {
this.osList = osList;
}
/**
- * Called from subclass to set the OS. If the OS cannot be determined from the given parameters,
- * it will not be set.
+ * Called from subclass to set the OS. If the OS cannot be determined from the
+ * given parameters, it will not be set.
*
- * @param virtId virtualizer, eg "vmware" for VMware
- * @param virtOsId the os identifier used by the virtualizer, eg. windows7-64 for 64bit Windows 7
- * on VMware
+ * @param virtId
+ * virtualizer, eg "vmware" for VMware
+ * @param virtOsId
+ * the os identifier used by the virtualizer, eg. windows7-64 for
+ * 64bit Windows 7 on VMware
*/
- protected final void setOs( String virtId, String virtOsId )
- {
+ protected final void setOs(String virtId, String virtOsId) {
OperatingSystem lazyMatch = null;
- for ( OperatingSystem os : osList ) {
- if ( os.getVirtualizerOsId() == null )
+ for (OperatingSystem os : osList) {
+ if (os.getVirtualizerOsId() == null)
continue;
- for ( Entry<String, String> entry : os.getVirtualizerOsId().entrySet() ) {
- if ( !entry.getValue().equals( virtOsId ) )
+ for (Entry<String, String> entry : os.getVirtualizerOsId().entrySet()) {
+ if (!entry.getValue().equals(virtOsId))
continue;
- if ( entry.getKey().equals( virtId ) ) {
+ if (entry.getKey().equals(virtId)) {
this.os = os;
return;
} else {
@@ -145,79 +128,63 @@ public abstract class VmMetaData
public abstract Virtualizer getVirtualizer();
- public abstract void enableUsb( boolean enabled );
+ public abstract void enableUsb(boolean enabled);
/**
- * Apply config options that are desired when locally editing a VM.
- * for vmware, this disables automatic DPI scaling of the guest.
+ * Apply config options that are desired when locally editing a VM. for vmware,
+ * this disables automatic DPI scaling of the guest.
*/
public abstract void applySettingsForLocalEdit();
// meta object needed when reading vm from file
- public static VmMetaData getInstance( List<OperatingSystem> osList, File file ) throws IOException
- {
-
- VmMetaData meta = null;
+ public static VmMetaData getInstance(List<OperatingSystem> osList, File file) throws IOException {
try {
- meta = new VmwareMetaData( osList, file );
- } catch ( UnsupportedVirtualizerFormatException e ) {
- LOGGER.debug( "datei war nicht .vmx; versuche mit VBox" );
- try {
- meta = new VboxMetaData( osList, file );
- } catch ( UnsupportedVirtualizerFormatException ex ) {
- LOGGER.debug( "datei war nicht .vbox; unterbrochen!", ex );
- // TODO ok so or throw new IOException?
- }
+ return new VmwareMetaData(osList, file);
+ } catch (UnsupportedVirtualizerFormatException e) {
+ LOGGER.debug("Disk file not .vmdk");
}
- if ( meta != null ) {
- return meta;
+ try {
+ return new VboxMetaData(osList, file);
+ } catch (UnsupportedVirtualizerFormatException e) {
+ LOGGER.debug("Disk file not .vdi");
}
+ LOGGER.error("Unsupported disk file format!");
return null;
}
// meta object needed when reading from configarray
- public static VmMetaData getInstance( List<OperatingSystem> osList, byte[] vmContent, int length ) throws IOException
- {
-
- VmMetaData meta = null;
+ public static VmMetaData getInstance(List<OperatingSystem> osList, byte[] vmContent, int length)
+ throws IOException {
try {
- meta = new VmwareMetaData( osList, vmContent, length );
- } catch ( UnsupportedVirtualizerFormatException e ) {
- LOGGER.debug( "machine Description entspricht nicht vmx format; versuche mit VBox" );
- try {
- meta = new VboxMetaData( osList, vmContent, length );
- } catch ( UnsupportedVirtualizerFormatException ex ) {
- LOGGER.debug( "machine Description entspricht nicht vbox format ); unterbrochen!", ex );
- }
+ return new VmwareMetaData(osList, vmContent, length);
+ } catch (UnsupportedVirtualizerFormatException e) {
+ LOGGER.debug("Machine description not in .vmx format.", e);
}
- if ( meta != null ) {
- return meta;
+ try {
+ return new VboxMetaData(osList, vmContent, length);
+ } catch (UnsupportedVirtualizerFormatException e) {
+ LOGGER.debug("Machine description not in .vbox format.", e);
}
+ LOGGER.error("Machine description has an unknown format!");
return null;
}
- public abstract boolean addHddTemplate( File diskImage, String hddMode, String redoDir );
+ public abstract boolean addHddTemplate(File diskImage, String hddMode, String redoDir);
- public abstract boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir );
+ public abstract boolean addHddTemplate(String diskImagePath, String hddMode, String redoDir);
public abstract boolean addDefaultNat();
- public abstract void setOs( String vendorOsId );
+ public abstract void setOs(String vendorOsId);
- public abstract boolean addDisplayName( String name );
+ public abstract boolean addDisplayName(String name);
- public abstract boolean addRam( int mem );
+ public abstract boolean addRam(int mem);
- public abstract void addFloppy( int index, String image, boolean readOnly );
+ public abstract void addFloppy(int index, String image, boolean readOnly);
- public abstract boolean addCdrom( String image );
+ public abstract boolean addCdrom(String image);
- public abstract void setTypeOf();
+ public abstract boolean addCpuCoreCount(int nrOfCores);
- public abstract boolean addCpuCoreCount( int nrOfCores );
-
- public TypeOf getTypeOf()
- {
- return typeOf;
- }
}