Skip to content

Commit

Permalink
provision devhost via release url api (PL-132065)
Browse files Browse the repository at this point in the history
Co-Authored-By: Philipp Herzog <[email protected]>
Co-Authored-By: Christian Theune <[email protected]>
  • Loading branch information
3 people committed Sep 10, 2024
1 parent c980406 commit 5b1f84a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
## 2.5.1 (unreleased)
---------------------

- Nothing changed yet.

- Devhost provisioning: Add `release` attribute to provisioner config
to allow using release metadata URLs instead of `hydra_eval`

## 2.5.0 (2024-09-04)
-----------------------
Expand Down
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

0 comments on commit 5b1f84a

Please sign in to comment.