diff --git a/lxd-init.sh b/lxd-init.sh new file mode 100644 index 0000000..51c0d06 --- /dev/null +++ b/lxd-init.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +yes '' | lxd init diff --git a/lxd_interface.py b/lxd_interface.py new file mode 100644 index 0000000..8b175d2 --- /dev/null +++ b/lxd_interface.py @@ -0,0 +1,22 @@ +import pylxd + +lxd_client = pylxd.client.Client() + + +def create_instance(container_name: str): + config = {'name': container_name, 'source': + {'type': 'image', "mode": "pull", "server": "https://cloud-images.ubuntu.com/daily", "protocol": "simplestreams", + 'alias': 'lts/amd64'}, 'security.nesting': 'true'} + + instance = lxd_client.instances.create(config, wait=True) + instance.start() + + return True + + +def destroy_instance(container_name: str): + instance = lxd_client.instances.get(container_name) + instance.stop(wait=True) + instance.delete(wait=True) + + return True diff --git a/main.py b/main.py index efac88e..1c2f433 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import logging import paramiko import sshim +import pylxd import os import re @@ -12,7 +13,7 @@ def check_auth_none(self, username): def check_auth_password(self, username, password): - if password == os.environ["ssh-password"]: + if username == os.environ["ssh-username"] and password == os.environ["ssh-password"]: return paramiko.AUTH_SUCCESSFUL return paramiko.AUTH_FAILED