mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
ImageRegistration task implemented
This commit is contained in:
parent
58e560a893
commit
5dd8c27c6a
4 changed files with 86 additions and 7 deletions
|
@ -11,7 +11,7 @@
|
|||
"tarball": true
|
||||
},
|
||||
"image": {
|
||||
"name" : "debian-{release}-{architecture}-{virtualization}-{year}{month}{day}",
|
||||
"name" : "debian-{release}-{architecture}-{virtualization}-{%y}{%M}{%d}",
|
||||
"description": "Debian {release} {architecture} AMI ({virtualization})"
|
||||
},
|
||||
"system": {
|
||||
|
@ -28,7 +28,7 @@
|
|||
},
|
||||
"plugins": {
|
||||
"admin_user": {
|
||||
"enabled": true
|
||||
"enabled": false
|
||||
},
|
||||
"build_metadata": {
|
||||
"enabled": false,
|
||||
|
|
|
@ -3,6 +3,7 @@ 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
|
||||
|
@ -26,6 +27,7 @@ def tasks(tasklist, manifest):
|
|||
host.CheckPackages(),
|
||||
connection.GetCredentials(),
|
||||
host.GetInfo(),
|
||||
ami.AMIName(),
|
||||
connection.Connect())
|
||||
if manifest.volume['backing'].lower() == 'ebs':
|
||||
tasklist.add(ebs.CreateVolume(),
|
||||
|
@ -35,7 +37,8 @@ def tasks(tasklist, manifest):
|
|||
tasklist.add(filesystem.AddXFSProgs())
|
||||
if manifest.volume['filesystem'].lower() in ['ext2', 'ext3', 'ext4']:
|
||||
tasklist.add(filesystem.TuneVolumeFS())
|
||||
tasklist.add(filesystem.CreateMountDir(), filesystem.MountVolume())
|
||||
tasklist.add(filesystem.CreateMountDir(),
|
||||
filesystem.MountVolume())
|
||||
if manifest.bootstrapper['tarball']:
|
||||
tasklist.add(bootstrap.MakeTarball())
|
||||
tasklist.add(bootstrap.Bootstrap(),
|
||||
|
@ -68,10 +71,9 @@ def tasks(tasklist, manifest):
|
|||
filesystem.DeleteMountDir())
|
||||
if manifest.volume['backing'].lower() == 'ebs':
|
||||
tasklist.add(ebs.DetachVolume(),
|
||||
ebs.CreateSnapshot())
|
||||
|
||||
from common.tasks import TriggerRollback
|
||||
tasklist.add(TriggerRollback())
|
||||
ebs.CreateSnapshot(),
|
||||
ebs.DeleteVolume())
|
||||
tasklist.add(ami.RegisterAMI())
|
||||
|
||||
|
||||
def rollback_tasks(tasklist, tasks_completed, manifest):
|
||||
|
|
|
@ -12,3 +12,4 @@ class Manifest(base.Manifest):
|
|||
super(Manifest, self).parse(data)
|
||||
self.credentials = data['credentials']
|
||||
self.virtualization = data['virtualization']
|
||||
self.image = data['image']
|
||||
|
|
76
providers/ec2/tasks/ami.py
Normal file
76
providers/ec2/tasks/ami.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
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)
|
Loading…
Add table
Reference in a new issue