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) { 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(); VmInfo info = VmInfo();
if (sshMatch != null) { List<String> lines = File(name + '/' + name + '.ports').readAsLinesSync();
info.sshPort = sshMatch.group(1); for (var line in lines) {
} List<String> parts = line.split(',');
if (spiceMatch != null) { switch(parts[0]) {
info.spicePort = spiceMatch.group(1); case 'ssh':
info.sshPort = parts[1];
break;
case 'spice':
info.spicePort = parts[1];
break;
}
} }
return info; return info;
} }