mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
commit
3e5c94f0d4
8 changed files with 148 additions and 7 deletions
|
@ -25,13 +25,15 @@ def load_volume(data, bootloader):
|
||||||
from bootstrapvz.common.fs.virtualharddisk import VirtualHardDisk
|
from bootstrapvz.common.fs.virtualharddisk import VirtualHardDisk
|
||||||
from bootstrapvz.common.fs.virtualmachinedisk import VirtualMachineDisk
|
from bootstrapvz.common.fs.virtualmachinedisk import VirtualMachineDisk
|
||||||
from bootstrapvz.common.fs.folder import Folder
|
from bootstrapvz.common.fs.folder import Folder
|
||||||
|
from bootstrapvz.common.fs.logicalvolume import LogicalVolume
|
||||||
volume_backing = {'raw': LoopbackVolume,
|
volume_backing = {'raw': LoopbackVolume,
|
||||||
's3': LoopbackVolume,
|
's3': LoopbackVolume,
|
||||||
'vdi': VirtualDiskImage,
|
'vdi': VirtualDiskImage,
|
||||||
'vhd': VirtualHardDisk,
|
'vhd': VirtualHardDisk,
|
||||||
'vmdk': VirtualMachineDisk,
|
'vmdk': VirtualMachineDisk,
|
||||||
'ebs': EBSVolume,
|
'ebs': EBSVolume,
|
||||||
'folder': Folder
|
'folder': Folder,
|
||||||
|
'lvm': LogicalVolume
|
||||||
}.get(data['backing'])
|
}.get(data['backing'])
|
||||||
|
|
||||||
# Instantiate the partition map
|
# Instantiate the partition map
|
||||||
|
|
|
@ -131,6 +131,12 @@ properties:
|
||||||
^\w+$: {}
|
^\w+$: {}
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
volume:
|
volume:
|
||||||
|
type: object
|
||||||
|
oneOf:
|
||||||
|
- $ref: '#/definitions/standardvolume'
|
||||||
|
- $ref: '#/definitions/logicalvolume'
|
||||||
|
definitions:
|
||||||
|
standardvolume:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
backing: {type: string}
|
backing: {type: string}
|
||||||
|
@ -141,7 +147,20 @@ properties:
|
||||||
- $ref: '#/definitions/partition_table'
|
- $ref: '#/definitions/partition_table'
|
||||||
required: [partitions]
|
required: [partitions]
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
definitions:
|
logicalvolume:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
backing:
|
||||||
|
enum: [lvm]
|
||||||
|
volumegroup : {type: string}
|
||||||
|
logicalvolume: {type: string}
|
||||||
|
partitions:
|
||||||
|
type: object
|
||||||
|
oneOf:
|
||||||
|
- $ref: '#/definitions/no_partitions'
|
||||||
|
- $ref: '#/definitions/partition_table'
|
||||||
|
required: [partitions]
|
||||||
|
additionalProperties: false
|
||||||
absolute_path:
|
absolute_path:
|
||||||
type: string
|
type: string
|
||||||
pattern: ^/[^\0]+$
|
pattern: ^/[^\0]+$
|
||||||
|
|
38
bootstrapvz/common/fs/logicalvolume.py
Normal file
38
bootstrapvz/common/fs/logicalvolume.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
from bootstrapvz.base.fs.volume import Volume
|
||||||
|
from bootstrapvz.common.tools import log_check_call
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class LogicalVolume(Volume):
|
||||||
|
|
||||||
|
def __init__(self, partitionmap):
|
||||||
|
super(LogicalVolume, self).__init__(partitionmap)
|
||||||
|
self.vg = ''
|
||||||
|
self.lv = ''
|
||||||
|
|
||||||
|
def create(self, volumegroup, logicalvolume):
|
||||||
|
self.vg = volumegroup
|
||||||
|
self.lv = logicalvolume
|
||||||
|
image_path = os.path.join(os.sep, 'dev', self.vg, self.lv)
|
||||||
|
self.fsm.create(image_path=image_path)
|
||||||
|
|
||||||
|
def _before_create(self, e):
|
||||||
|
self.image_path = e.image_path
|
||||||
|
lv_size = str(self.size.bytes.get_qty_in('MiB'))
|
||||||
|
log_check_call(['lvcreate', '--size', '{mib}M'.format(mib=lv_size),
|
||||||
|
'--name', self.lv, self.vg])
|
||||||
|
|
||||||
|
def _before_attach(self, e):
|
||||||
|
log_check_call(['lvchange', '--activate', 'y', self.image_path])
|
||||||
|
[self.loop_device_path] = log_check_call(['losetup', '--show', '--find', '--partscan', self.image_path])
|
||||||
|
self.device_path = self.loop_device_path
|
||||||
|
|
||||||
|
def _before_detach(self, e):
|
||||||
|
log_check_call(['losetup', '--detach', self.loop_device_path])
|
||||||
|
log_check_call(['lvchange', '--activate', 'n', self.image_path])
|
||||||
|
del self.loop_device_path
|
||||||
|
self.device_path = None
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
log_check_call(['lvremove', '-f', self.image_path])
|
||||||
|
del self.image_path
|
37
bootstrapvz/common/tasks/logicalvolume.py
Normal file
37
bootstrapvz/common/tasks/logicalvolume.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import bootstrapvz.common.tasks.host as host
|
||||||
|
import bootstrapvz.common.tasks.volume as volume
|
||||||
|
from bootstrapvz.base import Task
|
||||||
|
from bootstrapvz.common import phases
|
||||||
|
|
||||||
|
|
||||||
|
class AddRequiredCommands(Task):
|
||||||
|
description = 'Adding commands required for creating and mounting logical volumes'
|
||||||
|
phase = phases.validation
|
||||||
|
successors = [host.CheckExternalCommands]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run(cls, info):
|
||||||
|
from bootstrapvz.common.fs.logicalvolume import LogicalVolume
|
||||||
|
if type(info.volume) is LogicalVolume:
|
||||||
|
info.host_dependencies['lvcreate'] = 'lvm2'
|
||||||
|
info.host_dependencies['losetup'] = 'mount'
|
||||||
|
|
||||||
|
|
||||||
|
class Create(Task):
|
||||||
|
description = 'Creating a Logical volume'
|
||||||
|
phase = phases.volume_creation
|
||||||
|
successors = [volume.Attach]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run(cls, info):
|
||||||
|
info.volume.create(volumegroup=info.manifest.volume['volumegroup'],
|
||||||
|
logicalvolume=info.manifest.volume['logicalvolume'])
|
||||||
|
|
||||||
|
|
||||||
|
class Delete(Task):
|
||||||
|
description = 'Deleting a Logical volume'
|
||||||
|
phase = phases.cleaning
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run(cls, info):
|
||||||
|
info.volume.delete()
|
|
@ -6,6 +6,7 @@ virtual images for Linux Kernel-based Virtual Machines. It supports the
|
||||||
installation of `virtio kernel
|
installation of `virtio kernel
|
||||||
modules <http://www.linux-kvm.org/page/Virtio>`__ (paravirtualized
|
modules <http://www.linux-kvm.org/page/Virtio>`__ (paravirtualized
|
||||||
drivers for IO operations).
|
drivers for IO operations).
|
||||||
|
It also supports creating an image with LVM as a disk backend.
|
||||||
|
|
||||||
Manifest settings
|
Manifest settings
|
||||||
-----------------
|
-----------------
|
||||||
|
@ -15,6 +16,9 @@ Provider
|
||||||
|
|
||||||
- ``virtio``: Specifies which virtio kernel modules to install.
|
- ``virtio``: Specifies which virtio kernel modules to install.
|
||||||
``optional``
|
``optional``
|
||||||
|
- ``logicalvolume``: Specifies the logical volume where the disk image will be built.
|
||||||
|
``volumegroup``: Specifies the volume group where the logical volume will be stored.
|
||||||
|
These options should only be used if ``lvm`` was given as a disk backend.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@ -26,3 +30,7 @@ Example:
|
||||||
virtio:
|
virtio:
|
||||||
- virtio_blk
|
- virtio_blk
|
||||||
- virtio_net
|
- virtio_net
|
||||||
|
volume:
|
||||||
|
backing: lvm
|
||||||
|
logicalvolume: lvtest
|
||||||
|
volumegroup: vgtest
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from bootstrapvz.common import task_groups
|
from bootstrapvz.common import task_groups
|
||||||
import tasks.packages
|
import tasks.packages
|
||||||
from bootstrapvz.common.tasks import image, loopback, initd, ssh
|
from bootstrapvz.common.tasks import image, loopback, initd, ssh, logicalvolume
|
||||||
|
|
||||||
|
|
||||||
def validate_manifest(data, validator, error):
|
def validate_manifest(data, validator, error):
|
||||||
|
@ -12,14 +12,20 @@ def resolve_tasks(taskset, manifest):
|
||||||
taskset.update(task_groups.get_standard_groups(manifest))
|
taskset.update(task_groups.get_standard_groups(manifest))
|
||||||
|
|
||||||
taskset.update([tasks.packages.DefaultPackages,
|
taskset.update([tasks.packages.DefaultPackages,
|
||||||
loopback.AddRequiredCommands,
|
|
||||||
loopback.Create,
|
|
||||||
initd.InstallInitScripts,
|
initd.InstallInitScripts,
|
||||||
ssh.AddOpenSSHPackage,
|
ssh.AddOpenSSHPackage,
|
||||||
ssh.ShredHostkeys,
|
ssh.ShredHostkeys,
|
||||||
ssh.AddSSHKeyGeneration,
|
ssh.AddSSHKeyGeneration,
|
||||||
image.MoveImage,
|
|
||||||
])
|
])
|
||||||
|
if manifest.volume.get('logicalvolume', []):
|
||||||
|
taskset.update([logicalvolume.AddRequiredCommands,
|
||||||
|
logicalvolume.Create,
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
taskset.update([loopback.AddRequiredCommands,
|
||||||
|
loopback.Create,
|
||||||
|
image.MoveImage,
|
||||||
|
])
|
||||||
|
|
||||||
if manifest.provider.get('virtio', []):
|
if manifest.provider.get('virtio', []):
|
||||||
from tasks import virtio
|
from tasks import virtio
|
||||||
|
@ -28,3 +34,4 @@ def resolve_tasks(taskset, manifest):
|
||||||
|
|
||||||
def resolve_rollback_tasks(taskset, manifest, completed, counter_task):
|
def resolve_rollback_tasks(taskset, manifest, completed, counter_task):
|
||||||
taskset.update(task_groups.get_standard_rollback_tasks(completed))
|
taskset.update(task_groups.get_standard_rollback_tasks(completed))
|
||||||
|
counter_task(taskset, logicalvolume.Create, logicalvolume.Delete)
|
||||||
|
|
|
@ -32,7 +32,11 @@ properties:
|
||||||
properties:
|
properties:
|
||||||
backing:
|
backing:
|
||||||
type: string
|
type: string
|
||||||
enum: [raw]
|
enum:
|
||||||
|
- raw
|
||||||
|
- lvm
|
||||||
|
logicalvolume: {type: string}
|
||||||
|
volumegroup: {type: string}
|
||||||
partitions:
|
partitions:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
26
manifests/examples/kvm/jessie-lvm.yml
Normal file
26
manifests/examples/kvm/jessie-lvm.yml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
---
|
||||||
|
name: debian-lvm-example
|
||||||
|
provider:
|
||||||
|
name: kvm
|
||||||
|
bootstrapper:
|
||||||
|
workspace: /target
|
||||||
|
system:
|
||||||
|
release: jessie
|
||||||
|
architecture: amd64
|
||||||
|
bootloader: grub
|
||||||
|
charmap: UTF-8
|
||||||
|
locale: en_US
|
||||||
|
timezone: UTC
|
||||||
|
volume:
|
||||||
|
backing: lvm
|
||||||
|
logicalvolume: lvtest
|
||||||
|
volumegroup: vgtest
|
||||||
|
partitions:
|
||||||
|
type: gpt
|
||||||
|
root:
|
||||||
|
filesystem: ext4
|
||||||
|
size: 1GB
|
||||||
|
packages: {}
|
||||||
|
plugins:
|
||||||
|
root_password:
|
||||||
|
password: test
|
Loading…
Add table
Reference in a new issue