nixos: openstack: have its own metadata fetcher expression

These two APIs have diverged over time and are no longer compatible.
gstqt5
Graham Christensen 2020-11-18 11:42:32 -05:00
parent 6625284c39
commit 21339b41bf
No known key found for this signature in database
GPG Key ID: FE918C3A98C1030F
2 changed files with 24 additions and 1 deletions

View File

@ -3,7 +3,7 @@
with lib;
let
metadataFetcher = import ./ec2-metadata-fetcher.nix {
metadataFetcher = import ./openstack-metadata-fetcher.nix {
targetRoot = "/";
wgetExtraOptions = "--retry-connrefused";
};

View File

@ -0,0 +1,23 @@
{ targetRoot, wgetExtraOptions }:
''
metaDir=${targetRoot}etc/ec2-metadata
mkdir -m 0755 -p "$metaDir"
echo "getting EC2 instance metadata..."
if ! [ -e "$metaDir/ami-manifest-path" ]; then
wget ${wgetExtraOptions} -O "$metaDir/ami-manifest-path" http://169.254.169.254/1.0/meta-data/ami-manifest-path
fi
if ! [ -e "$metaDir/user-data" ]; then
wget ${wgetExtraOptions} -O "$metaDir/user-data" http://169.254.169.254/1.0/user-data && chmod 600 "$metaDir/user-data"
fi
if ! [ -e "$metaDir/hostname" ]; then
wget ${wgetExtraOptions} -O "$metaDir/hostname" http://169.254.169.254/1.0/meta-data/hostname
fi
if ! [ -e "$metaDir/public-keys-0-openssh-key" ]; then
wget ${wgetExtraOptions} -O "$metaDir/public-keys-0-openssh-key" http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
fi
''