Read VM ports from .ports file

Closes #3
This commit is contained in:
Mark Johnson 2021-11-02 20:19:41 +00:00
parent 555aec4934
commit 7124b6fc35
1 changed files with 11 additions and 8 deletions

View File

@ -58,15 +58,18 @@ class _ManagerState extends State<Manager> {
}
VmInfo _parseVmInfo(name) {
String shellScript = File(name + '/' + name + '.sh').readAsStringSync();
RegExpMatch? sshMatch = RegExp('hostfwd=tcp::(\\d+?)-:22').firstMatch(shellScript);
RegExpMatch? spiceMatch = RegExp('-spice.+?port=(\\d+)').firstMatch(shellScript);
VmInfo info = VmInfo();
if (sshMatch != null) {
info.sshPort = sshMatch.group(1);
}
if (spiceMatch != null) {
info.spicePort = spiceMatch.group(1);
List<String> lines = File(name + '/' + name + '.ports').readAsLinesSync();
for (var line in lines) {
List<String> parts = line.split(',');
switch(parts[0]) {
case 'ssh':
info.sshPort = parts[1];
break;
case 'spice':
info.spicePort = parts[1];
break;
}
}
return info;
}