Merge pull request #413 from polvi/rackspace

feat(rackspace): update rackspace to use cloudinit
This commit is contained in:
polvi 2014-03-13 15:12:20 -07:00
commit 65c9b6ca00
17 changed files with 64 additions and 436 deletions

View File

@ -9,7 +9,7 @@ CROS_WORKON_REPO="git://github.com"
if [[ "${PV}" == 9999 ]]; then
KEYWORDS="~amd64"
else
CROS_WORKON_COMMIT="d823f99f7d491b84e4bc91f492bf2aefef6846b5" # tag v0.1.1
CROS_WORKON_COMMIT="9bcd56222f08d7d1ecb23686a33238a8e89bded1"
KEYWORDS="amd64"
fi

View File

@ -0,0 +1 @@
nova-agent-watcher-9999.ebuild

View File

@ -0,0 +1,35 @@
# Copyright (c) 2014 CoreOS, Inc.. All rights reserved.
# Distributed under the terms of the GNU General Public License v2
EAPI=4
CROS_WORKON_PROJECT="coreos/nova-agent-watcher"
CROS_WORKON_LOCALNAME="nova-agent-watcher"
CROS_WORKON_REPO="git://github.com"
if [[ "${PV}" == 9999 ]]; then
KEYWORDS="~amd64"
else
CROS_WORKON_COMMIT="777669eb9e6f2bca3f494feb3e0b1fbef288d5ab"
KEYWORDS="amd64"
fi
inherit cros-workon systemd
DESCRIPTION="nova-agent-watcher"
HOMEPAGE="https://github.com/coreos/nova-agent-watcher"
SRC_URI=""
LICENSE="Apache-2.0"
SLOT="0"
IUSE=""
DEPEND=">=dev-lang/go-1.2"
src_compile() {
./build || die
}
src_install() {
dobin ${S}/scripts/gentoo-to-networkd
dobin ${S}/bin/nova-agent-watcher
}

View File

