Convert "provider" into provider specific section

This is where all provider specific settings belong
like waagent on azure, guest additions iso path on vbox and virtualization type on ec2
This commit is contained in:
Anders Ingemann 2014-07-05 18:14:29 +02:00
parent 5bb0e5428e
commit ebba39f59b
37 changed files with 234 additions and 183 deletions

View file

@ -4,7 +4,11 @@
"type": "object", "type": "object",
"properties": { "properties": {
"provider": { "provider": {
"type": "string" "type": "object",
"properties": {
"name": { "type": "string" }
},
"required": ["name"]
}, },
"bootstrapper": { "bootstrapper": {
"type": "object", "type": "object",

View file

@ -39,7 +39,7 @@ class Manifest(object):
self.data = load_yaml(self.path) self.data = load_yaml(self.path)
# Get the provider name from the manifest and load the corresponding module # Get the provider name from the manifest and load the corresponding module
provider_modname = 'bootstrapvz.providers.' + self.data['provider'] provider_modname = 'bootstrapvz.providers.' + self.data['provider']['name']
log.debug('Loading provider ' + provider_modname) log.debug('Loading provider ' + provider_modname)
# Create a modules dict that contains the loaded provider and plugins # Create a modules dict that contains the loaded provider and plugins
import importlib import importlib

View file

@ -63,10 +63,10 @@ class SetMetadataSource(Task):
sources = info.manifest.plugins['cloud_init']['metadata_sources'] sources = info.manifest.plugins['cloud_init']['metadata_sources']
else: else:
source_mapping = {'ec2': 'Ec2'} source_mapping = {'ec2': 'Ec2'}
sources = source_mapping.get(info.manifest.provider, None) sources = source_mapping.get(info.manifest.provider['name'], None)
if sources is None: if sources is None:
msg = ('No cloud-init metadata source mapping found for provider `{provider}\', ' msg = ('No cloud-init metadata source mapping found for provider `{provider}\', '
'skipping selections setting.').format(provider=info.manifest.provider) 'skipping selections setting.').format(provider=info.manifest.provider['name'])
logging.getLogger(__name__).warn(msg) logging.getLogger(__name__).warn(msg)
return return
sources = "cloud-init cloud-init/datasources multiselect " + sources sources = "cloud-init cloud-init/datasources multiselect " + sources

View file

@ -3,13 +3,9 @@
"title": "Azure manifest", "title": "Azure manifest",
"type": "object", "type": "object",
"properties": { "properties": {
"system": { "provider": {
"type": "object", "type": "object",
"properties": { "properties": {
"bootloader": {
"type": "string",
"enum": ["grub", "extlinux"]
},
"waagent": { "waagent": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -22,9 +18,18 @@
}, },
"required": ["version"] "required": ["version"]
} }
}, }
"required": ["waagent"] "required": ["waagent"]
}, },
"system": {
"type": "object",
"properties": {
"bootloader": {
"type": "string",
"enum": ["grub", "extlinux"]
}
},
},
"volume": { "volume": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -29,7 +29,7 @@ class Waagent(Task):
def run(cls, info): def run(cls, info):
from bootstrapvz.common.tools import log_check_call from bootstrapvz.common.tools import log_check_call
import os import os
waagent_version = info.manifest.system['waagent']['version'] waagent_version = info.manifest.provider['waagent']['version']
waagent_file = 'WALinuxAgent-' + waagent_version + '.tar.gz' waagent_file = 'WALinuxAgent-' + waagent_version + '.tar.gz'
waagent_url = 'https://github.com/Azure/WALinuxAgent/archive/' + waagent_file waagent_url = 'https://github.com/Azure/WALinuxAgent/archive/' + waagent_file
log_check_call(['wget', '-P', info.root, waagent_url]) log_check_call(['wget', '-P', info.root, waagent_url])

View file

@ -38,7 +38,7 @@ def validate_manifest(data, validator, error):
validator(data, os.path.join(os.path.dirname(__file__), 'manifest-schema-s3.json')) validator(data, os.path.join(os.path.dirname(__file__), 'manifest-schema-s3.json'))
bootloader = data['system']['bootloader'] bootloader = data['system']['bootloader']
virtualization = data['virtualization'] virtualization = data['provider']['virtualization']
backing = data['volume']['backing'] backing = data['volume']['backing']
partition_type = data['volume']['partitions']['type'] partition_type = data['volume']['partitions']['type']

View file

@ -3,18 +3,23 @@
"title": "EC2 manifest for instance store AMIs", "title": "EC2 manifest for instance store AMIs",
"type": "object", "type": "object",
"properties": { "properties": {
"credentials": { "provider": {
"type": "object", "type": "object",
"properties": { "properties": {
"certificate": { "credentials": {
"type": "string" "type": "object",
}, "properties": {
"private-key": { "certificate": {
"type": "string" "type": "string"
}, },
"user-id": { "private-key": {
"type": "string", "type": "string"
"pattern": "(^arn:aws:iam::\\d*:user/\\w.*$)|(^\\d{4}-\\d{4}-\\d{4}$)" },
"user-id": {
"type": "string",
"pattern": "(^arn:aws:iam::\\d*:user/\\w.*$)|(^\\d{4}-\\d{4}-\\d{4}$)"
}
}
} }
} }
}, },

View file

@ -3,7 +3,24 @@
"title": "EC2 manifest", "title": "EC2 manifest",
"type": "object", "type": "object",
"properties": { "properties": {
"virtualization": { "enum": ["pvm", "hvm"] }, "provider": {
"type": "object",
"properties": {
"virtualization": { "enum": ["pvm", "hvm"] },
"credentials": {
"type": "object",
"properties": {
"access-key": {
"type": "string"
},
"secret-key": {
"type": "string"
}
}
}
},
"required": ["virtualization"]
},
"image": { "image": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -12,17 +29,6 @@
} }
} }
}, },
"credentials": {
"type": "object",
"properties": {
"access-key": {
"type": "string"
},
"secret-key": {
"type": "string"
}
}
},
"system": { "system": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -103,7 +103,7 @@ class RegisterAMI(Task):
registration_params['image_location'] = info._ec2['manifest_location'] registration_params['image_location'] = info._ec2['manifest_location']
else: else:
root_dev_name = {'pvm': '/dev/sda', root_dev_name = {'pvm': '/dev/sda',
'hvm': '/dev/xvda'}.get(info.manifest.data['virtualization']) 'hvm': '/dev/xvda'}.get(info.manifest.provider['virtualization'])
registration_params['root_device_name'] = root_dev_name registration_params['root_device_name'] = root_dev_name
from boto.ec2.blockdevicemapping import BlockDeviceType from boto.ec2.blockdevicemapping import BlockDeviceType
@ -113,7 +113,7 @@ class RegisterAMI(Task):
registration_params['block_device_map'] = BlockDeviceMapping() registration_params['block_device_map'] = BlockDeviceMapping()
registration_params['block_device_map'][root_dev_name] = block_device registration_params['block_device_map'][root_dev_name] = block_device
if info.manifest.data['virtualization'] == 'hvm': if info.manifest.provider['virtualization'] == 'hvm':
registration_params['virtualization_type'] = 'hvm' registration_params['virtualization_type'] = 'hvm'
else: else:
registration_params['virtualization_type'] = 'paravirtual' registration_params['virtualization_type'] = 'paravirtual'

View file

@ -18,9 +18,9 @@ class GetCredentials(Task):
def get_credentials(cls, manifest, keys): def get_credentials(cls, manifest, keys):
from os import getenv from os import getenv
creds = {} creds = {}
if all(key in manifest.data['credentials'] for key in keys): if all(key in manifest.provider['credentials'] for key in keys):
for key in keys: for key in keys:
creds[key] = manifest.data['credentials'][key] creds[key] = manifest.provider['credentials'][key]
return creds return creds
def env_key(key): def env_key(key):

View file

@ -28,7 +28,7 @@ def resolve_tasks(taskset, manifest):
loopback.MoveImage, loopback.MoveImage,
]) ])
if manifest.bootstrapper.get('virtio', []): if manifest.provider.get('virtio', []):
from tasks import virtio from tasks import virtio
taskset.update([virtio.VirtIO]) taskset.update([virtio.VirtIO])

