Support Spice ticket.

This commit is contained in:
Michael Lipp 2023-06-20 12:00:02 +02:00
parent 12c2601b92
commit a2e9cd4f70
4 changed files with 23 additions and 1 deletions

View file

@ -95,4 +95,6 @@
# "display": # "display":
# "spice": # "spice":
# "port": 5900 # "port": 5900
# "ticket": (default is to disable ticketing)
# "streamingVideo": (default)
# "usbRedirects": 2 # "usbRedirects": 2

View file

@ -273,6 +273,9 @@ class Configuration implements Dto {
/** The port. */ /** The port. */
public int port = 5900; public int port = 5900;
/** The ticket. */
public String ticket;
/** The streaming video. */ /** The streaming video. */
public String streamingVideo; public String streamingVideo;

View file

@ -310,6 +310,10 @@ public class Runner extends Component {
model.put("firmwareVars", Optional.ofNullable(config.firmwareVars) model.put("firmwareVars", Optional.ofNullable(config.firmwareVars)
.map(Object::toString).orElse(null)); .map(Object::toString).orElse(null));
model.put("vm", config.vm); model.put("vm", config.vm);
if (Optional.ofNullable(config.vm.display)
.map(d -> d.spice).map(s -> s.ticket).isPresent()) {
model.put("ticketPath", config.runtimeDir.resolve("ticket.txt"));
}
// Combine template and data and parse result // Combine template and data and parse result
// (tempting, but no need to use a pipe here) // (tempting, but no need to use a pipe here)
@ -342,6 +346,14 @@ public class Runner extends Component {
// Files to watch for // Files to watch for
Files.deleteIfExists(config.swtpmSocket); Files.deleteIfExists(config.swtpmSocket);
fire(new WatchFile(config.swtpmSocket)); fire(new WatchFile(config.swtpmSocket));
// Helper files
var ticket = Optional.ofNullable(config.vm.display)
.map(d -> d.spice).map(s -> s.ticket);
if (ticket.isPresent()) {
Files.write(config.runtimeDir.resolve("ticket.txt"),
ticket.get().getBytes());
}
} catch (IOException e) { } catch (IOException e) {
logger.log(Level.SEVERE, e, logger.log(Level.SEVERE, e,
() -> "Cannot start runner: " + e.getMessage()); () -> "Cannot start runner: " + e.getMessage());

View file

@ -184,7 +184,12 @@
<#assign spice = vm.display.spice/> <#assign spice = vm.display.spice/>
# SPICE (display, channels ...) # SPICE (display, channels ...)
# https://www.linux-kvm.org/page/SPICE # https://www.linux-kvm.org/page/SPICE
- [ "-spice", "port=${ spice.port?c },disable-ticketing=on\ <#if ticketPath??>
- [ "-object", "secret,id=spiceTicket,file=${ ticketPath }" ]
</#if>
- [ "-spice", "port=${ spice.port?c }\
<#if spice.ticket??>,password-secret=spiceTicket\
<#else>,disable-ticketing=on</#if>\
<#if spice.streamingVideo??>,streaming-video=${ spice.streamingVideo }</#if>\ <#if spice.streamingVideo??>,streaming-video=${ spice.streamingVideo }</#if>\
,seamless-migration=on" ] ,seamless-migration=on" ]
- [ "-chardev", "spicevmc,id=vdagentdev,name=vdagent" ] - [ "-chardev", "spicevmc,id=vdagentdev,name=vdagent" ]