@ -1,328 +0,0 @@
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.
ifconfig_depend()
{
program /sbin/ifconfig /bin/ifconfig
provide interface
}
_up()
{
ifconfig "${IFACE}" up
}
_down()
{
ifconfig "${IFACE}" down
}
_exists()
{
[ -e /sys/class/net/"$IFACE" ]
}
_ifindex()
{
local index=-1
local f v
if [ -e /sys/class/net/"${IFACE}"/ifindex ]; then
index=$(cat /sys/class/net/"${IFACE}"/ifindex)
else
for f in /sys/class/net/*/ifindex ; do
v=$(cat $f)
[ $v -gt $index ] && index=$v
done
: $(( index += 1 ))
fi
echo "${index}"
return 0
}
_is_wireless()
{
# Support new sysfs layout
[ -d /sys/class/net/"${IFACE}"/wireless -o \
-d /sys/class/net/"${IFACE}"/phy80211 ] && return 0
[ ! -e /proc/net/wireless ] && return 1
grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
}
_set_flag()
{
ifconfig "${IFACE}" "$1"
}
_get_mac_address()
{
local mac=$(LC_ALL=C ifconfig "${IFACE}" | \
sed -n -e 's/.* \(HWaddr\|ether\) \(..:..:..:..:..:..\).*/\2/p')
case "${mac}" in
00:00:00:00:00:00);;
44:44:44:44:44:44);;
FF:FF:FF:FF:FF:FF);;
"");;
*) echo "${mac}"; return 0;;
esac
return 1
}
_set_mac_address()
{
ifconfig "${IFACE}" hw ether "$1"
}
_get_inet_address()
{
set -- $(LC_ALL=C ifconfig "${IFACE}" |
sed -n -e 's/.*\(inet addr:\|inet \)\([^ ]*\).*\(Mask:\|netmask \)\([^ ]*\).*/\2 \4/p')
[ -z "$1" ] && return 1
echo -n "$1"
shift
echo "/$(_netmask2cidr "$1")"
}
_get_inet_addresses()
{
local iface=${IFACE} i=0
local addrs="$(_get_inet_address)"
while true; do
local IFACE="${iface}:${i}"
_exists || break
local addr="$(_get_inet_address)"
[ -n "${addr}" ] && addrs="${addrs}${addrs:+ }${addr}"
: $(( i += 1 ))
done
echo "${addrs}"
}
_cidr2netmask()
{
local cidr="$1" netmask="" done=0 i=0 sum=0 cur=128
local octets= frac=
local octets=$(( cidr / 8 ))
local frac=$(( cidr % 8 ))
while [ ${octets} -gt 0 ]; do
netmask="${netmask}.255"
: $(( octets -= 1 ))
: $(( done += 1 ))
done
if [ ${done} -lt 4 ]; then
while [ ${i} -lt ${frac} ]; do
: $(( sum += cur ))
: $(( cur /= 2 ))
: $(( i += 1 ))
done
netmask="${netmask}.${sum}"
: $(( done += 1 ))
while [ ${done} -lt 4 ]; do
netmask="${netmask}.0"
: $(( done += 1 ))
done
fi
echo "${netmask#.*}"
}
_add_address()
{
if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then
ifconfig "${IFACE}" "$@" 2>/dev/null
return 0
fi
case "$1" in
*:*) ifconfig "${IFACE}" inet6 add "$@"; return $?;;
esac
# IPv4 is tricky - ifconfig requires an aliased device
# for multiple addresses
local iface="${IFACE}"
if LC_ALL=C ifconfig "${iface}" | grep -Eq '\<inet (addr:)?.*'; then
# Get the last alias made for the interface and add 1 to it
i=$(ifconfig | sed '1!G;h;$!d' | grep -m 1 -o "^${iface}:[0-9]*" \
| sed -n -e 's/'"${iface}"'://p')
: $(( i = ${i:-0} + 1 ))
iface="${iface}:${i}"
fi
# ifconfig doesn't like CIDR addresses
local ip="${1%%/*}" cidr="${1##*/}" netmask=
if [ -n "${cidr}" -a "${cidr}" != "${ip}" ]; then
netmask="$(_cidr2netmask "${cidr}")"
shift
set -- "${ip}" netmask "${netmask}" "$@"
fi
local arg= cmd=
while [ -n "$1" ]; do
case "$1" in
brd)
if [ "$2" = "+" ]; then
shift
else
cmd="${cmd} broadcast"
fi
;;
peer) cmd="${cmd} pointopoint";;
*) cmd="${cmd} $1";;
esac
shift
done
ifconfig "${iface}" ${cmd}
}
_add_route()
{
local inet6= family=
if [ "$1" = "-A" -o "$1" = "-f" -o "$1" = "-family" ]; then
family="-A $2"
shift; shift
elif [ "$1" = "-4" ]; then
family="-A inet"
shift
elif [ "$1" = "-6" ]; then
family="-A inet6"
shift
fi
if [ -n "${metric}" ]; then
set -- "$@" metric ${metric}
fi
if [ $# -eq 3 ]; then
set -- "$1" "$2" gw "$3"
elif [ "$3" = "via" ]; then
local one=$1 two=$2
shift; shift; shift
set -- "${one}" "${two}" gw "$@"
fi
case "$@" in
*:*|default*) [ "$1" = "-net" -o "$1" = "-host" ] && shift;;
esac
route ${family} add "$@" dev "${IFACE}"
}
_delete_addresses()
{
# We don't remove addresses from aliases
case "${IFACE}" in
*:*) return 0;;
esac
einfo "Removing addresses"
eindent
# iproute2 can add many addresses to an iface unlike ifconfig ...
# iproute2 added addresses cause problems for ifconfig
# as we delete an address, a new one appears, so we have to
# keep polling
while true; do
local addr=$(_get_inet_address)
[ -z "${addr}" ] && break
if [ "${addr}" = "127.0.0.1/8" ]; then
# Don't delete the loopback address
[ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] && break
fi
einfo "${addr}"
ifconfig "${IFACE}" 0.0.0.0 || break
done
# Remove IPv6 addresses
local addr=
for addr in $(LC_ALL=C ifconfig "${IFACE}" | \
sed -n -e 's/^.*\(inet6 addr:\|inet6\) \([^ ]*\) .*\(Scope:[^L]\|scopeid [^<]*<[^l]\).*/\2/p'); do
if [ "${IFACE}" = "lo" ]; then
case "${addr}" in
"::1/128"|"/128") continue;;
esac
fi
einfo "${addr}"
ifconfig "${IFACE}" inet6 del "${addr}"
done
return 0
}
_has_carrier()
{
return 0
}
_tunnel()
{
iptunnel "$@"
}
ifconfig_pre_start()
{
local tunnel=
eval tunnel=\$iptunnel_${IFVAR}
if [ -n "${tunnel}" ]; then
# Set our base metric to 1000
metric=1000
ebegin "Creating tunnel ${IFVAR}"
iptunnel add ${tunnel}
eend $? || return 1
_up
fi
# MTU support
local mtu=
eval mtu=\$mtu_${IFVAR}
[ -n "${mtu}" ] && ifconfig "${IFACE}" mtu "${mtu}"
# TX Queue Length support
local len=
eval len=\$txqueuelen_${IFVAR}
[ -n "${len}" ] && ifconfig "${IFACE}" txqueuelen "${len}"
return 0
}
ifconfig_post_stop()
{
# Don't delete sit0 as it's a special tunnel
[ "${IFACE}" = "sit0" ] && return 0
[ -z "$(iptunnel show "${IFACE}" 2>/dev/null)" ] && return 0
ebegin "Destroying tunnel ${IFACE}"
iptunnel del "${IFACE}"
eend $?
}
# Is the interface administratively/operationally up?
# The 'UP' status in ifconfig/iproute2 is the administrative status
# Operational state is available in iproute2 output as 'state UP', or the
# operstate sysfs variable.
# 0: up
# 1: down
# 2: invalid arguments
is_admin_up()
{
local iface="$1"
[ -z "$iface" ] && iface="$IFACE"
ifconfig "${iface}" | \
sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; '
}
is_oper_up()
{
local iface="$1"
[ -z "$iface" ] && iface="$IFACE"
read state </sys/class/net/"${iface}"/operstate
[ "x$state" = "up" ]
}

