mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
remove tasks ot required by raw provider, fix provider name in plugins after renaming from one to raw
This commit is contained in:
parent
6ffa601488
commit
385eac14a1
12 changed files with 11 additions and 294 deletions
|
@ -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" ],
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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(),
|
||||
|
|
Binary file not shown.
|
@ -1,14 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -n "$EC2_USER_DATA" ]; then
|
||||
# Check if EC2 user data is a script, if yes, execute
|
||||
if [[ $EC2_USER_DATA =~ ^#! ]]; then
|
||||
echo "EC2 data is an executable script, so execute it now"
|
||||
TMPFILE=$(mktemp /tmp/output.XXXXXXXXXX)
|
||||
chmod 755 $TMPFILE
|
||||
$TMPFILE
|
||||
cat $TMPFILE
|
||||
else
|
||||
print "Not an executable"
|
||||
fi
|
||||
fi
|
|
@ -1,17 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Reconfigure host ssh keys"
|
||||
dpkg-reconfigure openssh-server
|
||||
|
||||
if [ ! -e /root/.ssh ]; then
|
||||
mkdir /root/.ssh
|
||||
touch /root/.ssh/authorized_keys
|
||||
chmod 600 /root/.ssh/authorized_keys
|
||||
fi
|
||||
|
||||
echo "Copy public ssh keys to authorized_keys"
|
||||
for f in /mnt/*.pub
|
||||
do
|
||||
cat $f >> /root/.ssh/authorized_keys
|
||||
|
||||
done
|
|
@ -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)
|
|
@ -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'])
|
||||
|
|
|
@ -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'])
|
|
@ -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
|
|
@ -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)
|
||||
|
Loading…
Add table
Reference in a new issue