Make interface return v4 IP, fix bug with nested virt

os-repl
root 2022-11-24 18:06:41 +00:00
parent 9d1cad700f
commit 3e3ddc5250
1 changed files with 7 additions and 3 deletions

View File

@ -1,4 +1,6 @@
import time
import pylxd import pylxd
import ipaddress
lxd_client = pylxd.client.Client() lxd_client = pylxd.client.Client()
@ -6,12 +8,14 @@ lxd_client = pylxd.client.Client()
def create_instance(container_name: str): def create_instance(container_name: str):
config = {'name': container_name, 'source': config = {'name': container_name, 'source':
{'type': 'image', "mode": "pull", "server": "https://cloud-images.ubuntu.com/daily", "protocol": "simplestreams", {'type': 'image', "mode": "pull", "server": "https://cloud-images.ubuntu.com/daily", "protocol": "simplestreams",
'alias': 'lts/amd64'}, 'security.nesting': 'true'} 'alias': 'lts/amd64'}, 'config': {'security.nesting': 'true'}}
instance = lxd_client.instances.create(config, wait=True) instance = lxd_client.instances.create(config, wait=True)
instance.start() instance.start(wait=True)
return True while type(ipaddress.ip_address(instance.state().network['eth0']['addresses'][0]['address'])) != ipaddress.IPv4Address:
time.sleep(0.1)
return instance.state().network['eth0']['addresses'][0]
def destroy_instance(container_name: str): def destroy_instance(container_name: str):