block-device: change top level config from dict to list

With the old configuration structure it was only possible
to use one image and one partition layout.  The new
block-device configuration uses a list at top level;
therefore it is possible to use multiple instances
of each element type.

Change-Id: I9db4327486b676887d6ce09609994116dbebfc89
Signed-off-by: Andreas Florath <andreas@florath.net>
This commit is contained in:
Andreas Florath 2017-02-03 20:09:58 +00:00
parent 3f8800832a
commit a8953dd277
3 changed files with 54 additions and 45 deletions

View file

@ -34,13 +34,13 @@ class BlockDevice(object):
# Default configuration:
# one image, one partition, mounted under '/'
DefaultConfig = """
local_loop:
name: image0
- local_loop:
name: image0
"""
# This is an example of the next level config
# mkfs:
# base: root_p1
# base: root
# type: ext4
# mount_point: /
@ -85,7 +85,16 @@ local_loop:
# add the appropriate nodes and edges.
dg = Digraph()
for cfg_obj_name, cfg_obj_val in config.items():
for config_entry in config:
if len(config_entry) != 1:
logger.error("Invalid config entry: more than one key "
"on top level [%s]" % config_entry)
raise BlockDeviceSetupException(
"Top level config must contain exactly one key per entry")
logger.debug("Config entry [%s]" % config_entry)
cfg_obj_name = config_entry.keys()[0]
cfg_obj_val = config_entry[cfg_obj_name]
# As the first step the configured objects are created
# (if it exists)
if cfg_obj_name not in BlockDevice.cfg_type_map:
@ -132,8 +141,8 @@ local_loop:
# result to stdout.
# If there is no partition needed, pass back directly the
# image.
if 'root_p1' in result:
print("%s" % result['root_p1']['device'])
if 'root' in result:
print("%s" % result['root']['device'])
else:
print("%s" % result['image0']['device'])

View file

@ -1,14 +1,14 @@
export DIB_BLOCK_DEVICE_DEFAULT_CONFIG="
local_loop:
name: image0
- local_loop:
name: image0
partitioning:
base: image0
label: mbr
partitions:
- name: root_p1
flags: [ boot, primary ]
size: 100%
- partitioning:
base: image0
label: mbr
partitions:
- name: root
flags: [ boot, primary ]
size: 100%
"
DIB_BLOCK_DEVICE_CONFIG=${DIB_BLOCK_DEVICE_CONFIG:-${DIB_BLOCK_DEVICE_DEFAULT_CONFIG}}

View file

@ -60,7 +60,7 @@ formats are:
Disk Image Layout
-----------------
When generating a block image (e.g. qcow2 or raw), by default one
When generating a vm block image (e.g. qcow2 or raw), by default one
image with one partition holding all files is created.
The configuration is done by means of the environment variable
@ -72,16 +72,16 @@ The default is:
::
DIB_BLOCK_DEVICE_CONFIG='
local_loop:
name: image0
- local_loop:
name: image0
partitioning:
base: image0
label: mbr
partitions:
- name: root_p1
flags: [ boot, primary ]
size: 100%'
- partitioning:
base: image0
label: mbr
partitions:
- name: root
flags: [ boot, primary ]
size: 100%'
In general each module that depends on another module has a `base`
element that points to the depending base.
@ -103,7 +103,7 @@ all but the `image0` will be not useable (are deleted during the
build process).
Currently only one partitions is used for the image. The name of this
partition must be `root_p1`. Other partitions are created but not
partition must be `root`. Other partitions are created but not
used.
Level 0
@ -239,26 +239,26 @@ size
Example:
::
partitioning:
base: image0
label: mbr
partitions:
- name: part-01
flags: [ boot ]
size: 1GiB
- name: part-02
size: 100%
- partitioning:
base: image0
label: mbr
partitions:
- name: part-01
flags: [ boot ]
size: 1GiB
- name: part-02
size: 100%
partitioning:
base: data_image
label: mbr
partitions:
- name: data0
size: 33%
- name: data1
size: 50%
- name: data2
size: 100%
- partitioning:
base: data_image
label: mbr
partitions:
- name: data0
size: 33%
- name: data1
size: 50%
- name: data2
size: 100%
On the `image0` two partitions are created. The size of the first is
1GiB, the second uses the remaining free space. On the `data_image`