Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PL-132065] provision devhost with a certain release #449

Merged
merged 2 commits into from
Oct 29, 2024
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
2 changes: 2 additions & 0 deletions CHANGES.d/20241029_102921_elikowa_HEAD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Devhost provisioning: Add `release` attribute to provisioner config
to allow using release metadata URLs instead of `hydra_eval`
57 changes: 42 additions & 15 deletions src/batou/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import textwrap
import uuid

import requests

import batou.utils
from batou import output
from batou.utils import cmd


class Provisioner(object):

rebuild = False

def __init__(self, name):
Expand Down Expand Up @@ -289,7 +290,6 @@ def provision(self, host):


class FCDevContainer(FCDevProvisioner):

SEED_TEMPLATE = """\
#/bin/sh
set -e
Expand Down Expand Up @@ -371,7 +371,6 @@ def _initial_provision_env(self, host):


class FCDevVM(FCDevProvisioner):

SEED_TEMPLATE = """\
#/bin/sh
set -e
Expand Down Expand Up @@ -399,7 +398,21 @@ class FCDevVM(FCDevProvisioner):
ssh $PROVISION_HOST sudo fc-devhost destroy $PROVISION_VM
fi

ssh $PROVISION_HOST sudo fc-devhost ensure --memory $PROVISION_VM_MEMORY --cpu $PROVISION_VM_CORES --hydra-eval $PROVISION_HYDRA_EVAL --aliases "'$PROVISION_ALIASES'" $PROVISION_VM
cli_args="--memory $PROVISION_VM_MEMORY\\
--cpu $PROVISION_VM_CORES \\
--aliases \\"'$PROVISION_ALIASES'\\""

# Error handling is done in the python part
if [ -n "$PROVISION_HYDRA_EVAL" ]; then
cli_args="${{cli_args}} --hydra-eval $PROVISION_HYDRA_EVAL"
else
cli_args="${{cli_args}} --image-url $PROVISION_IMAGE --channel-url $PROVISION_CHANNEL"
fi

ssh $PROVISION_HOST sudo fc-devhost ensure \\
$cli_args \\
$PROVISION_VM

{seed_script}

# We experimented with hiding errors in this fc-manage run to allow
Expand All @@ -419,18 +432,33 @@ class FCDevVM(FCDevProvisioner):

""" # noqa: E501 line too long
target_host = None
hydra_eval = None
aliases = ()
memory = None
cores = None

hydra_eval = "" # deprecated
channel_url = ""
image_url = ""

@classmethod
def from_config_section(cls, name, section):
instance = FCDevVM(name)
instance.target_host = section["host"]
instance.hydra_eval = section["hydra-eval"]
instance.memory = section.get("memory")
instance.cores = section.get("cores")
instance.memory = section["memory"]
instance.cores = section["cores"]

if "release" in section:
resp = requests.get(section["release"])
resp.raise_for_status()
release_info = resp.json()
instance.channel_url = release_info["channel_url"]
instance.image_url = release_info["devhost_image_url"]
elif "hydra-eval" in section:
instance.hydra_eval = section["hydra-eval"]
else:
raise ValueError(
"Either `release` or `hydra-eval` must be set in the provisioner config section."
)
return instance

def suggest_name(self, name):
Expand All @@ -443,14 +471,13 @@ def suggest_name(self, name):
return name

def _initial_provision_env(self, host):
env = {
return {
"PROVISION_VM": host.name,
"PROVISION_HOST": self.target_host,
"PROVISION_HYDRA_EVAL": self.hydra_eval,
"PROVISION_ALIASES": " ".join(host.aliases.keys()),
"PROVISION_HYDRA_EVAL": self.hydra_eval,
"PROVISION_CHANNEL": self.channel_url,
"PROVISION_IMAGE": self.image_url,
"PROVISION_VM_MEMORY": self.memory,
"PROVISION_VM_CORES": self.cores,
}
if self.memory is not None:
env["PROVISION_VM_MEMORY"] = self.memory
if self.cores is not None:
env["PROVISION_VM_CORES"] = self.cores
return env
Loading