From 31678dce36c9eaa4b3382088e98114bf22c003a9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Sep 2024 11:56:48 +0200 Subject: [libvirt] Add support for devices --- .../java/org/openslx/libvirt/domain/Domain.java | 6 + .../org/openslx/libvirt/domain/device/BusType.java | 59 ++++++++++ .../org/openslx/libvirt/domain/device/Device.java | 48 ++++++++ .../org/openslx/libvirt/domain/device/Hostdev.java | 16 +-- .../openslx/libvirt/domain/device/RedirDevice.java | 129 +++++++++++++++++++++ .../org/openslx/libvirt/domain/DomainTest.java | 10 +- 6 files changed, 259 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/openslx/libvirt/domain/device/BusType.java create mode 100644 src/main/java/org/openslx/libvirt/domain/device/RedirDevice.java diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index af3e63c..b059353 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -37,6 +37,7 @@ 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.RedirDevice; import org.openslx.libvirt.domain.device.Serial; import org.openslx.libvirt.domain.device.Shmem; import org.openslx.libvirt.domain.device.Sound; @@ -1269,6 +1270,11 @@ public class Domain extends LibvirtXmlDocument return Domain.filterDevices( Video.class, this.getDevices() ); } + public ArrayList getRedirectDevices() + { + return Domain.filterDevices( RedirDevice.class, this.getDevices() ); + } + /** * Returns the values of QEMU command line arguments from the Libvirt domain XML document. * diff --git a/src/main/java/org/openslx/libvirt/domain/device/BusType.java b/src/main/java/org/openslx/libvirt/domain/device/BusType.java new file mode 100644 index 0000000..e0ce50e --- /dev/null +++ b/src/main/java/org/openslx/libvirt/domain/device/BusType.java @@ -0,0 +1,59 @@ +package org.openslx.libvirt.domain.device; + +/** + * Union of all known bus types, for generic querying. + */ +public enum BusType +{ + // @formatter:off + MDEV ( "mdev" ), + PCI ( "pci" ), + SATA ( "sata" ), + PS2 ( "ps2" ), + VIRTIO( "virtio" ), + IDE ( "ide" ), + FDC ( "fdc" ), + SCSI ( "scsi" ), + SD ( "sd" ), + XEN ( "xen" ), + USB ( "usb" ); + // @formatter:on + + /** + * Name of the hostdev device type. + */ + private String type = null; + + /** + * Creates hostdev device type. + * + * @param type valid name of the hostdev device type in a Libvirt domain XML document. + */ + BusType( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return this.type; + } + + /** + * Creates hostdev device type from its name with error check. + * + * @param type name of the hostdev device storage in a Libvirt domain XML document. + * @return valid hostdev device type. + */ + public static BusType fromString( String type ) + { + for ( BusType t : BusType.values() ) { + if ( t.type.equalsIgnoreCase( type ) ) { + return t; + } + } + + return null; + } +} \ No newline at end of file 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 31a54ca..e3adf90 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Device.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Device.java @@ -152,6 +152,9 @@ public class Device extends LibvirtXmlNode implements HostdevAddressableTarget