View file

@ -3,7 +3,7 @@
"title": "KVM manifest", "title": "KVM manifest",
"type": "object", "type": "object",
"properties": { "properties": {
"system": { "provider": {
"type": "object", "type": "object",
"properties": { "properties": {
"virtio": { "virtio": {
@ -18,7 +18,12 @@
"virtio_ring"] "virtio_ring"]
}, },
"minItems": 1 "minItems": 1
}, }
}
},
"system": {
"type": "object",
"properties": {
"bootloader": { "bootloader": {
"type": "string", "type": "string",
"enum": ["grub", "extlinux"] "enum": ["grub", "extlinux"]

View file

@ -12,5 +12,5 @@ class VirtIO(Task):
modules = os.path.join(info.root, '/etc/initramfs-tools/modules') modules = os.path.join(info.root, '/etc/initramfs-tools/modules')
with open(modules, "a") as modules_file: with open(modules, "a") as modules_file:
modules_file.write("\n") modules_file.write("\n")
for module in info.manifest.system.get('virtio', []): for module in info.manifest.provider.get('virtio', []):
modules_file.write(module + "\n") modules_file.write(module + "\n")

View file

@ -22,7 +22,7 @@ def resolve_tasks(taskset, manifest):
loopback.MoveImage, loopback.MoveImage,
]) ])
if manifest.bootstrapper.get('guest_additions', False): if manifest.provider.get('guest_additions', False):
from tasks import guest_additions from tasks import guest_additions
taskset.update([guest_additions.CheckGuestAdditionsPath, taskset.update([guest_additions.CheckGuestAdditionsPath,
guest_additions.AddGuestAdditionsPackages, guest_additions.AddGuestAdditionsPackages,

View file

@ -11,7 +11,7 @@ class CheckGuestAdditionsPath(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
import os.path import os.path
guest_additions_path = info.manifest.bootstrapper['guest_additions'] guest_additions_path = info.manifest.provider['guest_additions']
if not os.path.exists(guest_additions_path): if not os.path.exists(guest_additions_path):
msg = 'The file {file} does not exist.'.format(file=guest_additions_path) msg = 'The file {file} does not exist.'.format(file=guest_additions_path)
raise TaskError(msg) raise TaskError(msg)
@ -43,7 +43,7 @@ class InstallGuestAdditions(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
import os import os
guest_additions_path = info.manifest.bootstrapper['guest_additions'] guest_additions_path = info.manifest.provider['guest_additions']
mount_dir = 'mnt/guest_additions' mount_dir = 'mnt/guest_additions'
mount_path = os.path.join(info.root, mount_dir) mount_path = os.path.join(info.root, mount_dir)
os.mkdir(mount_path) os.mkdir(mount_path)

View file

@ -1,5 +1,10 @@
{ {
"provider": "azure", "provider": {
"name": "azure",
"waagent": {
"version": "2.0.4"
}
},
"bootstrapper": { "bootstrapper": {
"workspace": "/target", "workspace": "/target",
"mirror": "http://ftp.fr.debian.org/debian/" "mirror": "http://ftp.fr.debian.org/debian/"
@ -14,10 +19,7 @@
"bootloader": "grub", "bootloader": "grub",
"timezone": "UTC", "timezone": "UTC",
"locale": "en_US", "locale": "en_US",
"charmap": "UTF-8", "charmap": "UTF-8"
"waagent": {
"version": "2.0.4"
}
}, },
"packages": { "packages": {
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "hvm", "name": "ec2",
"credentials": { "virtualization": "hvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "hvm", "name": "ec2",
"credentials": { "virtualization": "hvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,36 +1,37 @@
--- ---
provider: "ec2" provider:
virtualization: "pvm" name: "ec2"
credentials: virtualization: "pvm"
credentials:
access-key: "" access-key: ""
secret-key: "" secret-key: ""
bootstrapper: bootstrapper:
workspace: "/target" workspace: "/target"
image: image:
name: "debian-{system.release}-{system.architecture}-{virtualization}-{%Y}-{%m}-{%d}-ebs" name: "debian-{system.release}-{system.architecture}-{virtualization}-{%Y}-{%m}-{%d}-ebs"
description: "Debian {system.release} {system.architecture}" description: "Debian {system.release} {system.architecture}"
system: system:
release: "testing" release: "testing"
architecture: "amd64" architecture: "amd64"
bootloader: "pvgrub" bootloader: "pvgrub"
timezone: "UTC" timezone: "UTC"
locale: "en_US" locale: "en_US"
charmap: "UTF-8" charmap: "UTF-8"
packages: packages:
#mirror: "http://cloudfront.debian.net/debian" #mirror: "http://cloudfront.debian.net/debian"
install_standard: true install_standard: true
volume: volume:
backing: "ebs" backing: "ebs"
partitions: partitions:
type: "none" type: "none"
root: root:
size: "8GiB" size: "8GiB"
filesystem: "ext4" filesystem: "ext4"
plugins: plugins:
cloud_init: cloud_init:
username: "admin" username: "admin"
#metadata_sources: "Ec2" #metadata_sources: "Ec2"
disable_modules: disable_modules:
- "landscape" - "landscape"
- "byobu" - "byobu"
- "ssh-import-id" - "ssh-import-id"

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,11 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,14 +1,12 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null, // "access-key": null,
// "certificate": null, // "secret-key": null
// "private-key": null, }
// "user-id": null
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,14 +1,15 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null, // "access-key": null,
// "certificate": null, // "secret-key": null,
// "private-key": null, // "certificate": null,
// "user-id": null // "private-key": null,
// "user-id": null
}
}, },
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },

View file

@ -1,7 +1,9 @@
{ {
"provider": "gce", "provider": {
"name": "gce"
},
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },
"image": { "image": {
"name": "disk", "name": "disk",

View file

@ -1,7 +1,9 @@
{ {
"provider": "gce", "provider": {
"name": "gce"
},
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
}, },
"image": { "image": {
"name": "disk", "name": "disk",

View file

@ -1,8 +1,10 @@
{ {
"provider": "kvm", "provider": {
"name": "kvm",
"virtio_modules": [ "virtio_pci", "virtio_blk" ]
},
"bootstrapper": { "bootstrapper": {
"workspace": "/target", "workspace": "/target"
"mirror": "http://ftp.fr.debian.org/debian/"
}, },
"image": { "image": {
"name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}", "name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}",
@ -14,8 +16,7 @@
"bootloader": "grub", "bootloader": "grub",
"timezone": "UTC", "timezone": "UTC",
"locale": "en_US", "locale": "en_US",
"charmap": "UTF-8", "charmap": "UTF-8"
"virtio_modules": [ "virtio_pci", "virtio_blk" ]
}, },
"packages": {}, "packages": {},
"volume": { "volume": {

View file

@ -1,8 +1,9 @@
{ {
"provider": "kvm", "provider": {
"name": "kvm"
},
"bootstrapper": { "bootstrapper": {
"workspace": "/target", "workspace": "/target"
"mirror": "http://ftp.fr.debian.org/debian/"
}, },
"image": { "image": {
"name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}", "name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}",

View file

@ -1,9 +1,11 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {

View file

@ -1,9 +1,11 @@
{ {
"provider": "ec2", "provider": {
"virtualization": "pvm", "name": "ec2",
"credentials": { "virtualization": "pvm",
// "access-key": null, "credentials": {
// "secret-key": null // "access-key": null,
// "secret-key": null
}
}, },
"bootstrapper": { "bootstrapper": {

View file

@ -1,9 +1,11 @@
{ {
"provider": "virtualbox", "provider": {
"bootstrapper": { "name": "virtualbox",
"workspace": "/target",
"guest_additions": "/root/images/VBoxGuestAdditions.iso" "guest_additions": "/root/images/VBoxGuestAdditions.iso"
}, },
"bootstrapper": {
"workspace": "/target"
},
"image": { "image": {
"name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}", "name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}",
"description": "Debian {system.release} {system.architecture}" "description": "Debian {system.release} {system.architecture}"

View file

@ -1,8 +1,10 @@
{ {
"provider": "virtualbox", "provider": {
"name": "virtualbox",
"guest_additions": "/root/images/VBoxGuestAdditions.iso"
},
"bootstrapper": { "bootstrapper": {
"workspace": "/target" "workspace": "/target"
// "guest_additions": "/root/images/VBoxGuestAdditions.iso"
}, },
"image": { "image": {
"name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}", "name": "debian-{system.release}-{system.architecture}-{%y}{%m}{%d}",