From 385eac14a1ed8e7554119b35146c95055fdb0332 Mon Sep 17 00:00:00 2001 From: Olivier Sallou Date: Thu, 1 Aug 2013 08:34:20 +0200 Subject: [PATCH] remove tasks ot required by raw provider, fix provider name in plugins after renaming from one to raw --- .../{raw-ide.manifest => one-ide.manifest} | 11 ++- plugins/opennebula/opennebula.py | 2 +- plugins/user_packages/user_packages.py | 6 +- providers/raw/__init__.py | 6 -- providers/raw/assets/one-context_3.8.1.deb | Bin 3790 -> 0 bytes providers/raw/assets/one-ec2.sh | 14 --- providers/raw/assets/one-pubkey.sh | 17 ---- providers/raw/tasks/ami.py | 76 --------------- providers/raw/tasks/boot.py | 5 - providers/raw/tasks/connection.py | 40 -------- providers/raw/tasks/ebs.py | 89 ------------------ providers/raw/tasks/one.py | 39 -------- 12 files changed, 11 insertions(+), 294 deletions(-) rename manifests/{raw-ide.manifest => one-ide.manifest} (83%) delete mode 100644 providers/raw/assets/one-context_3.8.1.deb delete mode 100755 providers/raw/assets/one-ec2.sh delete mode 100755 providers/raw/assets/one-pubkey.sh delete mode 100644 providers/raw/tasks/ami.py delete mode 100644 providers/raw/tasks/connection.py delete mode 100644 providers/raw/tasks/ebs.py delete mode 100644 providers/raw/tasks/one.py diff --git a/manifests/raw-ide.manifest b/manifests/one-ide.manifest similarity index 83% rename from manifests/raw-ide.manifest rename to manifests/one-ide.manifest index 913c8ac..7dc267c 100644 --- a/manifests/raw-ide.manifest +++ b/manifests/one-ide.manifest @@ -1,6 +1,6 @@ { - "provider" : "one", - "virtualization": "virtio", + "provider" : "raw", + "virtualization": "ide", "credentials" : { "access-key": null, "secret-key": null, @@ -9,13 +9,13 @@ "bootstrapper": { "mount_dir": "/mnt/target", - "image_file": "/tmp/target", + "image_file": "/tmp/one.img", "tarball": true, "device": "/dev/sda" }, "image": { "name" : "debian-{release}-{architecture}-{virtualization}-{%y}{%m}{%d}", - "description": "Debian {release} {architecture} Open Nebula ({virtualization})" + "description": "Debian {release} {architecture} ({virtualization})" }, "system": { "release" : "wheezy", @@ -42,6 +42,9 @@ "enabled": false, "snapshot": "" }, + "opennebula": { + "enabled": true + }, "user_packages": { "enabled": true, "repo": [ "apache2" ], diff --git a/plugins/opennebula/opennebula.py b/plugins/opennebula/opennebula.py index 1899127..df50a4b 100644 --- a/plugins/opennebula/opennebula.py +++ b/plugins/opennebula/opennebula.py @@ -1,7 +1,7 @@ from base import Task from common import phases import os -from providers.one.tasks.locale import GenerateLocale +from providers.raw.tasks.locale import GenerateLocale class OpenNebulaContext(Task): diff --git a/plugins/user_packages/user_packages.py b/plugins/user_packages/user_packages.py index 296c536..e1093ca 100644 --- a/plugins/user_packages/user_packages.py +++ b/plugins/user_packages/user_packages.py @@ -1,9 +1,9 @@ from base import Task from common import phases import os -from providers.one.tasks.packages import ImagePackages -from providers.one.tasks.host import CheckPackages -from providers.one.tasks.filesystem import MountVolume +from providers.raw.tasks.packages import ImagePackages +from providers.raw.tasks.host import CheckPackages +from providers.raw.tasks.filesystem import MountVolume class AddUserPackages(Task): diff --git a/providers/raw/__init__.py b/providers/raw/__init__.py index bdf9fba..2cd2f36 100644 --- a/providers/raw/__init__.py +++ b/providers/raw/__init__.py @@ -1,10 +1,7 @@ from manifest import Manifest import logging from tasks import packages -from tasks import connection from tasks import host -from tasks import ami -from tasks import ebs from tasks import filesystem from tasks import bootstrap from tasks import locale @@ -15,7 +12,6 @@ from tasks import network from tasks import initd from tasks import cleanup from tasks import fake -from tasks import one def initialize(): @@ -35,7 +31,6 @@ def tasks(tasklist, manifest): tasklist.add(filesystem.TuneVolumeFS()) tasklist.add(filesystem.CreateMountDir(), filesystem.MountVolume()) - #tasklist.add(filesystem.InstallMbr()) if manifest.bootstrapper['tarball']: tasklist.add(bootstrap.MakeTarball()) tasklist.add(bootstrap.Bootstrap(), @@ -59,7 +54,6 @@ def tasks(tasklist, manifest): network.ConfigureDHCP(), initd.ResolveInitScripts(), initd.InstallInitScripts(), - one.OpenNebulaContext(), cleanup.ClearMOTD(), cleanup.ShredHostkeys(), cleanup.CleanTMP(), diff --git a/providers/raw/assets/one-context_3.8.1.deb b/providers/raw/assets/one-context_3.8.1.deb deleted file mode 100644 index 2e811888cea425ba65bfc79e38aaad169ce23bdb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3790 zcmai$XD}R$_QplYvP5U~5-pcgH`_DV~KX>l^be}o%%=vK6`SQ&C=I|>!1~|K^0H3%xxjXtuIJx^c20RDz z@kzl!K;&g*`S||S{|gS3mV^MEeSLxge7z)t90Mc~q2T|y zFC{Id@UH`KAa4>S$>3F*F$vkOg}3jVJpC|&@XBVqM3+@JazKCERm*P9=5=c@y`pHe zBc)p+DzU#z`;mX4H!(uT+9R97x`AI8YCxA}#h5y>uvzt`?|6!bTdt>b(f%aq?8rCR z&UYd>WE*ff6v|YLpY}|an+dxbotk>&T}Ao~Xi3y=w&&AgKFHhDIdY`_iurO0-9o+q zc^Zc`Cg@ddf#Xc1BQ<#)s*r8g7<1x%+nOyRxk5#!P$7!-K_^!j^NbE`IB(qc6|3w5 z$fuCzSx2mPL9j*)d(2B47!!luWVBJ+fdI{hW@Z!6b-u2n3~1=im3f*)9fSPj1&F_A z$oSz~!Mnx0)~L4_;fN@$1ZUQJDwy6OaDQ*TlTohFh8Ft8*@FTKW>i8&J%8UTee4j5 zf~~gn=YwJEjK8I1gx#MP^?Z&t9M5ZgWT>0Fsdn&0O9QUF#*tyZm3C+TW8O_50v|Q9 z+wkBn8$TBE-i?7|=B4CxP;@fmc$!@l{ALv;KP7)XUY}E#ri%GiKp?A3pzpS+Bd1hx zg*;=7FMEi1S*z{mrf%b0(&(>`M3c|u{<7}8t2%$Tv&bz|IJk0QPW0Je78ImW;wbYd zfOesz7(2_!>+LX8FwbObf^FDAzuHx)C@bsv`behR!?uB5aux+Yyndgw_8lD)xxQ+L z57+wPp2fqTo>ZO&(JH+%CMl|2mL9}p?M55&Ro6T%1f3lPSS;6Gb6;DogeFeBTmzgv zQ)z!kd^5DrW^;rwIVOs9_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XR42*{T@ZvCjM-lN$I}VNlgnD==i0*}0PYawxo z>5DQyfYO+IJ={+B*SRYAYoRy!3`*1R_yn1HGLCkyeFsNdv$MR%^y*K9joGrCELeLd5dd_m z-|yvMGDD(x}kg@m=^8;_m9epPQmBDdZn_Q0DH z2<~`4Ahl_z^t!XaKo0GD2j-WJMuIj&IkXAHmr1Gt{FUlo z(Byqy>0(&Oz4WE48>6*OSJxTvm#WI?cZypxQH_k;XGtEUrG{UowXUn#&K;iK^SY%u z*|UgPE2&2{N|cHOEa0px;}5$_^a!k7kejr3-hl zUMTUXX#I&Pprx=(3m=@HvldVzCm^njPdS~tru96i1-we2Tea?ApJG0W@xK&DTGV6( z%^V{XCuP#(D22sOyu}2y5dFBO*Lw-1RpCDhLP3HvmyaB$>+wh1n);S*1FJ3Y4x<>t zRYPFVU27?ykK!&uM!jJFOzbiEiBeMX&&|VR&$z5M;|DVG&wGS<1FeY3JvOdg4%r4@8 z+aR#+{1zci>ZXyXtTdLCEQo4`qgSBu#w=-+iUEDzE`??ek>dmZc z&XM2Ai-c#4Qqlx5twopK&29|unm?!rln@=r^PYwK zIHgQ?DGv+jWz@qIthpYG6TDXF8%GqF9K{X5FGLS zdniRn=0wZJ0)^2HfQE%hA91;rUZd#=dka;ueJ{%hNwdBTyav7CE8@d83j%TJy_zIJ z{dK`F*cE67d_@?6Y`I+Vl3Da1(Ipq3c5Vr*YVYK}*ve}bth)^!RTvt> /root/.ssh/authorized_keys - -done diff --git a/providers/raw/tasks/ami.py b/providers/raw/tasks/ami.py deleted file mode 100644 index fbabbf3..0000000 --- a/providers/raw/tasks/ami.py +++ /dev/null @@ -1,76 +0,0 @@ -from base import Task -from common import phases -from ebs import CreateSnapshot -from connection import Connect -from common.exceptions import TaskError - - -class AMIName(Task): - description = 'Determining the AMI name' - phase = phases.preparation - after = [Connect] - - def run(self, info): - image_vars = {'release': info.manifest.system['release'], - 'architecture': info.manifest.system['architecture'], - 'virtualization': info.manifest.virtualization, - 'backing': info.manifest.volume['backing']} - from datetime import datetime - now = datetime.now() - time_vars = ['%a', '%A', '%b', '%B', '%c', '%d', '%f', '%H', - '%I', '%j', '%m', '%M', '%p', '%S', '%U', '%w', - '%W', '%x', '%X', '%y', '%Y', '%z', '%Z'] - for var in time_vars: - image_vars[var] = now.strftime(var) - - ami_name = info.manifest.image['name'].format(**image_vars) - ami_description = info.manifest.image['description'].format(**image_vars) - - images = info.connection.get_all_images() - for image in images: - if ami_name == image.name: - msg = 'An image by the name {ami_name} already exists.'.format(ami_name=ami_name) - raise TaskError(msg) - info.ami_name = ami_name - info.ami_description = ami_description - - -class RegisterAMI(Task): - description = 'Registering the image as an AMI' - phase = phases.image_registration - after = [CreateSnapshot] - - def run(self, info): - arch = {'i386': 'i386', - 'amd64': 'x86_64'}.get(info.manifest.system['architecture']) - kernel_mapping = {'us-east-1': {'amd64': 'aki-88aa75e1', - 'i386': 'aki-b6aa75df'}, - 'us-west-1': {'amd64': 'aki-f77e26b2', - 'i386': 'aki-f57e26b0'}, - 'us-west-2': {'amd64': 'aki-fc37bacc', - 'i386': 'aki-fa37baca'}, - 'eu-west-1': {'amd64': 'aki-71665e05', - 'i386': 'aki-75665e01'}, - 'ap-southeast-1': {'amd64': 'aki-fe1354ac', - 'i386': 'aki-f81354aa'}, - 'ap-southeast-2': {'amd64': 'aki-31990e0b', - 'i386': 'aki-33990e09'}, - 'ap-northeast-1': {'amd64': 'aki-44992845', - 'i386': 'aki-42992843'}, - 'sa-east-1': {'amd64': 'aki-c48f51d9', - 'i386': 'aki-ca8f51d7'}, - 'us-gov-west-1': {'amd64': 'aki-79a4c05a', - 'i386': 'aki-7ba4c058'}} - kernel_id = kernel_mapping.get(info.host['region']).get(info.manifest.system['architecture']) - - from boto.ec2.blockdevicemapping import BlockDeviceType - from boto.ec2.blockdevicemapping import BlockDeviceMapping - block_device = BlockDeviceType(snapshot_id=info.snapshot.id, delete_on_termination=True, - size=int(info.manifest.volume['size']/1024)) - block_device_map = BlockDeviceMapping() - block_device_map['/dev/sda1'] = block_device - - info.image = info.connection.register_image(name=info.ami_name, description=info.ami_description, - architecture=arch, kernel_id=kernel_id, - root_device_name='/dev/sda1', - block_device_map=block_device_map) diff --git a/providers/raw/tasks/boot.py b/providers/raw/tasks/boot.py index 4d7c7f9..0bf3d28 100644 --- a/providers/raw/tasks/boot.py +++ b/providers/raw/tasks/boot.py @@ -26,13 +26,8 @@ class ConfigureGrub(Task): from common.tools import sed_i grub_def = os.path.join(info.root, 'etc/default/grub') - #sed_i(grub_def, '^GRUB_TIMEOUT=[0-9]+', 'GRUB_TIMEOUT=0\n' - # 'GRUB_HIDDEN_TIMEOUT=true') from common.tools import log_check_call - #log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub']) - #log_check_call(['/usr/sbin/chroot', info.root, 'cat', '/boot/grub/grub.cfg']) - #log_check_call(['/usr/sbin/chroot', info.root, 'cat', '/boot/grub/device.map']) log_check_call(['/usr/sbin/chroot', info.root, 'ln', '-s', '/boot/grub/grub.cfg', '/boot/grub/menu.lst']) log_check_call(['/usr/sbin/chroot', info.root, 'update-initramfs', '-u']) diff --git a/providers/raw/tasks/connection.py b/providers/raw/tasks/connection.py deleted file mode 100644 index 2c2ce19..0000000 --- a/providers/raw/tasks/connection.py +++ /dev/null @@ -1,40 +0,0 @@ -from base import Task -from common import phases -import host - - -class GetCredentials(Task): - description = 'Getting AWS credentials' - phase = phases.preparation - - def run(self, info): - info.credentials = self.get_credentials(info.manifest) - - def get_credentials(self, manifest): - from os import getenv - # manifest overrides environment - if(manifest.credentials['access-key'] and manifest.credentials['secret-key']): - return {'access_key': manifest.credentials['access-key'], - 'secret_key': manifest.credentials['secret-key']} - if(getenv('EC2_ACCESS_KEY') and getenv('EC2_SECRET_KEY')): - return {'access_key': getenv('EC2_ACCESS_KEY'), - 'secret_key': getenv('EC2_SECRET_KEY')} - - if(bool(manifest.credentials['access-key']) != bool(manifest.credentials['secret-key'])): - raise RuntimeError('Both the access key and secret key must be specified in the manifest.') - if(bool(getenv('EC2_ACCESS_KEY')) != bool(getenv('EC2_SECRET_KEY'))): - raise RuntimeError('Both the access key and secret key must be specified as environment variables.') - - raise RuntimeError('No ec2 credentials found.') - - -class Connect(Task): - description = 'Connecting to EC2' - phase = phases.preparation - after = [GetCredentials, host.GetInfo] - - def run(self, info): - from boto.ec2 import connect_to_region - info.connection = connect_to_region(info.host['region'], - aws_access_key_id=info.credentials['access_key'], - aws_secret_access_key=info.credentials['secret_key']) diff --git a/providers/raw/tasks/ebs.py b/providers/raw/tasks/ebs.py deleted file mode 100644 index a07b1a8..0000000 --- a/providers/raw/tasks/ebs.py +++ /dev/null @@ -1,89 +0,0 @@ -from base import Task -from common import phases -from common.exceptions import TaskError -from connection import Connect -from filesystem import UnmountVolume -import time - - -class CreateVolume(Task): - phase = phases.volume_creation - after = [Connect] - - description = 'Creating an EBS volume for bootstrapping' - - def run(self, info): - volume_size = int(info.manifest.volume['size']/1024) - - info.volume = info.connection.create_volume(volume_size, info.host['availabilityZone']) - while info.volume.volume_state() != 'available': - time.sleep(5) - info.volume.update() - - -class AttachVolume(Task): - phase = phases.volume_creation - after = [CreateVolume] - - description = 'Attaching the EBS volume' - - def run(self, info): - def char_range(c1, c2): - """Generates the characters from `c1` to `c2`, inclusive.""" - for c in xrange(ord(c1), ord(c2)+1): - yield chr(c) - - import os.path - info.bootstrap_device = {} - for letter in char_range('f', 'z'): - dev_path = os.path.join('/dev', 'xvd' + letter) - if not os.path.exists(dev_path): - info.bootstrap_device['path'] = dev_path - info.bootstrap_device['ec2_path'] = os.path.join('/dev', 'sd' + letter) - break - if 'path' not in info.bootstrap_device: - raise VolumeError('Unable to find a free block device path for mounting the bootstrap volume') - - info.volume.attach(info.host['instanceId'], info.bootstrap_device['ec2_path']) - while info.volume.attachment_state() != 'attached': - time.sleep(2) - info.volume.update() - - -class DetachVolume(Task): - phase = phases.volume_unmounting - after = [UnmountVolume] - - description = 'Detaching the EBS volume' - - def run(self, info): - info.volume.detach() - while info.volume.attachment_state() is not None: - time.sleep(2) - info.volume.update() - - -class CreateSnapshot(Task): - description = 'Creating a snapshot of the EBS volume' - phase = phases.image_registration - - def run(self, info): - info.snapshot = info.volume.create_snapshot() - while info.snapshot.status != 'completed': - time.sleep(2) - info.snapshot.update() - - -class DeleteVolume(Task): - phase = phases.cleaning - after = [] - - description = 'Deleting the EBS volume' - - def run(self, info): - info.volume.delete() - del info.volume - - -class VolumeError(TaskError): - pass diff --git a/providers/raw/tasks/one.py b/providers/raw/tasks/one.py deleted file mode 100644 index fda5185..0000000 --- a/providers/raw/tasks/one.py +++ /dev/null @@ -1,39 +0,0 @@ -from base import Task -from common import phases -import os -from providers.one.tasks.locale import GenerateLocale - - -class OpenNebulaContext(Task): - description = 'Setup OpenNebula init context' - phase = phases.system_modification - after = [GenerateLocale] - - def run(self, info): - import stat - rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | - stat.S_IRGRP | stat.S_IXGRP | - stat.S_IROTH | stat.S_IXOTH) - - from shutil import copy - script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/one-context_3.8.1.deb')) - script_dst = os.path.join(info.root, 'tmp/one-context_3.8.1.deb') - copy(script_src, script_dst) - os.chmod(script_dst, rwxr_xr_x) - - from common.tools import log_check_call - log_check_call(['/usr/sbin/chroot', info.root, 'dpkg', '-i', '/tmp/one-context_3.8.1.deb']) - # Fix start - from common.tools import sed_i - vmcontext_def = os.path.join(info.root, 'etc/init.d/vmcontext') - sed_i(vmcontext_def, '# Default-Start:', '# Default-Start: 2 3 4 5') - os.chmod(vmcontext_def, rwxr_xr_x) - log_check_call(['/usr/sbin/chroot', info.root, 'update-rc.d', 'vmcontext', 'start', '90', '2', '3', '4', '5', 'stop', '90', '0', '6']) - - script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/one-pubkey.sh')) - script_dst = os.path.join(info.root, 'etc/one-context.d/one-pubkey.sh') - copy(script_src, script_dst) - script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/one-ec2.sh')) - script_dst = os.path.join(info.root, 'etc/one-context.d/one-ec2.sh') - copy(script_src, script_dst) -