diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/openslx/thrifthelper/TConst.java | 1 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/ThriftUtil.java | 9 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/DiskImage.java | 5 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/DockerMetaDataDummy.java | 144 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/OvfConfig.java | 69 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/OvfMetaData.java | 218 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/VmMetaData.java | 20 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/VmwareConfig.java | 7 |
8 files changed, 466 insertions, 7 deletions
diff --git a/src/main/java/org/openslx/thrifthelper/TConst.java b/src/main/java/org/openslx/thrifthelper/TConst.java index 2ff902e..b7debba 100644 --- a/src/main/java/org/openslx/thrifthelper/TConst.java +++ b/src/main/java/org/openslx/thrifthelper/TConst.java @@ -9,5 +9,6 @@ public class TConst public static final String VIRT_VMWARE = "vmware"; public static final String VIRT_VIRTUALBOX = "virtualbox"; public static final String VIRT_QEMU = "qemukvm"; + public static final String VIRT_DOCKER = "docker"; } diff --git a/src/main/java/org/openslx/util/ThriftUtil.java b/src/main/java/org/openslx/util/ThriftUtil.java index bafe566..327f2d3 100644 --- a/src/main/java/org/openslx/util/ThriftUtil.java +++ b/src/main/java/org/openslx/util/ThriftUtil.java @@ -2,6 +2,7 @@ package org.openslx.util; import java.io.BufferedReader; import java.io.IOException; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -16,9 +17,9 @@ public class ThriftUtil { List<byte[]> hashList = new ArrayList<>(blockHashes.size()); for (ByteBuffer hash : blockHashes) { byte[] buffer = new byte[hash.remaining()]; - hash.mark(); + ((Buffer)hash).mark(); hash.get(buffer); - hash.reset(); + ((Buffer)hash).reset(); hashList.add(buffer); } return hashList; @@ -28,9 +29,9 @@ public class ThriftUtil { byte[] byteArray = null; if (buffer != null) { byteArray = new byte[buffer.remaining()]; - buffer.mark(); + ((Buffer)buffer).mark(); buffer.get(byteArray); - buffer.reset(); + ((Buffer)buffer).reset(); } return byteArray; } diff --git a/src/main/java/org/openslx/util/vm/DiskImage.java b/src/main/java/org/openslx/util/vm/DiskImage.java index 2b24a3f..15b3800 100644 --- a/src/main/java/org/openslx/util/vm/DiskImage.java +++ b/src/main/java/org/openslx/util/vm/DiskImage.java @@ -26,7 +26,8 @@ public class DiskImage public enum ImageFormat { - VMDK( "vmdk" ), QCOW2( "qcow2" ), VDI( "vdi" ); + VMDK( "vmdk" ), QCOW2( "qcow2" ), VDI( "vdi" ), + DOCKER("dockerfile"); public final String extension; @@ -52,6 +53,8 @@ public class DiskImage return VDI; if ( virtId.equals( TConst.VIRT_QEMU ) ) return QCOW2; + if ( virtId.equals( TConst.VIRT_DOCKER) ) + return DOCKER; return null; } } diff --git a/src/main/java/org/openslx/util/vm/DockerMetaDataDummy.java b/src/main/java/org/openslx/util/vm/DockerMetaDataDummy.java new file mode 100644 index 0000000..3ee964f --- /dev/null +++ b/src/main/java/org/openslx/util/vm/DockerMetaDataDummy.java @@ -0,0 +1,144 @@ +package org.openslx.util.vm; + +import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.thrifthelper.TConst; + +import java.io.*; +import java.util.List; + +public class DockerMetaDataDummy extends VmMetaData { + // TODO Define DOCKER CONSTANT + + private static final Logger LOGGER = Logger.getLogger( DockerMetaDataDummy.class); + + private final Virtualizer virtualizer = new Virtualizer( TConst.VIRT_DOCKER, "Docker" ); + + /* this field is in vm context the machine description + e.g. vmware = vmx. + This field will be stored in table imageversion.virtualizerconfig + */ + private byte[] dockerfile; + + public DockerMetaDataDummy(List osList, File file) { + super(osList); + + try { + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); + dockerfile = new byte[(int) file.length()]; + bis.read(dockerfile); + } catch (IOException e) { + LOGGER.error("Couldn't read dockerfile",e); + } + } + + public DockerMetaDataDummy(List osList, byte[] vmContent, int length) { + super(osList); + + dockerfile = vmContent; + } + + @Override public byte[] getFilteredDefinitionArray() { + return dockerfile; + } + + @Override public void applySettingsForLocalEdit() { + + } + + @Override public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) { + return false; + } + + @Override public boolean addHddTemplate(String diskImagePath, String hddMode, String redoDir) { + return false; + } + + @Override public boolean addDefaultNat() { + return false; + } + + @Override public void setOs(String vendorOsId) { + + } + + @Override public boolean addDisplayName(String name) { + return false; + } + + @Override public boolean addRam(int mem) { + return false; + } + + @Override public void addFloppy(int index, String image, boolean readOnly) { + + } + + @Override public boolean addCdrom(String image) { + return false; + } + + @Override public boolean addCpuCoreCount(int nrOfCores) { + return false; + } + + @Override public void setSoundCard(SoundCardType type) { + + } + + @Override public SoundCardType getSoundCard() { + return SoundCardType.NONE; + } + + @Override public void setDDAcceleration(DDAcceleration type) { + + } + + @Override public DDAcceleration getDDAcceleration() { + return DDAcceleration.OFF; + } + + @Override public void setHWVersion(HWVersion type) { + + } + + @Override public HWVersion getHWVersion() { + return HWVersion.DEFAULT; + } + + @Override public void setEthernetDevType(int cardIndex, EthernetDevType type) { + + } + + @Override public EthernetDevType getEthernetDevType(int cardIndex) { + return EthernetDevType.NONE; + } + + @Override public void setMaxUsbSpeed(UsbSpeed speed) { + + } + + @Override public UsbSpeed getMaxUsbSpeed() { + return UsbSpeed.NONE; + } + + @Override public byte[] getDefinitionArray() { + return new byte[0]; + } + + @Override public boolean addEthernet(EtherType type) { + return false; + } + + @Override public Virtualizer getVirtualizer() { + return virtualizer; + } + + @Override public boolean tweakForNonPersistent() { + return false; + } + + @Override public void registerVirtualHW() { + + } +} diff --git a/src/main/java/org/openslx/util/vm/OvfConfig.java b/src/main/java/org/openslx/util/vm/OvfConfig.java new file mode 100644 index 0000000..4bb597c --- /dev/null +++ b/src/main/java/org/openslx/util/vm/OvfConfig.java @@ -0,0 +1,69 @@ +package org.openslx.util.vm; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; + +import javax.xml.xpath.XPathExpressionException; + +import org.apache.log4j.Logger; +import org.openslx.util.Util; +import org.openslx.util.XmlHelper; +import org.openslx.util.vm.VmMetaData.HardDisk; +import org.w3c.dom.Document; + +/** + * Class handling the parsing of a .ovf machine description file For now only a + * dummy for conversion and will be replaced in the image upload flow after + * converting the ovf to vmx. + */ +public class OvfConfig +{ + private static final Logger LOGGER = Logger.getLogger( OvfConfig.class ); + + // key information set during initial parsing of the XML file + private String osName = new String(); + private ArrayList<HardDisk> hddsArray = new ArrayList<HardDisk>(); + + // XPath and DOM parsing related members + private Document doc = null; + + public OvfConfig( File file ) throws IOException, UnsupportedVirtualizerFormatException + { + doc = XmlHelper.parseDocumentFromStream( new FileInputStream( file ) ); + doc = XmlHelper.removeFormattingNodes( doc ); + if ( doc == null ) + throw new UnsupportedVirtualizerFormatException( + "Could not create DOM from given ovf machine configuration file!" ); + init(); + } + + /** + * Main initialization functions parsing the document created during the + * constructor. + * + * @throws UnsupportedVirtualizerFormatException + */ + private void init() throws UnsupportedVirtualizerFormatException + { + if ( Util.isEmptyString( getDisplayName() ) ) { + throw new UnsupportedVirtualizerFormatException( "Machine doesn't have a name" ); + } + } + + /** + * Getter for the display name + * + * @return the display name of this VM + */ + public String getDisplayName() + { + try { + return XmlHelper.XPath.compile( "/Envelope/VirtualSystem/Name" ).evaluate( this.doc ); + } catch ( XPathExpressionException e ) { + return ""; + } + } + +} diff --git a/src/main/java/org/openslx/util/vm/OvfMetaData.java b/src/main/java/org/openslx/util/vm/OvfMetaData.java new file mode 100644 index 0000000..3c69c67 --- /dev/null +++ b/src/main/java/org/openslx/util/vm/OvfMetaData.java @@ -0,0 +1,218 @@ +package org.openslx.util.vm; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; + +/** + * Class handling the metadata of ovf images. Only needed until the ovf has been + * converted into a vmx. + */ +public class OvfMetaData extends VmMetaData +{ + + private static final Logger LOGGER = Logger.getLogger( OvfMetaData.class ); + + private final OvfConfig config; + + public OvfMetaData( List<OperatingSystem> osList, File file ) + throws IOException, UnsupportedVirtualizerFormatException + { + super( osList ); + this.config = new OvfConfig( file ); + init(); + } + + private void init() + { + registerVirtualHW(); + displayName = config.getDisplayName(); + } + + @Override + public byte[] getFilteredDefinitionArray() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void applySettingsForLocalEdit() + { + // TODO Auto-generated method stub + + } + + @Override + public boolean addHddTemplate( File diskImage, String hddMode, String redoDir ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean addDefaultNat() + { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setOs( String vendorOsId ) + { + // TODO Auto-generated method stub + + } + + @Override + public boolean addDisplayName( String name ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean addRam( int mem ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public void addFloppy( int index, String image, boolean readOnly ) + { + // TODO Auto-generated method stub + + } + + @Override + public boolean addCdrom( String image ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean addCpuCoreCount( int nrOfCores ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setSoundCard( SoundCardType type ) + { + // TODO Auto-generated method stub + + } + + @Override + public SoundCardType getSoundCard() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setDDAcceleration( DDAcceleration type ) + { + // TODO Auto-generated method stub + + } + + @Override + public DDAcceleration getDDAcceleration() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setHWVersion( HWVersion type ) + { + // TODO Auto-generated method stub + + } + + @Override + public HWVersion getHWVersion() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setEthernetDevType( int cardIndex, EthernetDevType type ) + { + // TODO Auto-generated method stub + + } + + @Override + public EthernetDevType getEthernetDevType( int cardIndex ) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setMaxUsbSpeed( UsbSpeed speed ) + { + // TODO Auto-generated method stub + + } + + @Override + public UsbSpeed getMaxUsbSpeed() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public byte[] getDefinitionArray() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean addEthernet( EtherType type ) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public Virtualizer getVirtualizer() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean tweakForNonPersistent() + { + // TODO Auto-generated method stub + return false; + } + + @Override + public void registerVirtualHW() + { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/org/openslx/util/vm/VmMetaData.java b/src/main/java/org/openslx/util/vm/VmMetaData.java index 29e2db9..1b9aff9 100644 --- a/src/main/java/org/openslx/util/vm/VmMetaData.java +++ b/src/main/java/org/openslx/util/vm/VmMetaData.java @@ -312,6 +312,18 @@ public abstract class VmMetaData<T, U, V, W, X> } catch ( Exception e ) { LOGGER.info( "Not a QEmu file", e ); } + try { + return new OvfMetaData( osList, file ); + } catch ( Exception e ) { + LOGGER.info( "Not an OVF file", e ); + } + try { + // TODO This will work for each file because simple read as byte array + // TODO No checks if file is a dockerfile --- THIS SHOOULD NOT BE IN PRODUCTION + return new DockerMetaDataDummy(osList, file); + } catch ( Exception e ) { + LOGGER.info( "Not a docker file", e ); + } LOGGER.error( "Could not detect any known virtualizer format" ); return null; } @@ -338,6 +350,14 @@ public abstract class VmMetaData<T, U, V, W, X> } catch ( UnsupportedVirtualizerFormatException e ) { exceptions.put( "Not a VirtualBox file", e ); } + try { + // TODO This should work in each case, because no checks if vmContent is dockerfile + // TODO --- THIS SHOULD NOT BE IN PRODUCTION + LOGGER.info("Creating DockerMetaDataDummy from vmContent"); + return new DockerMetaDataDummy(osList, vmContent, length); + } catch (Exception e) { + e.printStackTrace(); + } // TODO QEmu -- hack above expects qcow2 file, so we can't do anything here yet LOGGER.error( "Could not detect any known virtualizer format" ); for ( Entry<String, Exception> e : exceptions.entrySet() ) { diff --git a/src/main/java/org/openslx/util/vm/VmwareConfig.java b/src/main/java/org/openslx/util/vm/VmwareConfig.java index 20ab3ab..62a014d 100644 --- a/src/main/java/org/openslx/util/vm/VmwareConfig.java +++ b/src/main/java/org/openslx/util/vm/VmwareConfig.java @@ -83,8 +83,11 @@ public class VmwareConfig while ( ( line = reader.readLine() ) != null ) { KeyValuePair entry = parse( line ); - if ( entry != null ) { - if ( entry.key.equals( "virtualHW.version" ) || entry.key.equals( "ddb.virtualHWVersion" ) ) { + if ( entry != null ) { + if ( entry.key.equals( "virtualHW.version" ) || entry.key.equals( "ddb.virtualHWVersion" ) + // TODO: This is supposed to be case insensitive. + // Check if there are other consequences from lowercase entries in converted vmx files. + || entry.key.equals( "virtualhw.version" )) { isValid = true; } set( entry.key, unescape( entry.value ) ); |