mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2025-12-15 11:22:43 +03:00
Add incus support
Incus provides meta-data via unix socket /dev/incus/sock https://linuxcontainers.org/incus/docs/main/dev-incus/
This commit is contained in:
parent
abe98e6cbf
commit
3197427cb3
21
lib/tiny-cloud/cloud/incus/imds
Normal file
21
lib/tiny-cloud/cloud/incus/imds
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Incus Instance Metadata
|
||||||
|
# vim:set filetype=sh:
|
||||||
|
# shellcheck shell=sh
|
||||||
|
|
||||||
|
# https://linuxcontainers.org/incus/docs/main/dev-incus/
|
||||||
|
|
||||||
|
IMDS_URI=/1.0/meta-data
|
||||||
|
IMDS_LOCAL_HOSTNAME="local-hostname"
|
||||||
|
IMDS_HOSTNAME="local-hostname"
|
||||||
|
IMDS_ENDPOINT=local:/dev/incus/sock
|
||||||
|
|
||||||
|
_imds() {
|
||||||
|
printf "GET %s HTTP/1.0\n\n" "$IMDS_URI" \
|
||||||
|
| nc "$IMDS_ENDPOINT" | dos2unix \
|
||||||
|
| awk -F ': ' -v key="$1" '$1 == key { print $2 }'
|
||||||
|
}
|
||||||
|
|
||||||
|
_imds_userdata() {
|
||||||
|
printf "GET /1.0/config/user.user-data HTTP/1.0\n\n" \
|
||||||
|
| nc "$IMDS_ENDPOINT" | sed '1,/^\r$/d'
|
||||||
|
}
|
||||||
32
tests/bin/nc
32
tests/bin/nc
@ -20,14 +20,24 @@ while [ ! -z "$1" ]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Scaleway
|
case "$CLOUD" in
|
||||||
if [ "$CLOUD" = "scaleway" ]; then
|
scaleway)
|
||||||
if [ $local_port -gt 1023 ]; then
|
if [ $local_port -gt 1023 ]; then
|
||||||
NC_CONTENT="invalid local port"
|
NC_CONTENT="invalid local port"
|
||||||
else
|
else
|
||||||
NC_CONTENT="$(cat ${NC_FILE:-$host.txt})"
|
NC_CONTENT="$(cat ${NC_FILE:-$host.txt})"
|
||||||
fi
|
fi
|
||||||
printf "HTTP/1.1 200 OK\r\n\r\n%s" "$NC_CONTENT"
|
printf "HTTP/1.1 200 OK\r\n\r\n%s" "$NC_CONTENT"
|
||||||
else
|
;;
|
||||||
echo "token-foo"
|
incus)
|
||||||
fi
|
set -- $input # GET $URL HTTP/1.0
|
||||||
|
url="$2"
|
||||||
|
NC_CONTENT="$(cat ${NC_FILE:-${host%:*}.txt})"
|
||||||
|
len=$(printf "%s" "$NC_CONTENT" | wc -c)
|
||||||
|
printf "HTTP/1.0 200 $url OK\r\nContent-Type: application/json\r\nContent-Length: $len\r\n\r\n%s" \
|
||||||
|
"$NC_CONTENT"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "token-foo"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|||||||
@ -18,6 +18,7 @@ init_tests \
|
|||||||
imds_hostname_oci \
|
imds_hostname_oci \
|
||||||
imds_hostname_scaleway \
|
imds_hostname_scaleway \
|
||||||
imds_hostname_hetzner \
|
imds_hostname_hetzner \
|
||||||
|
imds_hostname_incus \
|
||||||
\
|
\
|
||||||
imds_local_hostname_aws \
|
imds_local_hostname_aws \
|
||||||
imds_local_hostname_azure \
|
imds_local_hostname_azure \
|
||||||
@ -26,6 +27,7 @@ init_tests \
|
|||||||
imds_local_hostname_oci \
|
imds_local_hostname_oci \
|
||||||
imds_local_hostname_scaleway \
|
imds_local_hostname_scaleway \
|
||||||
imds_local_hostname_hetzner \
|
imds_local_hostname_hetzner \
|
||||||
|
imds_local_hostname_incus \
|
||||||
\
|
\
|
||||||
imds_ssh_keys_aws \
|
imds_ssh_keys_aws \
|
||||||
imds_ssh_keys_azure \
|
imds_ssh_keys_azure \
|
||||||
@ -38,6 +40,7 @@ init_tests \
|
|||||||
imds_nocloud_cmdline_local_hostname \
|
imds_nocloud_cmdline_local_hostname \
|
||||||
imds_nocloud_smbios_local_hostname \
|
imds_nocloud_smbios_local_hostname \
|
||||||
\
|
\
|
||||||
|
imds_userdata_incus \
|
||||||
imds_userdata_scaleway
|
imds_userdata_scaleway
|
||||||
|
|
||||||
imds_help_body() {
|
imds_help_body() {
|
||||||
@ -68,6 +71,13 @@ check_hostname() {
|
|||||||
imds_hostname_aws_body() { check_hostname aws; }
|
imds_hostname_aws_body() { check_hostname aws; }
|
||||||
imds_hostname_azure_body() { check_hostname azure; }
|
imds_hostname_azure_body() { check_hostname azure; }
|
||||||
imds_hostname_gcp_body() { check_hostname gcp; }
|
imds_hostname_gcp_body() { check_hostname gcp; }
|
||||||
|
imds_hostname_incus_body() {
|
||||||
|
fake_metadata incus <<-EOF
|
||||||
|
#cloud-config
|
||||||
|
local-hostname: myhostname
|
||||||
|
EOF
|
||||||
|
CLOUD="incus" atf_check -o match:"myhostname" imds @hostname
|
||||||
|
}
|
||||||
imds_hostname_nocloud_body() { check_hostname nocloud; }
|
imds_hostname_nocloud_body() { check_hostname nocloud; }
|
||||||
imds_hostname_oci_body() { check_hostname oci; }
|
imds_hostname_oci_body() { check_hostname oci; }
|
||||||
imds_hostname_scaleway_body() {
|
imds_hostname_scaleway_body() {
|
||||||
@ -80,7 +90,7 @@ imds_hostname_hetzner_body() { check_hostname hetzner; }
|
|||||||
|
|
||||||
check_local_hostname() {
|
check_local_hostname() {
|
||||||
fake_metadata "$1" <<-EOF
|
fake_metadata "$1" <<-EOF
|
||||||
# nocloud, alpine, aws
|
# nocloud, alpine, aws, incus
|
||||||
local-hostname: myhostname
|
local-hostname: myhostname
|
||||||
# hetzner
|
# hetzner
|
||||||
hostname: myhostname
|
hostname: myhostname
|
||||||
@ -96,6 +106,7 @@ check_local_hostname() {
|
|||||||
imds_local_hostname_aws_body() { check_local_hostname aws; }
|
imds_local_hostname_aws_body() { check_local_hostname aws; }
|
||||||
imds_local_hostname_azure_body() { check_local_hostname azure; }
|
imds_local_hostname_azure_body() { check_local_hostname azure; }
|
||||||
imds_local_hostname_gcp_body() { check_local_hostname gcp; }
|
imds_local_hostname_gcp_body() { check_local_hostname gcp; }
|
||||||
|
imds_local_hostname_incus_body() { check_local_hostname incus; }
|
||||||
imds_local_hostname_nocloud_body() { check_local_hostname nocloud; }
|
imds_local_hostname_nocloud_body() { check_local_hostname nocloud; }
|
||||||
imds_local_hostname_oci_body() { check_local_hostname oci; }
|
imds_local_hostname_oci_body() { check_local_hostname oci; }
|
||||||
imds_local_hostname_scaleway_body() {
|
imds_local_hostname_scaleway_body() {
|
||||||
@ -106,6 +117,7 @@ EOF
|
|||||||
CLOUD="scaleway" atf_check -o match:"^myhostname$" imds @local-hostname
|
CLOUD="scaleway" atf_check -o match:"^myhostname$" imds @local-hostname
|
||||||
}
|
}
|
||||||
imds_local_hostname_hetzner_body() { check_local_hostname hetzner; }
|
imds_local_hostname_hetzner_body() { check_local_hostname hetzner; }
|
||||||
|
imds_local_hostname_incus_body() { check_local_hostname incus; }
|
||||||
|
|
||||||
check_ssh_keys() {
|
check_ssh_keys() {
|
||||||
local key="ssh-ed25519 keydata"
|
local key="ssh-ed25519 keydata"
|
||||||
@ -181,6 +193,13 @@ imds_nocloud_smbios_local_hostname_body() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imds_userdata_incus_body() {
|
||||||
|
fake_userdata_incus <<-EOF
|
||||||
|
#alpine-config
|
||||||
|
EOF
|
||||||
|
CLOUD="incus" atf_check -o match:"#alpine-config" imds @userdata
|
||||||
|
}
|
||||||
|
|
||||||
imds_userdata_scaleway_body() {
|
imds_userdata_scaleway_body() {
|
||||||
local cmd="sh ./cmd"
|
local cmd="sh ./cmd"
|
||||||
fake_userdata_scaleway <<-EOF
|
fake_userdata_scaleway <<-EOF
|
||||||
|
|||||||
@ -98,15 +98,24 @@ fake_metadata_hetzner() {
|
|||||||
export WGET_STRIP_PREFIX="/hetzner/v1/metadata"
|
export WGET_STRIP_PREFIX="/hetzner/v1/metadata"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fake_metadata_incus() {
|
||||||
|
cat > "local.txt"
|
||||||
|
}
|
||||||
|
|
||||||
|
fake_userdata_incus() {
|
||||||
|
cat > "local.txt"
|
||||||
|
}
|
||||||
|
|
||||||
fake_metadata() {
|
fake_metadata() {
|
||||||
case "${1:-$CLOUD}" in
|
case "${1:-$CLOUD}" in
|
||||||
alpine|nocloud) fake_metadata_nocloud;;
|
alpine|nocloud) fake_metadata_nocloud;;
|
||||||
aws) fake_metadata_aws;;
|
aws) fake_metadata_aws;;
|
||||||
azure) fake_metadata_azure;;
|
azure) fake_metadata_azure;;
|
||||||
gcp) fake_metadata_gcp;;
|
gcp) fake_metadata_gcp;;
|
||||||
|
hetzner) fake_metadata_hetzner;;
|
||||||
|
incus) fake_metadata_incus;;
|
||||||
oci) fake_metadata_oci;;
|
oci) fake_metadata_oci;;
|
||||||
scaleway) fake_metadata_scaleway;;
|
scaleway) fake_metadata_scaleway;;
|
||||||
hetzner) fake_metadata_hetzner;;
|
|
||||||
*) echo "TODO: fake_metadata_$CLOUD" >&2;;
|
*) echo "TODO: fake_metadata_$CLOUD" >&2;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user