add(coreos-base/oem-cloudstack): CloudStack support

Provide initial support for CloudStack.
This commit is contained in:
Petr Hosek 2014-05-22 15:34:09 +01:00
parent 9b42ac6013
commit c1ecc8e874
7 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,33 @@
#cloud-config
coreos:
units:
- name: cloudstack-ssh-key.service
command: restart
runtime: yes
content: |
[Unit]
Description=Sets SSH key from metadata
[Service]
Type=oneshot
StandardOutput=journal+console
ExecStart=/usr/share/oem/bin/cloudstack-ssh-key
- name: cloudstack-cloudinit.service
command: restart
runtime: yes
content: |
[Unit]
Description=Cloudinit from CloudStack-style metadata
Requires=coreos-setup-environment.service
After=coreos-setup-environment.service
[Service]
Type=oneshot
EnvironmentFile=/etc/environment
ExecStart=/usr/share/oem/bin/cloudstack-coreos-cloudinit
oem:
id: cloudstack
name: CloudStack
home-url: http://cloudstack.apache.org/
bug-report-url: https://github.com/coreos/coreos-overlay

View File

@ -0,0 +1,9 @@
#!/bin/bash
. /usr/share/oem/bin/cloudstack-dhcp
DHCP_SERVER=$(get_dhcp_ip)
USERDATA_URL="http://${DHCP_SERVER}/latest/user-data"
block-until-url "${USERDATA_URL}"
coreos-cloudinit --from-url="${USERDATA_URL}"

View File

@ -0,0 +1,23 @@
#!/bin/bash
get_dhcp_ip() {
local leases_dir="/run/systemd/network/leases"
while true; do
if [[ "$(find "${leases_dir}" -type f -size +1c)" ]]; then
break
fi
sleep .5
done
for leasefile in "${leases_dir}/"*; do
dhcp_server_ip=$(cat $leasefile | awk -F= '/SERVER_ADDRESS/ { print $2 }')
if [[ -n "${dhcp_server_ip}" ]]; then
metadata_url="http://${dhcp_server_ip}/latest/meta-data/"
curl --fail -s "${metadata_url}" >/dev/null
if [[ $? -eq 0 ]]; then
echo $dhcp_server_ip
break
fi
fi
done
}

View File

@ -0,0 +1,9 @@
#!/bin/bash
. /usr/share/oem/bin/cloudstack-dhcp
DHCP_SERVER=$(get_dhcp_ip)
KEY_URL="http://${DHCP_SERVER}/latest/meta-data/public-keys"
block-until-url "${KEY_URL}"
curl --fail -s "${KEY_URL}" | update-ssh-keys -a cloudstack

View File

@ -0,0 +1,32 @@
#!/bin/bash
ENV=$1
if [[ -z "$ENV" ]]; then
echo "usage: $0 /etc/environment" >&2
exit 1
fi
# Make sure that the file is writable
touch $ENV
if [[ $? -ne 0 ]]; then
echo "$0: unable to modify ${ENV}" >&2
exit 1
fi
sed -i -e '/^COREOS_PUBLIC_IPV4=/d' \
-e '/^COREOS_PRIVATE_IPV4=/d' \
"${ENV}"
. /usr/share/oem/bin/cloudstack-dhcp
DHCP_SERVER=$(get_dhcp_ip)
METADATA_URL="http://${DHCP_SERVER}/latest/meta-data/"
block-until-url "${METADATA_URL}"
PUBLIC_IP=$(curl --fail -s "${METADATA_URL}public-ipv4")
echo COREOS_PUBLIC_IPV4=${PUBLIC_IP} >> $ENV
PRIVATE_IP=$(curl --fail -s "${METADATA_URL}local-ipv4")
echo COREOS_PRIVATE_IPV4=${PRIVATE_IP} >> $ENV

View File

@ -0,0 +1 @@
oem-cloudstack-0.0.1.ebuild

View File

@ -0,0 +1,31 @@
#
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Copyright (c) 2014 CoreOS, Inc.. All rights reserved.
# Distributed under the terms of the GNU General Public License v2
# $Header:$
#
EAPI=5
DESCRIPTION="OEM suite for CloudStack images"
HOMEPAGE=""
SRC_URI=""
LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="amd64 x86"
IUSE=""
# no source directory
S="${WORKDIR}"
src_install() {
into "/usr/share/oem"
dobin ${FILESDIR}/cloudstack-dhcp
dobin ${FILESDIR}/cloudstack-ssh-key
dobin ${FILESDIR}/cloudstack-coreos-cloudinit
dobin ${FILESDIR}/coreos-setup-environment
insinto "/usr/share/oem"
doins ${FILESDIR}/cloud-config.yml
}