diff options
Diffstat (limited to 'src/main/java/org/openslx/libvirt/domain')
11 files changed, 892 insertions, 21 deletions
diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index 4e15ec1..50d0811 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -20,6 +20,7 @@ import org.openslx.libvirt.domain.device.Disk; import org.openslx.libvirt.domain.device.DiskCdrom; import org.openslx.libvirt.domain.device.DiskFloppy; import org.openslx.libvirt.domain.device.DiskStorage; +import org.openslx.libvirt.domain.device.FileSystem; import org.openslx.libvirt.domain.device.Graphics; import org.openslx.libvirt.domain.device.GraphicsSdl; import org.openslx.libvirt.domain.device.GraphicsSpice; @@ -28,6 +29,8 @@ import org.openslx.libvirt.domain.device.Hostdev; import org.openslx.libvirt.domain.device.Interface; import org.openslx.libvirt.domain.device.InterfaceBridge; import org.openslx.libvirt.domain.device.InterfaceNetwork; +import org.openslx.libvirt.domain.device.Parallel; +import org.openslx.libvirt.domain.device.Serial; import org.openslx.libvirt.domain.device.Sound; import org.openslx.libvirt.domain.device.Video; import org.openslx.libvirt.xml.LibvirtXmlDocument; @@ -258,6 +261,17 @@ public class Domain extends LibvirtXmlDocument } /** + * Returns the libosinfo operating system identifier. + * + * @return libosinfo operating system identifier. + */ + public String getLibOsInfoOsId() + { + return this.getRootXmlNode() + .getXmlElementAttributeValue( "metadata/*[local-name()='libosinfo']/*[local-name()='os']", "id" ); + } + + /** * Returns virtual machine UUID defined in the Libvirt domain XML document. * * @return UUID of virtual machine. @@ -353,6 +367,122 @@ public class Domain extends LibvirtXmlDocument } /** + * Returns OS type defined in the Libvirt domain XML document. + * + * @return OS type of the virtual machine. + */ + public OsType getOsType() + { + final String osType = this.getRootXmlNode().getXmlElementValue( "os/type" ); + return OsType.fromString( osType ); + } + + /** + * Set OS type in the Libvirt domain XML document. + * + * @param type OS type for the virtual machine. + */ + public void setOsType( OsType type ) + { + this.getRootXmlNode().setXmlElementValue( "os/type", type.toString() ); + } + + /** + * Returns OS architecture defined in the Libvirt domain XML document. + * + * @return OS architecture of the virtual machine. + */ + public String getOsArch() + { + return this.getRootXmlNode().getXmlElementAttributeValue( "os/type", "arch" ); + } + + /** + * Set OS architecture in the Libvirt domain XML document. + * + * @param arch OS architecture for the virtual machine. + */ + public void setOsArch( String arch ) + { + this.getRootXmlNode().setXmlElementAttributeValue( "os/type", "arch", arch ); + } + + /** + * Returns OS machine defined in the Libvirt domain XML document. + * + * @return OS machine of the virtual machine. + */ + public String getOsMachine() + { + return this.getRootXmlNode().getXmlElementAttributeValue( "os/type", "machine" ); + } + + /** + * Set OS machine in the Libvirt domain XML document. + * + * @param machine OS machine for the virtual machine. + */ + public void setOsMachine( String machine ) + { + this.getRootXmlNode().setXmlElementAttributeValue( "os/type", "machine", machine ); + } + + /** + * Operating system types specifiable for a virtual machine in the Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum OsType + { + // @formatter:off + XEN ( "xen" ), + LINUX( "linux" ), + HVM ( "hvm" ), + EXE ( "exe" ), + UML ( "uml" ); + // @formatter:on + + /** + * Name of the OS type in a Libvirt domain XML document. + */ + private final String osType; + + /** + * Creates an OS type. + * + * @param osType valid name of the OS type in the Libvirt domain XML document. + */ + OsType( String osType ) + { + this.osType = osType; + } + + @Override + public String toString() + { + return this.osType; + } + + /** + * Creates an OS type from its name with error check. + * + * @param osType name of the OS type in the Libvirt domain XML document. + * @return valid OS type. + */ + public static OsType fromString( String osType ) + { + for ( OsType t : OsType.values() ) { + if ( t.osType.equalsIgnoreCase( osType ) ) { + return t; + } + } + + return null; + } + } + + /** * Returns virtual machine CPU model defined in the Libvirt domain XML document. * * @return CPU model of virtual machine. @@ -484,7 +614,7 @@ public class Domain extends LibvirtXmlDocument /** * Creates a CPU check from its name with error check. * - * @param mode name of the CPU check in the Libvirt domain XML document. + * @param check name of the CPU check in the Libvirt domain XML document. * @return valid CPU check. */ public static CpuCheck fromString( String check ) @@ -521,6 +651,26 @@ public class Domain extends LibvirtXmlDocument } /** + * Returns the file name of the emulator binary defined in the Libvirt domain XML document. + * + * @return file name of the emulator binary. + */ + public String getDevicesEmulator() + { + return this.getRootXmlNode().getXmlElementValue( "devices/emulator" ); + } + + /** + * Sets the file name of the emulator binary in the Libvirt domain XML document. + * + * @param emulator file name of the emulator binary. + */ + public void setDevicesEmulator( String emulator ) + { + this.getRootXmlNode().setXmlElementValue( "devices/emulator", emulator ); + } + + /** * Returns virtual machine devices defined in the Libvirt domain XML document. * * @return devices of the virtual machine. @@ -535,12 +685,14 @@ public class Domain extends LibvirtXmlDocument NodeList devicesElements = devicesNode.getChildNodes(); for ( int i = 0; i < devicesElements.getLength(); i++ ) { - LibvirtXmlNode deviceNode = null; - deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), devicesElements.item( i ) ); - Device device = Device.newInstance( deviceNode ); - - if ( device != null ) { - devices.add( device ); + final Node childNode = devicesElements.item( i ); + if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { + LibvirtXmlNode deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), childNode ); + Device device = Device.newInstance( deviceNode ); + + if ( device != null ) { + devices.add( device ); + } } } } @@ -687,6 +839,17 @@ public class Domain extends LibvirtXmlDocument } /** + * Returns list of virtual machine file system devices specified in the Libvirt domain XML + * document. + * + * @return list of virtual machine file system devices. + */ + public ArrayList<FileSystem> getFileSystemDevices() + { + return Domain.filterDevices( FileSystem.class, this.getDevices() ); + } + + /** * Returns list of virtual machine hostdev devices specified in the Libvirt domain XML document. * * @return list of virtual machine hostdev devices. @@ -718,6 +881,28 @@ public class Domain extends LibvirtXmlDocument } /** + * Returns list of virtual machine parallel port devices specified in the Libvirt domain XML + * document. + * + * @return list of virtual machine parallel port devices. + */ + public ArrayList<Parallel> getParallelDevices() + { + return Domain.filterDevices( Parallel.class, this.getDevices() ); + } + + /** + * Returns list of virtual machine serial port devices specified in the Libvirt domain XML + * document. + * + * @return list of virtual machine serial port devices. + */ + public ArrayList<Serial> getSerialDevices() + { + return Domain.filterDevices( Serial.class, this.getDevices() ); + } + + /** * Returns list of virtual machine sound devices specified in the Libvirt domain XML document. * * @return list of virtual machine sound devices. @@ -871,6 +1056,16 @@ public class Domain extends LibvirtXmlDocument } /** + * Adds a virtual machine file system device to the Libvirt domain XML document. + * + * @return reference to the added file system device if creation was successful. + */ + public FileSystem addFileSystemDevice() + { + return FileSystem.class.cast( this.addDevice( new FileSystem() ) ); + } + + /** * Adds a virtual machine disk device to the Libvirt domain XML document. * * @return reference to the added disk device if creation was successful. @@ -951,6 +1146,26 @@ public class Domain extends LibvirtXmlDocument } /** + * Adds a virtual machine parallel port device to the Libvirt domain XML document. + * + * @return reference to the added parallel port device if creation was successful. + */ + public Parallel addParallelDevice() + { + return Parallel.class.cast( this.addDevice( new Parallel() ) ); + } + + /** + * Adds a virtual machine serial port device to the Libvirt domain XML document. + * + * @return reference to the added serial port device if creation was successful. + */ + public Serial addSerialDevice() + { + return Serial.class.cast( this.addDevice( new Serial() ) ); + } + + /** * Adds a virtual machine sound device to the Libvirt domain XML document. * * @return reference to the added sound device if creation was successful. @@ -1012,7 +1227,8 @@ public class Domain extends LibvirtXmlDocument public void removeInterfaceDevicesSource() { for ( Interface interfaceDevice : this.getInterfaceDevices() ) { - interfaceDevice.removeSource(); + // set empty source to preserve the XML attribute (to prevent XML validation errors) + interfaceDevice.setSource( "" ); } } } diff --git a/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java b/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java index 695167c..1798027 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java +++ b/src/main/java/org/openslx/libvirt/domain/device/ControllerUsb.java @@ -122,7 +122,7 @@ public class ControllerUsb extends Controller /** * Creates USB controller device model from its name with error check. * - * @param type name of the USB controller device model in a Libvirt domain XML document. + * @param model name of the USB controller device model in a Libvirt domain XML document. * @return valid USB controller device model. */ public static Model fromString( String model ) diff --git a/src/main/java/org/openslx/libvirt/domain/device/Device.java b/src/main/java/org/openslx/libvirt/domain/device/Device.java index 5c26c55..151592a 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Device.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Device.java @@ -77,6 +77,9 @@ public class Device extends LibvirtXmlNode } else if ( device instanceof Disk ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.DISK ); createdDevice = Disk.createInstance( Disk.class.cast( device ), xmlNode ); + } else if ( device instanceof FileSystem ) { + LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.FILESYSTEM ); + createdDevice = FileSystem.createInstance( FileSystem.class.cast( device ), xmlNode ); } else if ( device instanceof Hostdev ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.HOSTDEV ); createdDevice = Hostdev.createInstance( Hostdev.class.cast( device ), xmlNode ); @@ -86,6 +89,12 @@ public class Device extends LibvirtXmlNode } else if ( device instanceof Graphics ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.GRAPHICS ); createdDevice = Graphics.createInstance( Graphics.class.cast( device ), xmlNode ); + } else if ( device instanceof Parallel ) { + LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.PARALLEL ); + createdDevice = Parallel.createInstance( xmlNode ); + } else if ( device instanceof Serial ) { + LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.SERIAL ); + createdDevice = Serial.createInstance( xmlNode ); } else if ( device instanceof Sound ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.SOUND ); createdDevice = Sound.createInstance( xmlNode ); @@ -125,6 +134,9 @@ public class Device extends LibvirtXmlNode case DISK: device = Disk.newInstance( xmlNode ); break; + case FILESYSTEM: + device = FileSystem.newInstance( xmlNode ); + break; case HOSTDEV: device = Hostdev.newInstance( xmlNode ); break; @@ -134,6 +146,12 @@ public class Device extends LibvirtXmlNode case GRAPHICS: device = Graphics.newInstance( xmlNode ); break; + case PARALLEL: + device = Parallel.newInstance( xmlNode ); + break; + case SERIAL: + device = Serial.newInstance( xmlNode ); + break; case SOUND: device = Sound.newInstance( xmlNode ); break; @@ -157,9 +175,12 @@ public class Device extends LibvirtXmlNode // @formatter:off CONTROLLER( "controller" ), DISK ( "disk" ), + FILESYSTEM( "filesystem" ), HOSTDEV ( "hostdev" ), INTERFACE ( "interface" ), GRAPHICS ( "graphics" ), + PARALLEL ( "parallel" ), + SERIAL ( "serial" ), SOUND ( "sound" ), VIDEO ( "video" ); // @formatter:on diff --git a/src/main/java/org/openslx/libvirt/domain/device/Disk.java b/src/main/java/org/openslx/libvirt/domain/device/Disk.java index 464e7b6..7694538 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Disk.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Disk.java @@ -68,7 +68,7 @@ public class Disk extends Device storageSource = this.getXmlElementAttributeValue( "source", "file" ); break; case BLOCK: - storageSource = this.getXmlElementAttributeValue( "source", "bdev" ); + storageSource = this.getXmlElementAttributeValue( "source", "dev" ); break; } @@ -96,7 +96,7 @@ public class Disk extends Device this.setXmlElementAttributeValue( "source", "file", source ); break; case BLOCK: - this.setXmlElementAttributeValue( "source", "bdev", source ); + this.setXmlElementAttributeValue( "source", "dev", source ); break; } } @@ -195,7 +195,7 @@ public class Disk extends Device /** * Sets target device for the disk device. * - * @param target device for the disk device. + * @param targetDevice target device for the disk device. */ public void setTargetDevice( String targetDevice ) { diff --git a/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java b/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java new file mode 100644 index 0000000..9ec8caf --- /dev/null +++ b/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java @@ -0,0 +1,292 @@ +package org.openslx.libvirt.domain.device; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * A file system device node in a Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class FileSystem extends Device +{ + /** + * Creates an empty file system device. + */ + public FileSystem() + { + super(); + } + + /** + * Creates a file system device representing an existing Libvirt XML file system device element. + * + * @param xmlNode existing Libvirt XML file system device element. + */ + public FileSystem( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns access mode of the file system device. + * + * @return access mode of the file system device. + */ + public AccessMode getAccessMode() + { + final String mode = this.getXmlElementAttributeValue( "accessmode" ); + return AccessMode.fromString( mode ); + } + + /** + * Sets access mode for the file system device. + * + * @param mode access mode for the file system device. + */ + public void setAccessMode( AccessMode mode ) + { + this.setXmlElementAttributeValue( "accessmode", mode.toString() ); + } + + /** + * Returns type of the file system device. + * + * @return type of the file system device. + */ + public Type getType() + { + final String type = this.getXmlElementAttributeValue( "type" ); + return Type.fromString( type ); + } + + /** + * Sets type for the file system device. + * + * @param type type for the file system device. + */ + public void setType( Type type ) + { + this.setXmlElementAttributeValue( "type", type.toString() ); + } + + /** + * Returns source of the file system device. + * + * @return source of the file system device. + */ + public String getSource() + { + final Type type = this.getType(); + String source = null; + + switch ( type ) { + case BIND: + source = this.getXmlElementAttributeValue( "source", "dir" ); + break; + case BLOCK: + source = this.getXmlElementAttributeValue( "source", "dev" ); + break; + case FILE: + source = this.getXmlElementAttributeValue( "source", "file" ); + break; + case MOUNT: + source = this.getXmlElementAttributeValue( "source", "dir" ); + break; + case RAM: + source = this.getXmlElementAttributeValue( "source", "usage" ); + break; + case TEMPLATE: + source = this.getXmlElementAttributeValue( "source", "name" ); + break; + } + + return source; + } + + /** + * Sets source for the file system device. + * + * @param source source for the file system device. + */ + public void setSource( String source ) + { + Type type = this.getType(); + + // remove all attributes from sub-element 'source' + this.removeXmlElementAttributes( "source" ); + + switch ( type ) { + case BIND: + this.setXmlElementAttributeValue( "source", "dir", source ); + break; + case BLOCK: + this.setXmlElementAttributeValue( "source", "dev", source ); + break; + case FILE: + this.setXmlElementAttributeValue( "source", "file", source ); + break; + case MOUNT: + this.setXmlElementAttributeValue( "source", "dir", source ); + break; + case RAM: + this.setXmlElementAttributeValue( "source", "usage", source ); + break; + case TEMPLATE: + this.setXmlElementAttributeValue( "source", "name", source ); + break; + } + } + + /** + * Returns target of the file system device. + * + * @return target of the file system device. + */ + public String getTarget() + { + return this.getXmlElementAttributeValue( "target", "dir" ); + } + + /** + * Sets target for the file system device. + * + * @param target target for the file system device. + */ + public void setTarget( String target ) + { + this.setXmlElementAttributeValue( "target", "dir", target ); + } + + /** + * Creates a non-existent file system device as Libvirt XML device element. + * + * @param xmlNode Libvirt XML node of the Libvirt XML device that is created. + * @return created file system device instance. + */ + public static FileSystem createInstance( LibvirtXmlNode xmlNode ) + { + return FileSystem.newInstance( xmlNode ); + } + + /** + * Creates a file system device representing an existing Libvirt XML file system device element. + * + * @param xmlNode existing Libvirt XML file system device element. + * @return file system device instance. + */ + public static FileSystem newInstance( LibvirtXmlNode xmlNode ) + { + return new FileSystem( xmlNode ); + } + + /** + * Access mode for the file system device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum AccessMode + { + // @formatter:off + PASSTHROUGH( "passthrough" ), + MAPPED ( "mapped" ), + SQUASH ( "squash" ); + // @formatter:on + + /** + * Name of the file system device access mode. + */ + private String mode; + + /** + * Creates file system device access mode. + * + * @param mode valid name of the file system device access mode in a Libvirt domain XML + * document. + */ + AccessMode( String mode ) + { + this.mode = mode; + } + + @Override + public String toString() + { + return this.mode; + } + + /** + * Creates file system device access mode from its name with error check. + * + * @param mode name of the file system device access mode in a Libvirt domain XML document. + * @return valid file system device access mode. + */ + public static AccessMode fromString( String mode ) + { + for ( AccessMode a : AccessMode.values() ) { + if ( a.mode.equalsIgnoreCase( mode ) ) { + return a; + } + } + + return null; + } + } + + /** + * Type of file system device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum Type + { + // @formatter:off + MOUNT ( "mount" ), + TEMPLATE( "template" ), + FILE ( "file" ), + BLOCK ( "block" ), + RAM ( "ram" ), + BIND ( "bind" ); + // @formatter:on + + /** + * Name of the file system device type. + */ + private String type; + + /** + * Creates file system device type. + * + * @param type valid name of the file system device type in a Libvirt domain XML document. + */ + Type( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return this.type; + } + + /** + * Creates file system device type from its name with error check. + * + * @param type name of the file system device type in a Libvirt domain XML document. + * @return valid file system device type. + */ + public static Type fromString( String type ) + { + for ( Type t : Type.values() ) { + if ( t.type.equalsIgnoreCase( type ) ) { + return t; + } + } + + return null; + } + } +} diff --git a/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java b/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java index 3b26fb0..a0563f2 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java +++ b/src/main/java/org/openslx/libvirt/domain/device/HostdevPci.java @@ -48,7 +48,7 @@ public class HostdevPci extends Hostdev * detached from the host before being passed on to the guest and reattached to the host after * the guest exits. * - * @return state whether PCI hostdev device is managed. + * @param managed state whether PCI hostdev device is managed or not. */ public void setManaged( boolean managed ) { diff --git a/src/main/java/org/openslx/libvirt/domain/device/Interface.java b/src/main/java/org/openslx/libvirt/domain/device/Interface.java index b09c7da..44b8e4c 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Interface.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Interface.java @@ -59,16 +59,16 @@ public class Interface extends Device { return Type.fromString( this.getXmlElementAttributeValue( "type" ) ); } - + /** * Sets type of the network device. - * - * @return type of the network device. + * + * @param type network device type. */ - public void setType(Type type) + public void setType( Type type ) { String source = this.getSource(); - + // change type and set source again this.setXmlElementAttributeValue( "type", type.toString() ); this.setSource( source ); @@ -119,6 +119,26 @@ public class Interface extends Device } /** + * Returns MAC address of the network device. + * + * @return MAC address of the network device. + */ + public String getMacAddress() + { + return this.getXmlElementAttributeValue( "mac", "address" ); + } + + /** + * Sets MAC address of the network device. + * + * @param macAddress MAC address for the network device. + */ + public void setMacAddress( String macAddress ) + { + this.setXmlElementAttributeValue( "mac", "address", macAddress ); + } + + /** * Removes boot oder entry of the network interface device. */ public void removeBootOrder() @@ -135,6 +155,14 @@ public class Interface extends Device } /** + * Removes MAC address of the network interface device. + */ + public void removeMacAddress() + { + this.removeXmlElement( "mac" ); + } + + /** * Creates a non-existent network interface device as Libvirt XML device element. * * @param iface network device that is created. @@ -299,7 +327,7 @@ public class Interface extends Device /** * Creates network interface device model from its name with error check. * - * @param type name of the network interface device model in a Libvirt domain XML document. + * @param model name of the network interface device model in a Libvirt domain XML document. * @return valid network interface device model. */ public static Model fromString( String model ) diff --git a/src/main/java/org/openslx/libvirt/domain/device/Parallel.java b/src/main/java/org/openslx/libvirt/domain/device/Parallel.java new file mode 100644 index 0000000..7db60ca --- /dev/null +++ b/src/main/java/org/openslx/libvirt/domain/device/Parallel.java @@ -0,0 +1,158 @@ +package org.openslx.libvirt.domain.device; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * A parallel port device node in a Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Parallel extends Device +{ + /** + * Creates an empty parallel port device. + */ + public Parallel() + { + super(); + } + + /** + * Creates a parallel port device representing an existing Libvirt XML parallel port device + * element. + * + * @param xmlNode existing Libvirt XML parallel port device element. + */ + public Parallel( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the type of the parallel port device. + * + * @return type of the parallel port device. + */ + public Type getType() + { + final String type = this.getXmlElementAttributeValue( "type" ); + return Type.fromString( type ); + } + + /** + * Sets the type for the parallel port device. + * + * @param type type for the parallel port device. + */ + public void setType( Type type ) + { + this.setXmlElementAttributeValue( "type", type.toString() ); + } + + /** + * Returns the source of the parallel port device. + * + * @return source of the parallel port device. + */ + public String getSource() + { + return this.getXmlElementAttributeValue( "source", "path" ); + } + + /** + * Sets the source for the parallel port device. + * + * @param source source for the parallel port device. + */ + public void setSource( String source ) + { + this.setXmlElementAttributeValue( "source", "path", source ); + } + + /** + * Creates a non-existent parallel port device as Libvirt XML parallel port device element. + * + * @param xmlNode Libvirt XML node of the Libvirt XML parallel port device that is created. + * @return created parallel port device instance. + */ + public static Parallel createInstance( LibvirtXmlNode xmlNode ) + { + return Parallel.newInstance( xmlNode ); + } + + /** + * Creates a parallel port device representing an existing Libvirt XML parallel port device + * element. + * + * @param xmlNode existing Libvirt XML parallel port device element. + * @return parallel port device instance. + */ + public static Parallel newInstance( LibvirtXmlNode xmlNode ) + { + return new Parallel( xmlNode ); + } + + /** + * Type of parallel port device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum Type + { + // @formatter:off + DEV ( "dev" ), + FILE ( "file" ), + PIPE ( "pipe" ), + UNIX ( "unix" ), + TCP ( "tcp" ), + UDP ( "udp" ), + NULL ( "null" ), + STDIO ( "stdio" ), + VC ( "vc" ), + PTY ( "pty" ), + SPICEVMC ( "spicevmc" ), + SPICEPORT( "spiceport" ), + NMDM ( "nmdm" ); + // @formatter:on + + /** + * Name of the parallel port device type. + */ + private String type; + + /** + * Creates parallel port device type. + * + * @param type valid name of the parallel port device type in a Libvirt domain XML document. + */ + Type( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return this.type; + } + + /** + * Creates parallel port device type from its name with error check. + * + * @param type name of the parallel port device type in a Libvirt domain XML document. + * @return valid parallel port device type. + */ + public static Type fromString( String type ) + { + for ( Type t : Type.values() ) { + if ( t.type.equalsIgnoreCase( type ) ) { + return t; + } + } + + return null; + } + } +} diff --git a/src/main/java/org/openslx/libvirt/domain/device/Serial.java b/src/main/java/org/openslx/libvirt/domain/device/Serial.java new file mode 100644 index 0000000..54be26e --- /dev/null +++ b/src/main/java/org/openslx/libvirt/domain/device/Serial.java @@ -0,0 +1,156 @@ +package org.openslx.libvirt.domain.device; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * A serial port device node in a Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Serial extends Device +{ + /** + * Creates an empty serial port device. + */ + public Serial() + { + super(); + } + + /** + * Creates a serial port device representing an existing Libvirt XML serial port device element. + * + * @param xmlNode existing Libvirt XML serial port device element. + */ + public Serial( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the type of the serial port device. + * + * @return type of the serial port device. + */ + public Type getType() + { + final String type = this.getXmlElementAttributeValue( "type" ); + return Type.fromString( type ); + } + + /** + * Sets the type for the serial port device. + * + * @param type type for the serial port device. + */ + public void setType( Type type ) + { + this.setXmlElementAttributeValue( "type", type.toString() ); + } + + /** + * Returns the source of the serial port device. + * + * @return source of the serial port device. + */ + public String getSource() + { + return this.getXmlElementAttributeValue( "source", "path" ); + } + + /** + * Sets the source for the serial port device. + * + * @param source source for the serial port device. + */ + public void setSource( String source ) + { + this.setXmlElementAttributeValue( "source", "path", source ); + } + + /** + * Creates a non-existent serial port device as Libvirt XML serial port device element. + * + * @param xmlNode Libvirt XML node of the Libvirt XML serial port device that is created. + * @return created serial port device instance. + */ + public static Serial createInstance( LibvirtXmlNode xmlNode ) + { + return Serial.newInstance( xmlNode ); + } + + /** + * Creates a serial port device representing an existing Libvirt XML serial port device element. + * + * @param xmlNode existing Libvirt XML serial port device element. + * @return serial port device instance. + */ + public static Serial newInstance( LibvirtXmlNode xmlNode ) + { + return new Serial( xmlNode ); + } + + /** + * Type of serial port device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum Type + { + // @formatter:off + DEV ( "dev" ), + FILE ( "file" ), + PIPE ( "pipe" ), + UNIX ( "unix" ), + TCP ( "tcp" ), + UDP ( "udp" ), + NULL ( "null" ), + STDIO ( "stdio" ), + VC ( "vc" ), + PTY ( "pty" ), + SPICEVMC ( "spicevmc" ), + SPICEPORT( "spiceport" ), + NMDM ( "nmdm" ); + // @formatter:on + + /** + * Name of the serial port device type. + */ + private String type; + + /** + * Creates serial port device type. + * + * @param type valid name of the serial port device type in a Libvirt domain XML document. + */ + Type( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return this.type; + } + + /** + * Creates serial port device type from its name with error check. + * + * @param type name of the serial port device type in a Libvirt domain XML document. + * @return valid serial port device type. + */ + public static Type fromString( String type ) + { + for ( Type t : Type.values() ) { + if ( t.type.equalsIgnoreCase( type ) ) { + return t; + } + } + + return null; + } + } +} diff --git a/src/main/java/org/openslx/libvirt/domain/device/Sound.java b/src/main/java/org/openslx/libvirt/domain/device/Sound.java index e424ed4..dfeeffd 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Sound.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Sound.java @@ -111,7 +111,7 @@ public class Sound extends Device /** * Creates sound device model from its name with error check. * - * @param type name of the sound device model in a Libvirt domain XML document. + * @param model name of the sound device model in a Libvirt domain XML document. * @return valid sound device model. */ public static Model fromString( String model ) diff --git a/src/main/java/org/openslx/libvirt/domain/device/Video.java b/src/main/java/org/openslx/libvirt/domain/device/Video.java index e901b85..0f8861f 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Video.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Video.java @@ -171,7 +171,7 @@ public class Video extends Device /** * Creates video device model from its name with error check. * - * @param type name of the video device model in a Libvirt domain XML document. + * @param model name of the video device model in a Libvirt domain XML document. * @return valid video device model. */ public static Model fromString( String model ) |