mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
Add libvirt support for vagrant plugin
This commit is contained in:
parent
fee756185d
commit
19c241be2c
4 changed files with 37 additions and 10 deletions
|
@ -9,4 +9,10 @@ of the virtual machine.
|
|||
|
||||
This plugin creates a vagrant box that is ready to be shared or
|
||||
deployed. At the moment it is only compatible with the VirtualBox
|
||||
provider and doesn't requires any additional settings.
|
||||
and Libvirt providers.
|
||||
|
||||
Settings
|
||||
~~~~~~~~
|
||||
|
||||
- ``provider``: Specifies the provider of a resulting vagrant box.
|
||||
``optional`` Valid values: ``virtualbox, libvirt`` Default: ``libvirt``
|
|
@ -6,6 +6,11 @@ from bootstrapvz.common.tools import rel_path
|
|||
|
||||
def validate_manifest(data, validator, error):
|
||||
validator(data, rel_path(__file__, 'manifest-schema.yml'))
|
||||
vagrant_provider = data['plugins']['vagrant'].get('provider', 'virtualbox')
|
||||
if vagrant_provider == 'virtualbox' and data['volume']['backing'] != 'vmdk':
|
||||
error('Virtualbox vagrant boxes support vmdk images only', ['plugins', 'vagrant', 'provider'])
|
||||
if vagrant_provider == 'libvirt' and data['volume']['backing'] != 'qcow2':
|
||||
error('Libvirt vagrant boxes support qcow2 images only', ['plugins', 'vagrant', 'provider'])
|
||||
|
||||
|
||||
def resolve_tasks(taskset, manifest):
|
||||
|
|
|
@ -8,7 +8,7 @@ properties:
|
|||
properties:
|
||||
name:
|
||||
type: string
|
||||
enum: [virtualbox]
|
||||
enum: [virtualbox, kvm]
|
||||
system:
|
||||
required: [hostname]
|
||||
volume:
|
||||
|
@ -16,11 +16,15 @@ properties:
|
|||
properties:
|
||||
backing:
|
||||
type: string
|
||||
enum: [vmdk]
|
||||
enum: [vmdk, qcow2]
|
||||
required: [backing]
|
||||
plugins:
|
||||
type: object
|
||||
properties:
|
||||
vagrant:
|
||||
type: object
|
||||
properties:
|
||||
provider:
|
||||
type: string
|
||||
enum: [virtualbox, libvirt]
|
||||
additionalProperties: false
|
||||
|
|
|
@ -4,6 +4,7 @@ from bootstrapvz.common.tasks import workspace
|
|||
from bootstrapvz.common.tools import rel_path
|
||||
import os
|
||||
import shutil
|
||||
import json
|
||||
|
||||
assets = rel_path(__file__, 'assets')
|
||||
|
||||
|
@ -128,18 +129,29 @@ class PackageBox(Task):
|
|||
from bootstrapvz.common.tools import sed_i
|
||||
sed_i(vagrantfile, '\\[MAC_ADDRESS\\]', mac_address)
|
||||
|
||||
metadata_source = os.path.join(assets, 'metadata.json')
|
||||
metadata = os.path.join(info._vagrant['folder'], 'metadata.json')
|
||||
shutil.copy(metadata_source, metadata)
|
||||
vagrant_provider = info.manifest.plugins['vagrant'].get('provider', 'virtualbox')
|
||||
metadata = {'provider': vagrant_provider}
|
||||
|
||||
if vagrant_provider == 'libvirt':
|
||||
metadata['format'] = info.manifest.volume['backing']
|
||||
virtual_size = info.volume.size.bytes.get_qty_in('G')
|
||||
metadata['virtual_size'] = virtual_size
|
||||
|
||||
metadata_file = os.path.join(info._vagrant['folder'], 'metadata.json')
|
||||
with open(metadata_file, 'w') as f:
|
||||
json.dump(metadata, f)
|
||||
|
||||
from bootstrapvz.common.tools import log_check_call
|
||||
disk_name = 'box-disk1.' + info.volume.extension
|
||||
if vagrant_provider == 'libvirt':
|
||||
disk_name = 'box.img'
|
||||
else:
|
||||
disk_name = 'box-disk1.' + info.volume.extension
|
||||
ovf_path = os.path.join(info._vagrant['folder'], 'box.ovf')
|
||||
cls.write_ovf(info, ovf_path, mac_address, disk_name)
|
||||
|
||||
disk_link = os.path.join(info._vagrant['folder'], disk_name)
|
||||
log_check_call(['ln', '-s', info.volume.image_path, disk_link])
|
||||
|
||||
ovf_path = os.path.join(info._vagrant['folder'], 'box.ovf')
|
||||
cls.write_ovf(info, ovf_path, mac_address, disk_name)
|
||||
|
||||
box_files = os.listdir(info._vagrant['folder'])
|
||||
log_check_call(['tar', '--create', '--gzip', '--dereference',
|
||||
'--file', info._vagrant['box_path'],
|
||||
|
|
Loading…
Add table
Reference in a new issue