Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions ctf/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,11 @@ def deploy(

# Waiting for virtual machine to be up and running
# Starting with a minute
if start_timer > time.time() - (seconds := 60.0):
LOG.info(
f"Waiting for the virtual machine to be ready. Remaining {(seconds - (time.time() - start_timer)):.1f} seconds..."
)

if start_timer > time.time() - (seconds := 30):
for machine in incus_list:
if machine["type"] != "virtual-machine":
continue

rebooting: bool = False
cmd: str = "whoami" # Should works on most OS
while start_timer > time.time() - seconds:
# Avoid spamming too much, sleeping for a second between each request.
Expand Down Expand Up @@ -236,20 +231,12 @@ def deploy(
)
start_timer = time.time()
case 0:
if not rebooting:
LOG.debug(
f"Remaining {(seconds - (time.time() - start_timer)):.1f} seconds..."
)
else:
LOG.info("Agent is up and running!")
break
LOG.info("Agent is up and running!")
break
case _:
# Once the virtual machine rebooted once, set the timer to 30 minutes.
if not rebooting:
LOG.info(
"Virtual machine is most likely rebooting. Once the agent is back up, let's move on."
)
rebooting = True
LOG.info(
f"Waiting for the virtual machine to be ready. Remaining {(seconds - (time.time() - start_timer)):.1f} seconds..."
)

run_ansible_playbook(
remote=remote, production=production, track=track.name, path=path
Expand Down
25 changes: 14 additions & 11 deletions ctf/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess

import typer
from pydantic import ValidationError
from typing_extensions import Annotated

from ctf import ENV
Expand Down Expand Up @@ -138,17 +139,19 @@ def destroy(
)
}

networks = {
Track(name=network["name"])
for network in json.loads(
s=subprocess.run(
args=["incus", "network", "list", "--format=json"],
check=False,
capture_output=True,
env=ENV,
).stdout.decode()
)
}
networks = set()
for network in json.loads(
s=subprocess.run(
args=["incus", "network", "list", "--format=json"],
check=False,
capture_output=True,
env=ENV,
).stdout.decode()
):
try:
networks.add(Track(name=network["name"]))
except ValidationError:
pass

network_acls = {
Track(name=network_acl["name"])
Expand Down