commit 371a6e8e77a0e3887a50d3d4338f85aba3f15229
parent f93c23a9682faa84c86110373022eac91901af9d
Author: Stefan Koch <programming@stefan-koch.name>
Date: Sun, 20 Dec 2020 18:57:52 +0100
bring jitsi example to a working state
Diffstat:
4 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/aetherscale/execution.py b/aetherscale/execution.py
@@ -1,6 +1,4 @@
import logging
-from pathlib import Path
-import shutil
import subprocess
from typing import List
diff --git a/aetherscale/qemu/image.py b/aetherscale/qemu/image.py
@@ -5,7 +5,7 @@ from pathlib import Path
import shutil
import subprocess
import tempfile
-from typing import List, TextIO, Iterator
+from typing import TextIO, Iterator
from aetherscale.execution import run_command_chain
from aetherscale.qemu.exceptions import QemuException
@@ -78,6 +78,8 @@ def create_systemd_startup_unit(
f.write('[Unit]\n')
f.write('Description=aetherscale VM init script\n')
f.write(f'ConditionPathExists=!{condition_file}\n')
+ f.write('Wants=network-online.target\n')
+ f.write('After=network-online.target\n')
f.write('\n')
f.write('[Service]\n')
f.write('Type=oneshot\n')
diff --git a/examples/jitsi_auto_install/jitsi-install.sh.jinja2 b/examples/jitsi_auto_install/jitsi-install.sh.jinja2
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
apt update
+apt -y upgrade
apt -y install gnupg2 nginx-full apt-transport-https
apt-add-repository universe
apt update
diff --git a/examples/jitsi_auto_install/start_vm.py b/examples/jitsi_auto_install/start_vm.py
@@ -4,8 +4,12 @@ import jinja2
from pathlib import Path
import sys
import tempfile
+import time
+from typing import List
from aetherscale.client import ServerCommunication
+import aetherscale.config
+from aetherscale.timing import timeout
def create_vm(init_script: Path, comm: ServerCommunication) -> str:
@@ -17,6 +21,10 @@ def create_vm(init_script: Path, comm: ServerCommunication) -> str:
'options': {
'image': 'ubuntu-20.04.1-server-amd64',
'init-script': script,
+ # At the moment this is required for the installation of the
+ # packages, because there is no gateway defined inside VPNs
+ 'public-ip': True,
+ 'vpn': 'jitsi',
}
}, response_expected=True)
@@ -30,6 +38,22 @@ def create_vm(init_script: Path, comm: ServerCommunication) -> str:
return responses[0]['response']['vm-id']
+def get_vm_ips(vm_id: str, comm: ServerCommunication) -> List[str]:
+ responses = comm.send_msg({
+ 'command': 'list-vms',
+ }, response_expected=True)
+
+ for r in responses:
+ try:
+ for vm in r['response']:
+ if vm['vm-id'] == vm_id:
+ return vm['ip-addresses']
+ except KeyError:
+ pass
+
+ return []
+
+
def main():
env = jinja2.Environment(loader=jinja2.FileSystemLoader('./'))
template = env.get_template('jitsi-install.sh.jinja2')
@@ -40,11 +64,39 @@ def main():
with ServerCommunication() as comm:
try:
vm_id = create_vm(Path(f.name), comm)
- print(vm_id)
except RuntimeError as e:
print(str(e), file=sys.stderr)
sys.exit(1)
+ try:
+ # TODO: Currently, the VM image has a flaw in setup of IP addresses
+ # it will wait for a DHCP to be available on all interfaces, but
+ # VPN interface does not have this. To make this work with all
+ # variants of vpn/public-ip we have to define fixed interface names
+ # with https://www.freedesktop.org/software/systemd/man/systemd.link.html
+ # and then can set the right IP lookup for each interface in
+ # /etc/systemd/network/
+ # or we can omit the fixed interface names and directly match on the
+ # MAC address in .network files
+ # (both variants have to be copied to the image before booting it)
+ with timeout(300):
+ ip_address = None
+
+ while not ip_address:
+ with ServerCommunication() as comm:
+ ips = get_vm_ips(vm_id, comm)
+ vpn_prefix = aetherscale.config.VPN_48_PREFIX
+ vpn_ips = [ip for ip in ips if ip.startswith(vpn_prefix)]
+
+ if len(vpn_ips) > 0:
+ ip_address = vpn_ips[0]
+
+ time.sleep(5)
+
+ print(ip_address)
+ except TimeoutError:
+ print('Could not retrieve IP address', file=sys.stderr)
+
if __name__ == '__main__':
main()