summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@nelson>2010-01-07 21:40:44 -0500
committerScott Moser <smoser@nelson>2010-01-07 21:40:44 -0500
commit41268c94d0f832d6a6dade0fffb7ddc0cd7a1a6c (patch)
treec578859cbdf70d38af582b00d1f81229fbee62c4
parent938ba376f2c7551a471991b4046e11a4f92f30d5 (diff)
downloadvyos-cloud-init-41268c94d0f832d6a6dade0fffb7ddc0cd7a1a6c.tar.gz
vyos-cloud-init-41268c94d0f832d6a6dade0fffb7ddc0cd7a1a6c.zip
remove dead/unused code, call this 0.5.0
-rwxr-xr-xec2-fetch-credentials.py67
-rwxr-xr-xec2-init-appliance-ebs-volume-mount.sh48
-rwxr-xr-xec2-run-user-data.py179
-rwxr-xr-xec2-set-defaults.py64
-rwxr-xr-xec2-set-hostname.py33
-rwxr-xr-xec2-wait-for-meta-data-service.py33
-rw-r--r--ec2init-disable.conf24
-rw-r--r--ec2init.conf.goal14
-rw-r--r--ec2init/DataSourceEc2.py33
-rw-r--r--ec2init/__init__.py1
-rwxr-xr-xsetup.py12
11 files changed, 3 insertions, 505 deletions
diff --git a/ec2-fetch-credentials.py b/ec2-fetch-credentials.py
deleted file mode 100755
index c4df4a4e..00000000
--- a/ec2-fetch-credentials.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/python
-#
-# Fetch login credentials for EC2
-# Copyright (C) 2008-2009 Canonical Ltd.
-#
-# Author: Soren Hansen <soren@canonical.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 3, as
-# published by the Free Software Foundation.
-#
-# 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 os
-import pwd
-import sys
-
-import ec2init
-
-def setup_user_keys(keys, user, key_prefix):
- saved_umask = os.umask(077)
-
- pwent = pwd.getpwnam(user)
-
- ssh_dir = '%s/.ssh' % pwent.pw_dir
- if not os.path.exists(ssh_dir):
- os.mkdir(ssh_dir)
- os.chown(ssh_dir, pwent.pw_uid, pwent.pw_gid)
-
- authorized_keys = '%s/.ssh/authorized_keys' % pwent.pw_dir
- fp = open(authorized_keys, 'a')
- fp.write(''.join(['%s%s\n' % (key_prefix, key) for key in keys]))
- fp.close()
-
- os.chown(authorized_keys, pwent.pw_uid, pwent.pw_gid)
-
- os.umask(saved_umask)
-
-def main():
- ec2 = ec2init.EC2Init()
-
- user = ec2.get_cfg_option_str('user')
- disable_root = ec2.get_cfg_option_bool('disable_root', True)
-
- try:
- keys = ec2.get_ssh_keys()
- except Exception, e:
- sys.exit(1)
-
- if user:
- setup_user_keys(keys, user, '')
-
- if disable_root:
- key_prefix = 'command="echo \'Please login as the ubuntu user rather than root user.\';echo;sleep 10" '
- else:
- key_prefix = ''
-
- setup_user_keys(keys, 'root', key_prefix)
-
-if __name__ == '__main__':
- main()
diff --git a/ec2-init-appliance-ebs-volume-mount.sh b/ec2-init-appliance-ebs-volume-mount.sh
deleted file mode 100755
index de3c63ca..00000000
--- a/ec2-init-appliance-ebs-volume-mount.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-
-if [ -n "$EBSMOUNT_DEBUG" ]
-then
- do="echo"
- mktemp_args="-u"
-else
- do=""
- mktemp_args=""
-fi
-
-if [ "$#" -lt 2 ]
-then
- echo "Usage: $0 <EBS device> <path> [<path> [<path>...]]"
- exit 1
-fi
-
-ebs_volume_device="$1"
-shift
-
-canonicalise_dir() {
- dirname="$1"
- echo "${dirname}" | sed -e 's/[^a-zA-Z0-9]/_/g'
-}
-
-# The blkid call will detect whether there's already a filesystem on the EBS volume
-if [ -n "$(blkid -p -o udev "${ebs_volume_device}")" ]
-then
- $do mkfs.ext3 "${ebs_volume_device}"
-fi
-
-tmpdir="$(mktemp -d $mktemp_args --tmpdir=/var/run/ec2)"
-$do mount ${ebs_volume_device} ${tmpdir}
-
-for dir in "$@"
-do
- ebsdir="${tmpdir}/$(canonicalise_dir "${dir}")"
- if [ ! -d "${ebsdir}" ]
- then
- # We bootstrap the storage with the existing data
- $do mkdir "${ebsdir}"
- $do cp -a ${dir} "${ebsdir}"
- $do chown --reference "${dir}" "${ebsdir}"
- $do chmod --reference "${dir}" "${ebsdir}"
- fi
- # Finally, we mount it on top of the old directory.
- $do mount --bind "${ebsdir}" "${dir}"
-done
diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py
deleted file mode 100755
index 2108e0a0..00000000
--- a/ec2-run-user-data.py
+++ /dev/null
@@ -1,179 +0,0 @@
-#!/usr/bin/python
-#
-# Fetch and run user-data from EC2
-# Copyright (C) 2008-2009 Canonical Ltd.
-#
-# Author: Soren Hansen <soren@canonical.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 3, as
-# published by the Free Software Foundation.
-#
-# 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 email
-import os
-import subprocess
-import tempfile
-from xml.dom.minidom import parse, parseString
-
-import ec2init
-
-content_type_handlers = {}
-
-def handler(mimetype):
- return lambda f: register_handler(mimetype, f)
-
-def register_handler(mimetype, func):
- content_type_handlers[mimetype] = func
- return func
-
-def handle_part(part):
- if part.is_multipart():
- for p in part.get_payload():
- handle_part(p)
- else:
- if part.get_content_type() in content_type_handlers:
- content_type_handlers[part.get_content_type](part.get_payload())
- return
-
- handle_unknown_payload(part.get_payload())
-
-def handle_unknown_payload(payload):
- # Try to detect magic
- if payload.startswith('#!'):
- content_type_handlers['text/x-shellscript'](payload)
- return
- if payload.startswith('<appliance>'):
- content_type_handlers['text/x-appliance-config'](payload)
-
-@handler('text/x-appliance-config')
-def handle_appliance_config(payload):
- app = ApplianceConfig(payload)
- app.handle()
-
-@handler('text/x-ebs-mount-description')
-def handle_ebs_mount_description(payload):
- (volume_description, paths) = payload.split(':')
- (identifier_type, identifier) = volume_description.split('=')
-
- if identifier_type == 'device':
- device = identifier
-# Perhaps some day the volume id -> device path mapping
-# will be exposed through meta-data.
-# elif identifier_type == 'volume':
-# device = extract_device_name_from_meta_data
- else:
- return
-
- mount_ebs_volume(device, paths.split(','))
-
-def mount_ebs_volume(device, paths):
- if os.path.exists('ec2-init-appliance-ebs-volume-mount.sh'):
- helper = './ec2-init-appliance-ebs-volume-mount.sh'
- else:
- helper = '/usr/share/ec2-init/ec2-init-appliance-ebs-volume-mount.sh'
- helper = subprocess.Popen([helper, device] + paths, stdout=subprocess.PIPE)
- stdout, stderr = helper.communicate()
- return stdout
-
-@handler('text/x-shellscript')
-def handle_shell_script(payload):
- (fd, path) = tempfile.mkstemp()
- fp = os.fdopen(fd, 'a')
- fp.write(payload)
- fp.close()
- os.chmod(path, 0700)
-
- # Run the user data script and pipe its output to logger
- user_data_process = subprocess.Popen([path], stdout=subprocess.PIPE)
- logger_process = subprocess.Popen(['logger', '-t', 'user-data'], stdin=user_data_process.stdout)
- logger_process.communicate()
-
- os.unlink(path)
-
-class ApplianceConfig(object):
- def __init__(self, data):
- self.data = data
-
- def handle(self):
- self.dom = parseString(self.data)
-
- if self.dom.childNodes[0].tagName == 'appliance':
- root = self.dom.childNodes[0]
- else:
- return
-
- for node in root.childNodes:
- if node.tagName == 'package':
- pkg = None
- for subnode in node.childNodes:
- if subnode.nodeType == root.TEXT_NODE:
- pkg = subnode.nodeValue
- if not pkg:
- # Something's fishy. We should have been passed the name of
- # a package.
- return
- if node.getAttribute('action') == 'remove':
- remove_package(pkg)
- else:
- install_package(pkg)
- elif node.tagName == 'script':
- script = ''
- for subnode in node.childNodes:
- # If someone went through the trouble of wrapping it in CDATA,
- # it's probably the script we want to run..
- if subnode.nodeType == root.CDATA_SECTION_NODE:
- script = subnode.nodeValue
- # ..however, fall back to whatever TEXT_NODE stuff is between
- # the <script> tags.
- if subnode.nodeType == root.TEXT_NODE and not script:
- script = subnode.nodeValue
- if not script:
- # An empty script?
- continue
- content_type_handlers['text/x-shellscript'](script)
- elif node.tagName == 'storage':
- paths = []
- device = node.getAttribute('device')
- for subnode in node.childNodes:
- if subnode.tagName == 'path':
- for subsubnode in subnode.childNodes:
- if subsubnode.nodeType == root.TEXT_NODE:
- paths += [subsubnode.nodeValue.strip()]
- break
- mount_ebs_volume(device, paths)
-
-def main():
- ec2 = ec2init.EC2Init()
-
- user_data = get_user_data()
- msg = parse_user_data(user_data)
- handle_part(msg)
-
-def get_user_data():
- return ec2.get_user_data()
-
-def parse_user_data(user_data):
- return email.message_from_string(user_data)
-
-def install_remove_package(pkg, action):
- apt_get = subprocess.Popen(['apt-get', action, pkg], stdout=subprocess.PIPE)
- logger_process = subprocess.Popen(['logger', '-t', 'user-data'], stdin=apt_get.stdout)
- logger_process.communicate()
-
-def install_package(pkg):
- return install_remove_package(pkg, 'install')
-
-def remove_package(pkg):
- return install_remove_package(pkg, 'remove')
-
-if __name__ == '__main__':
- main()
diff --git a/ec2-set-defaults.py b/ec2-set-defaults.py
deleted file mode 100755
index 364225aa..00000000
--- a/ec2-set-defaults.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/python
-#
-# Fetch the availabity zone and create the sources.list
-# Copyright (C) 2008-2009 Canonical Ltd.
-#
-# Authors: Chuck Short <chuck.short@canonical.com>
-# Soren Hansen <soren@canonical.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 3, as
-# published by the Free Software Foundation.
-#
-# 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 subprocess
-from Cheetah.Template import Template
-
-import ec2init
-
-def main():
- ec2 = ec2init.EC2Init()
-
- availability_zone = ec2.get_availability_zone()
-
- try:
- location = ec2.get_location_from_availability_zone(availability_zone)
- locale = ec2.location_locale_map[location]
- except Exception, e:
- locale = "en_US.UTF-8"
-
- # get_mirror_from_availability_zone returns default on no match
- mirror = ec2.get_mirror_from_availability_zone(availability_zone)
-
- apply_locale(locale)
-
- generate_sources_list(mirror)
-
-def render_to_file(template, outfile, searchList):
- t = Template(file='/etc/ec2-init/templates/%s.tmpl' % template, searchList=[searchList])
- f = open(outfile, 'w')
- f.write(t.respond())
- f.close()
-
-def apply_locale(locale):
- subprocess.Popen(['locale-gen', locale]).communicate()
- subprocess.Popen(['update-locale', locale]).communicate()
-
- render_to_file('default-locale', '/etc/default/locale', { 'locale' : locale })
-
-def generate_sources_list(mirror):
- stdout, stderr = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).communicate()
- codename = stdout.strip()
-
- render_to_file('sources.list', '/etc/apt/sources.list', { 'mirror' : mirror, 'codename' : codename })
-
-if __name__ == '__main__':
- main()
diff --git a/ec2-set-hostname.py b/ec2-set-hostname.py
deleted file mode 100755
index cc22f046..00000000
--- a/ec2-set-hostname.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/python
-#
-# Set instance hostname to the localhostname defined by the EC2 meta-data
-# service
-# Copyright (C) 2008-2009 Canonical Ltd.
-#
-# Authors: Chuck Short <chuck.short@canonical.com>
-# Soren Hansen <soren@canonical.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 3, as
-# published by the Free Software Foundation.
-#
-# 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 subprocess
-
-import ec2init
-
-def main():
- ec2 = ec2init.EC2Init()
-
- hostname = ec2.get_hostname()
- subprocess.Popen(['hostname', hostname]).communicate()
-
-if __name__ == '__main__':
- main()
diff --git a/ec2-wait-for-meta-data-service.py b/ec2-wait-for-meta-data-service.py
deleted file mode 100755
index a2759f37..00000000
--- a/ec2-wait-for-meta-data-service.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/python
-#
-# Wait for the meta-data service to turn up. If it never does, execute
-# the configured bailout
-# Copyright (C) 2009 Canonical Ltd.
-#
-# Author: Soren Hansen <soren@canonical.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 3, as
-# published by the Free Software Foundation.
-#
-# 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 sys
-
-import ec2init
-
-def main():
- ec2 = ec2init.EC2Init()
- if ec2.wait_or_bail():
- sys.exit(0)
- else:
- sys.exit(1)
-
-if __name__ == '__main__':
- main()
diff --git a/ec2init-disable.conf b/ec2init-disable.conf
deleted file mode 100644
index b9d57f06..00000000
--- a/ec2init-disable.conf
+++ /dev/null
@@ -1,24 +0,0 @@
-start on startup
-normal exit 0 1
-
-console output
-
-script
- set +e
- i=0
- while ! touch /etc/TEST >/dev/null 2>&1; do
- echo "DISABLER: waiting for writable /"
- sleep 1
- i=$(($i+1))
- [ $i -lt 30 ] || { echo "DISABLER: bailing"; exit 0; }
- done
- f="/etc/init/ec2init.conf"
- [ -e "$f" ] || { echo "DISABLER: no ${f}, exiting"; exit 0; }
- echo "DISABLER: sleeping 5, then disabling ${f}"
- sleep 5
- mv "${f}" "${f}.disabled" &&
- echo "DISABLER: disabled ${f}" ||
- echo "DISABLER: failed mv ${f} ${f}.disabled"
- exit 0
-end script
-
diff --git a/ec2init.conf.goal b/ec2init.conf.goal
deleted file mode 100644
index 8ee2abef..00000000
--- a/ec2init.conf.goal
+++ /dev/null
@@ -1,14 +0,0 @@
-## Hopefully, this is all we need sometime in the future for
-## the ec2init.conf. It will get called as soon as
-## eth0 comes up and / is mounted rw
-##
-## it requires
-## newer mountall than 1.1 (for 'mounted' events)
-##
-start on (mounted MOUNTPOINT=/ and net-device-up IFACE=eth0)
-
-task
-
-console output
-
-exec /usr/bin/ec2-init start
diff --git a/ec2init/DataSourceEc2.py b/ec2init/DataSourceEc2.py
index cdea0b3e..c7415c0a 100644
--- a/ec2init/DataSourceEc2.py
+++ b/ec2init/DataSourceEc2.py
@@ -9,7 +9,6 @@ import cPickle
class DataSourceEc2(DataSource.DataSource):
api_ver = '2009-04-04'
- conffile = '/etc/ec2-init/ec2-config.cfg'
cachedir = ec2init.cachedir + '/ec2'
location_locale_map = {
@@ -47,31 +46,6 @@ class DataSourceEc2(DataSource.DataSource):
def get_instance_id(self):
return(self.metadata['instance-id'])
- def wait_or_bail(self):
- if self.wait_for_metadata_service():
- return True
- else:
- bailout_command = self.get_cfg_option_str('bailout_command')
- if bailout_command:
- os.system(bailout_command)
- return False
-
- def get_cfg_option_str(self, key, default=None):
- return self.config.get(key, default)
-
- def get_ssh_keys(self):
- conn = urllib2.urlopen('%s/public-keys/' % self.meta_data_base_url)
- data = conn.read()
- keyids = [line.split('=')[0] for line in data.split('\n')]
- return [urllib2.urlopen('%s/public-keys/%d/openssh-key' % (self.meta_data_base_url, int(keyid))).read().rstrip() for keyid in keyids]
-
-# def get_userdata(self):
-# return boto.utils.get_instance_userdata()
-#
-# def get_instance_metadata(self):
-# self.instance_metadata = getattr(self, 'instance_metadata', boto.utils.get_instance_metadata())
-# return self.instance_metadata
-
def get_availability_zone(self):
return(self.metadata['placement']['availability-zone'])
@@ -118,13 +92,6 @@ class DataSourceEc2(DataSource.DataSource):
#timeout = timeout * 2
return False
- def get_location_from_availability_zone(self, availability_zone):
- if availability_zone.startswith('us-'):
- return 'us'
- elif availability_zone.startswith('eu-'):
- return 'eu'
- raise Exception('Could not determine location')
-
def get_public_ssh_keys(self):
keys = []
if not self.metadata.has_key('public-keys'): return([])
diff --git a/ec2init/__init__.py b/ec2init/__init__.py
index 270414f7..d9d24969 100644
--- a/ec2init/__init__.py
+++ b/ec2init/__init__.py
@@ -82,7 +82,6 @@ class EC2Init:
self.datasource = s
return
except Exception as e:
- print e
pass
raise Exception("Could not find data source")
diff --git a/setup.py b/setup.py
index 55ec31d1..4b4d0ae7 100755
--- a/setup.py
+++ b/setup.py
@@ -23,25 +23,19 @@ import os.path
import subprocess
setup(name='EC2-init',
- version='0.4.999',
+ version='0.5.0',
description='EC2 initialisation magic',
author='Soren Hansen',
author_email='soren@canonical.com',
url='http://launchpad.net/ec2-init/',
packages=['ec2init'],
- scripts=['ec2-fetch-credentials.py',
- 'ec2-get-info.py',
- 'ec2-run-user-data.py',
- 'ec2-set-defaults.py',
- 'ec2-set-hostname.py',
- 'ec2-wait-for-meta-data-service.py',
- 'ec2-init.py',
+ scripts=['ec2-init.py',
'ec2-is-compat-env',
'cloud-init-run-module.py'
],
data_files=[('/etc/ec2-init', ['ec2-config.cfg']),
('/etc/ec2-init/templates', glob('templates/*')),
('/etc/init', glob('upstart/*.conf')),
- ('/usr/share/ec2-init', ['ec2-init-appliance-ebs-volume-mount.sh']),
+ ('/usr/share/ec2-init', []),
],
)