summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuck Short <zulcss@ubuntu.com>2009-02-09 19:12:09 +0000
committerBazaar Package Importer <jamesw@ubuntu.com>2009-02-09 19:12:09 +0000
commitdc70c714cd797194fd84ed53f947b7d536b60624 (patch)
tree79738235d552663619932980d46f9a9e004aeb2e
parentd6ccf71ac3d670cd3539234728c1a93fde05c775 (diff)
downloadcloud-init-git-ubuntu-0.3.3.tar.gz
* ec2-set-apt-sources.pyubuntu-0.3.3
- Determine the zone that the user is in and generate a /etc/apt/sources.list.d/ based on that. * debian/init: - Check to see if there is an /var/run/ec2 and create it if it doesnt exist. - Start ec2-set-apt-sources at first bootup. * debian/rules: - Install ec2-set-apt-sources. * debian/control: - Add python-configobj as a dependency. * debian/{install,dirs} - Create an /etc/ec2-init to read the configuration file and install it.
-rw-r--r--debian/changelog18
-rw-r--r--debian/control2
-rw-r--r--debian/dirs1
-rw-r--r--debian/ec2-config.cfg2
-rw-r--r--debian/init11
-rw-r--r--debian/install1
-rwxr-xr-xdebian/rules2
-rwxr-xr-xec2-set-apt-sources.py45
8 files changed, 81 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog
index 1f720438..643e509b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,21 @@
+ec2-init (0.3.3) jaunty; urgency=low
+
+ * ec2-set-apt-sources.py
+ - Determine the zone that the user is in and generate
+ a /etc/apt/sources.list.d/ based on that.
+ * debian/init:
+ - Check to see if there is an /var/run/ec2 and create
+ it if it doesnt exist.
+ - Start ec2-set-apt-sources at first bootup.
+ * debian/rules:
+ - Install ec2-set-apt-sources.
+ * debian/control:
+ - Add python-configobj as a dependency.
+ * debian/{install,dirs}
+ - Create an /etc/ec2-init to read the configuration file and install it.
+
+ -- Chuck Short <zulcss@ubuntu.com> Mon, 09 Feb 2009 10:35:56 -0500
+
ec2-init (0.3.2) jaunty; urgency=low
* debian/init:
diff --git a/debian/control b/debian/control
index 4505cbaf..2eb50d17 100644
--- a/debian/control
+++ b/debian/control
@@ -7,7 +7,7 @@ Standards-Version: 3.8.0
Package: ec2-init
Architecture: i386 amd64
-Depends: python, procps
+Depends: python, procps, python-configobj
Description: Init scripts for EC2 instances
EC2 instances need special scripts to run during initialisation
to retrieve and install ssh keys and to let the user run various scripts.
diff --git a/debian/dirs b/debian/dirs
index 19be79b3..3c349733 100644
--- a/debian/dirs
+++ b/debian/dirs
@@ -1,2 +1,3 @@
var/ec2
usr/sbin
+etc/ec2-init
diff --git a/debian/ec2-config.cfg b/debian/ec2-config.cfg
new file mode 100644
index 00000000..aa6757e2
--- /dev/null
+++ b/debian/ec2-config.cfg
@@ -0,0 +1,2 @@
+user="ubuntu"
+distro="jaunty"
diff --git a/debian/init b/debian/init
index e28edd06..1e5a36c1 100644
--- a/debian/init
+++ b/debian/init
@@ -16,6 +16,10 @@ NAME=ec2-init
. /lib/lsb/init-functions
+if [ ! -d /var/run/ec2 ]; then
+ mkdir /var/run/ec2
+fi
+
case "$1" in
start)
log_daemon_msg "Fetching EC2 login credentials"
@@ -51,6 +55,13 @@ case "$1" in
else
log_end_msg 1
fi
+ log_daemon_msg "Determining EC2 availability zone"
+ if ec2-set-apt-sources.py 2> /dev/null
+ then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
;;
stop)
diff --git a/debian/install b/debian/install
index 54a21487..c9b3c391 100644
--- a/debian/install
+++ b/debian/install
@@ -1 +1,2 @@
debian/tmp/usr/sbin/*
+debian/ec2-config.cfg etc/ec2-init
diff --git a/debian/rules b/debian/rules
index f3f8d30f..dbdd8253 100755
--- a/debian/rules
+++ b/debian/rules
@@ -7,6 +7,8 @@ DEB_UPDATE_RCD_PARAMS:= start 90 2 3 4 5 . stop 20 1 .
build/ec2-init::
install -d debian/tmp/usr/sbin
mkdir -p debian/tmp/var/ec2
+ mkdir -p debian/tmp/etc/ec2-init
install -m 775 ec2-fetch-credentials.py debian/tmp/usr/sbin/ec2-fetch-credentials
install -m 775 ec2-run-user-data.py debian/tmp/usr/sbin/ec2-run-user-data
install -m 755 ec2-set-hostname.py debian/tmp/usr/sbin/ec2-set-hostname
+ install -m 755 ec2-set-apt-sources.py debian/tmp/usr/sbin/ec2-set-apt-sources
diff --git a/ec2-set-apt-sources.py b/ec2-set-apt-sources.py
new file mode 100755
index 00000000..d6535013
--- /dev/null
+++ b/ec2-set-apt-sources.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+#
+# Fetch the availabity zone and create the sources.list
+# Copyright 2009 Canonical Ltd.
+#
+# Author: Chuck Short <chuck.short@canonical.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import urllib
+import os
+from configobj import ConfigObj
+
+api_ver = '2008-02-01'
+metadata = None
+filename='/etc/ec2/ec2-init.cfg'
+
+base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
+zone = urllib.urlopen('%s/placement/availability-zone' % base_url).read()
+
+if zone.startswith("us"):
+ archive = "http://us.ec2.archive.ubuntu.com/ubuntu"
+elif zone.startswith("eu"):
+ archive = "http://eu.ec2.archive.ubuntu.com/ubuntu"
+
+config = ConfigObj(filename)
+distro = config['distro']
+
+f = open("/var/run/ec2/sources.list", "w")
+f.write('deb %s %s main universe\n' % (archive,distro))
+f.write('deb %s %s-updates main restricted universe\n' % (archive,distro))
+f.close()
+os.system("ln -s /var/run/ec2/sources.list /etc/apt/sources.list.d/amazon.list")