From 41268c94d0f832d6a6dade0fffb7ddc0cd7a1a6c Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 7 Jan 2010 21:40:44 -0500 Subject: remove dead/unused code, call this 0.5.0 --- ec2-fetch-credentials.py | 67 ------------ ec2-init-appliance-ebs-volume-mount.sh | 48 --------- ec2-run-user-data.py | 179 --------------------------------- ec2-set-defaults.py | 64 ------------ ec2-set-hostname.py | 33 ------ ec2-wait-for-meta-data-service.py | 33 ------ ec2init-disable.conf | 24 ----- ec2init.conf.goal | 14 --- ec2init/DataSourceEc2.py | 33 ------ ec2init/__init__.py | 1 - setup.py | 12 +-- 11 files changed, 3 insertions(+), 505 deletions(-) delete mode 100755 ec2-fetch-credentials.py delete mode 100755 ec2-init-appliance-ebs-volume-mount.sh delete mode 100755 ec2-run-user-data.py delete mode 100755 ec2-set-defaults.py delete mode 100755 ec2-set-hostname.py delete mode 100755 ec2-wait-for-meta-data-service.py delete mode 100644 ec2init-disable.conf delete mode 100644 ec2init.conf.goal 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 -# -# 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 . -# -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 [ [...]]" - 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 -# -# 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 . -# - -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(''): - 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