View File

@ -0,0 +1,19 @@
#cloud-config
coreos:
units:
- name: nova-agent-auto.service
content: |
[Unit]
After=dbus.service
[Service]
Environment=HOME=/root
ExecStartPre=/bin/mount -t proc none /usr/share/oem/nova-agent/proc
ExecStartPre=/bin/mount -t xenfs none /usr/share/oem/nova-agent/proc/xen
ExecStartPre=/bin/mount --bind /dev /usr/share/oem/nova-agent/dev
ExecStartPre=/bin/mount --bind /sys /usr/share/oem/nova-agent/sys
ExecStart=/usr/bin/chroot /usr/share/oem/nova-agent/ /usr/share/nova-agent/0.0.1.38/sbin/nova-agent -o - -n -l info /usr/share/nova-agent/nova-agent.py
ExecStopPost=/bin/umount -f /usr/share/oem/nova-agent/sys
ExecStopPost=/bin/umount -f /usr/share/oem/nova-agent/dev
ExecStopPost=/bin/umount -f /usr/share/oem/nova-agent/proc/xen
ExecStopPost=/bin/umount -f /usr/share/oem/nova-agent/proc

View File

@ -1,32 +0,0 @@
#!/bin/bash
OEM_DIR="/usr/share/oem"
NET_CONF=$OEM_DIR/nova-agent/etc/conf.d/net
while [ ! -e ${NET_CONF} ]; do
echo waiting...
sleep .1
done
. ${NET_CONF}
. ${OEM_DIR}/usr/bin/ifconfig.sh
for if in eth0 eth1; do
IFACE=$if
OLDIFS=$IFS
IFS=$'\n'
CONFIG="config_${if}"
eval CONFIG=\$$CONFIG
for net in $CONFIG; do
IFS=$OLDIFS
_add_address $net
done
OLDIFS=$IFS
IFS=$'\n'
ROUTE="routes_${if}"
eval ROUTE=\$$ROUTE
for route in $ROUTE; do
IFS=$OLDIFS
#_add_route $route
ip route add $route dev $if
done
done

View File

