summary refs log tree commit diff
path: root/nixos/modules/virtualisation/openstack-config.nix
diff options
context:
space:
mode:
authorAntoine Eiche <lewo@abesis.fr>2019-02-06 12:16:22 +0100
committerAntoine Eiche <lewo@abesis.fr>2019-02-11 20:58:45 +0100
commit933da6de9110ca208a82fb31a6730cbe9d971600 (patch)
treebde6daed5b8cb26053067195b00455c4752307be /nixos/modules/virtualisation/openstack-config.nix
parent78acac050ff27eb45332095935ab112de31d065d (diff)
downloadnixpkgs-933da6de9110ca208a82fb31a6730cbe9d971600.tar
nixpkgs-933da6de9110ca208a82fb31a6730cbe9d971600.tar.gz
nixpkgs-933da6de9110ca208a82fb31a6730cbe9d971600.tar.bz2
nixpkgs-933da6de9110ca208a82fb31a6730cbe9d971600.tar.lz
nixpkgs-933da6de9110ca208a82fb31a6730cbe9d971600.tar.xz
nixpkgs-933da6de9110ca208a82fb31a6730cbe9d971600.tar.zst
nixpkgs-933da6de9110ca208a82fb31a6730cbe9d971600.zip
nixos: Add ec2-metadata-fetcher.nix file
To share the metadata fetcher script between ec2 and Openstack images.
Diffstat (limited to 'nixos/modules/virtualisation/openstack-config.nix')
-rw-r--r--nixos/modules/virtualisation/openstack-config.nix29
1 files changed, 7 insertions, 22 deletions
diff --git a/nixos/modules/virtualisation/openstack-config.nix b/nixos/modules/virtualisation/openstack-config.nix
index 9d8f2ac245d..d5e862da0ea 100644
--- a/nixos/modules/virtualisation/openstack-config.nix
+++ b/nixos/modules/virtualisation/openstack-config.nix
@@ -2,6 +2,12 @@
 
 with lib;
 
+let
+  metadataFetcher = import ./ec2-metadata-fetcher.nix {
+    targetRoot = "/";
+    wgetExtraOptions = "--retry-connrefused";
+  };
+in
 {
   imports = [
     ../profiles/qemu-guest.nix
@@ -39,28 +45,7 @@ with lib;
       before = [ "apply-ec2-data.service" "amazon-init.service"];
       wants = [ "network-online.target" ];
       after = [ "network-online.target" ];
-      script =
-        ''
-          metaDir=/etc/ec2-metadata
-          mkdir -m 0755 -p "$metaDir"
-
-          echo "getting Openstack instance metadata (via EC2 API)..."
-          if ! [ -e "$metaDir/ami-manifest-path" ]; then
-            wget --retry-connrefused -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 --retry-connrefused -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 --retry-connrefused -O "$metaDir/hostname" http://169.254.169.254/1.0/meta-data/hostname
-          fi
-
-          if ! [ -e "$metaDir/public-keys-0-openssh-key" ]; then
-            wget --retry-connrefused -O "$metaDir/public-keys-0-openssh-key" http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
-          fi
-        '';
+      script = metadataFetcher;
       restartIfChanged = false;
       unitConfig.X-StopOnRemoval = false;
       serviceConfig = {