Merge pull request #472 from philips/more-gce-oem-setup

feat(coreos-base/oem-gce): support cloudconfig
This commit is contained in:
Brandon Philips 2014-03-22 09:17:40 -07:00
commit b8b1af1b94
7 changed files with 68 additions and 7 deletions

View File

@ -1,6 +1,4 @@
#!/bin/sh
set -e
#!/bin/sh -e
KEY_URL="http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key"

View File

@ -2,7 +2,27 @@
coreos:
units:
- name: ec2-ssh-key.service
- name: gce-coreos-cloudinit.service
runtime: yes
content: |
[Unit]
Requires=gce-setup-environment.service
After=gce-setup-environment.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/usr/share/oem/bin/gce-coreos-cloudinit
- name: gce-setup-environment.service
runtime: yes
content: |
[Unit]
Description=Setup environment variables from metadata
[Service]
Type=oneshot
StandardOutput=journal+console
ExecStart=/usr/share/oem/bin/gce-setup-environment /etc/environment
- name: gce-ssh-key.service
runtime: yes
content: |
[Unit]

View File

@ -0,0 +1,10 @@
#!/bin/bash -e
TMPFILE=$(mktemp /tmp/XXXXXX-cloud-init)
trap 'echo "removing ${TMPFILE}"; rm -f ${TMPFILE}' INT TERM EXIT
curl --retry 5 --retry-delay 2 --silent --fail \
"http://169.254.169.254/computeMetadata/v1/instance/attributes/user-data" \
-H "X-Google-Metadata-Request: True" > ${TMPFILE}
/usr/bin/coreos-cloudinit --from-file=${TMPFILE}

View File

@ -0,0 +1,31 @@
#!/bin/bash -e
ENV=$1
if [ -z "$ENV" ]; then
echo usage: $0 /etc/environment
exit 1
fi
# test for rw
touch $ENV
if [ $? -ne 0 ]; then
echo exiting, unable to modify: $ENV
exit 1
fi
sed -i -e '/^COREOS_PUBLIC_IPV4=/d' \
-e '/^COREOS_PRIVATE_IPV4=/d' \
"${ENV}"
external_ip=$(curl --retry 5 --retry-delay 2 --silent --fail \
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip" \
-H "X-Google-Metadata-Request: True")
public_ip=$(curl --retry 5 --retry-delay 2 --silent --fail \
"http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/ip" \
-H "X-Google-Metadata-Request: True")
echo COREOS_PUBLIC_IPV4=${external_ip} >> $ENV
echo COREOS_PRIVATE_IPV4=${public_ip} >> $ENV

View File

@ -1,8 +1,8 @@
#!/bin/bash
#!/bin/bash -e
set -e
URL_PREFIX="http://metadata/computeMetadata/v1beta1/"
URL_PREFIX="http://169.254.169.254/computeMetadata/v1beta1/"
update_keys() {
local id="$1"

View File

@ -18,6 +18,8 @@ S="${WORKDIR}"
src_install() {
into "/"
dobin ${FILESDIR}/gce-ssh-key
dobin ${FILESDIR}/gce-coreos-cloudinit
dobin ${FILESDIR}/gce-setup-environment
insinto "/"
doins ${FILESDIR}/cloud-config.yml

View File

@ -1,4 +1,4 @@
#!/bin/bash +x
#!/bin/bash -e
ENV=$1