From e33d5e17b789fb180e9d24dce1d36caed2d83e16 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 1 Sep 2021 12:30:25 +0200 Subject: Add getter/setter for listen address and port of Libvirt SPICE graphics --- .../openslx/libvirt/domain/device/Graphics.java | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/main/java/org/openslx/libvirt/domain/device/Graphics.java') diff --git a/src/main/java/org/openslx/libvirt/domain/device/Graphics.java b/src/main/java/org/openslx/libvirt/domain/device/Graphics.java index d10eb3f..3fd2f81 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Graphics.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Graphics.java @@ -1,5 +1,8 @@ package org.openslx.libvirt.domain.device; +import java.net.InetAddress; +import java.net.UnknownHostException; + import org.openslx.libvirt.xml.LibvirtXmlNode; /** @@ -49,6 +52,66 @@ public class Graphics extends Device this.setXmlElementAttributeValue( "listen", "type", type.toString() ); } + /** + * Returns the listen address of the graphics device. + * + * @return listen address of the graphics device. + */ + public InetAddress getListenAddress() + { + InetAddress parsedListenAddress = null; + + if ( this.getListenType() == ListenType.ADDRESS ) { + // only read listen address, if address listen type is set + final String rawListenAddress = this.getXmlElementAttributeValue( "listen", "address" ); + + try { + parsedListenAddress = InetAddress.getByName( rawListenAddress ); + } catch ( UnknownHostException e ) { + parsedListenAddress = null; + } + } + + return parsedListenAddress; + } + + /** + * Sets the listen address for the graphics device. + * + * @param listenAddress listen address for the graphics device. + */ + public void setListenAddress( InetAddress listenAddress ) + { + if ( this.getListenType() == ListenType.ADDRESS && listenAddress != null ) { + // only set listen address, if address listen type is set + this.setXmlElementAttributeValue( "listen", "address", listenAddress.getHostAddress() ); + } + } + + /** + * Returns the listen port of the graphics device. + * + * @return listen port of the graphics device. + */ + public int getListenPort() + { + final String listenPort = this.getXmlElementAttributeValue( "port" ); + return Integer.valueOf( listenPort ); + } + + /** + * Sets the listen port for the graphics device. + * + * @param listenPort listen port for the graphics device. + */ + public void setListenPort( int listenPort ) + { + if ( this.getListenType() == ListenType.ADDRESS ) { + // only set listen port, if address listen type is set + this.setXmlElementAttributeValue( "port", Integer.toString( listenPort ) ); + } + } + /** * Creates a non-existent graphics device as Libvirt XML device element. * -- cgit v1.2.3-55-g7522