@ -1,10 +0,0 @@
#!/bin/bash
OEM_DIR="/usr/share/oem"
CONF=$OEM_DIR/nova-agent/etc/resolv.conf
while [ ! -e ${CONF} ]; do
echo waiting...
sleep .1
done
cp ${CONF} /etc/resolv.conf

View File

@ -1,4 +1,4 @@
#!/bin/bash
systemctl enable --runtime /usr/share/oem/system/*
systemctl start oem.target
/usr/bin/systemd-run --unit=cloudinit-init /usr/bin/coreos-cloudinit --from-file=/usr/share/oem/init.yml
/usr/bin/systemd-run --unit=nova-agent-watcher /usr/share/oem/usr/bin/nova-agent-watcher -watch-dir=/usr/share/oem/nova-agent -scripts-dir=/usr/share/oem/usr/bin/

View File

@ -1,12 +0,0 @@
#!/bin/bash
AGENT_ROOT="/usr/share/oem/nova-agent"
/bin/mount --bind /proc ${AGENT_ROOT}/proc
/bin/mount -t xenfs none ${AGENT_ROOT}/proc/xen
/bin/mount --bind /dev ${AGENT_ROOT}/dev
/bin/mount --bind /sys ${AGENT_ROOT}/sys
/usr/bin/chroot /usr/share/oem/nova-agent/ /bin/sh -c "HOME=/root /usr/share/nova-agent/0.0.1.38/sbin/nova-agent -o - -n -l info /usr/share/nova-agent/nova-agent.py"
/bin/umount ${AGENT_ROOT}/proc/xen
/bin/umount ${AGENT_ROOT}/proc
/bin/umount ${AGENT_ROOT}/dev
/bin/umount ${AGENT_ROOT}/sys

View File

@ -1,10 +0,0 @@
#!/bin/bash
OEM_DIR="/usr/share/oem"
SSH_CONF=$OEM_DIR/nova-agent/root/.ssh/authorized_keys
while [ ! -e ${SSH_CONF} ]; do
echo waiting...
sleep .1
done
/usr/bin/update-ssh-keys -a nova-agent /usr/share/oem/nova-agent/root/.ssh/authorized_keys

View File

@ -1,5 +0,0 @@
[Service]
ExecStart=/usr/share/oem/usr/bin/run-nova-agent.sh
[Install]
WantedBy=multi-user.target

View File

@ -1,9 +0,0 @@
[Unit]
Description=CoreOS Rackspace OEM Target
Wants=nova-agent.service
Wants=setup-networking.service
Wants=setup-ssh.service
Wants=setup-resolvconf.service
[Install]
WantedBy=multi-user.target

View File

@ -1,7 +0,0 @@
[Service]
Type=oneshot
ExecStartPre=/usr/bin/systemctl stop dhcpcd
ExecStart=/usr/bin/timeout 60 /usr/share/oem/usr/bin/net.sh
[Install]
WantedBy=multi-user.target

View File

@ -1,7 +0,0 @@
[Service]
Type=oneshot
ExecStartPre=/usr/bin/systemctl stop dhcpcd
ExecStart=/usr/bin/timeout 60 /usr/share/oem/usr/bin/resolvconf.sh
[Install]
WantedBy=multi-user.target

View File

@ -1,6 +0,0 @@
[Service]
Type=oneshot
ExecStart=/usr/bin/timeout 60 /usr/share/oem/usr/bin/ssh.sh
[Install]
WantedBy=multi-user.target

View File

@ -20,15 +20,14 @@ IUSE=""
EGIT_REPO_URI="https://github.com/coreos/nova-agent-container.git"
EGIT_COMMIT="44af5608e9a9e43fe83d05f03049a1f66d564930"
RDEPEND="
coreos-base/nova-agent-watcher
"
src_install() {
rsync --exclude=".git" -aq ${S}/ ${D}/nova-agent/
rsync -aq ${FILESDIR}/systemd/ ${D}/system/
dobin "${FILESDIR}"/ifconfig.sh
dobin "${FILESDIR}"/net.sh
dobin "${FILESDIR}"/ssh.sh
dobin "${FILESDIR}"/run-nova-agent.sh
dobin "${FILESDIR}"/resolvconf.sh
exeinto "/"
doexe ${FILESDIR}/run
insinto "/"
doins ${FILESDIR}/init.yml
}