Disk partitioning
Ability to create partitions on empty disks.
Change-Id: I0a71da9d62d8f7df3fa03e3f34d49bad6988ba6d
diff --git a/README.rst b/README.rst
index 51e6370..ca6d005 100644
--- a/README.rst
+++ b/README.rst
@@ -1269,6 +1269,28 @@
size: 40G
mount: ${linux:storage:mount:data}
+Create partitions on disk. Specify size in MB. It expects empty
+disk without any existing partitions.
+
+.. code-block:: yaml
+
+ linux:
+ storage:
+ disk:
+ first_drive:
+ name: /dev/loop1
+ type: gpt
+ partitions:
+ - size: 200 #size in MB
+ type: fat32
+ - size: 300 #size in MB
+ type: ext4
+ /dev/vda1:
+ partitions:
+ - size: 5
+ type: ext2
+ - size: 10
+ type: ext4
Multipath with Fujitsu Eternus DXL
diff --git a/linux/storage/disk.sls b/linux/storage/disk.sls
new file mode 100644
index 0000000..0c8dd3b
--- /dev/null
+++ b/linux/storage/disk.sls
@@ -0,0 +1,35 @@
+{%- from "linux/map.jinja" import storage with context %}
+{%- if storage.enabled %}
+
+{%- for disk_name, disk in storage.disk.iteritems() %}
+
+{%- if disk.type is defined %}
+create_disk_label:
+ module.run:
+ - name: partition.mklabel
+ - device: {{ disk.name|default(disk_name) }}
+ - label_type: {{ disk.get('type', 'gpt') }}
+ - unless: fdisk -l | grep {{ disk.get('type', 'gpt') }}
+{%- endif %}
+
+{% set end_size = 0 -%}
+
+{%- for partition in disk.get('partitions', []) %}
+
+{%- if not salt['partition.exists'](disk.get('name', disk_name)+'p'~loop.index) %}
+create_partition_{{ disk.name|default(disk_name) }}_{{ loop.index }}:
+ module.run:
+ - name: partition.mkpart
+ - device: {{ disk.name|default(disk_name) }}
+ - part_type: primary
+ - fs_type: {{ partition.type }}
+ - start: {{ end_size }}MB
+ - end: {{ end_size + partition.size }}MB
+{%- endif %}
+
+{% set end_size = end_size + partition.size -%}
+
+{%- endfor %}
+{%- endfor %}
+
+{%- endif %}
diff --git a/linux/storage/init.sls b/linux/storage/init.sls
index a5b78eb..b996b73 100644
--- a/linux/storage/init.sls
+++ b/linux/storage/init.sls
@@ -1,9 +1,12 @@
{%- from "linux/map.jinja" import storage with context %}
-{%- if storage.mount|length > 0 or storage.swap|length > 0 or storage.multipath.enabled or storage.lvm|length > 0 or storage.loopback|length > 0 %}
+{%- if storage.mount|length > 0 or storage.swap|length > 0 or storage.multipath.enabled or storage.disk|length > 0 or storage.lvm|length > 0 or storage.loopback|length > 0 %}
include:
{%- if storage.loopback|length > 0 %}
- linux.storage.loopback
{%- endif %}
+{%- if storage.disk|length > 0 %}
+- linux.storage.disk
+{%- endif %}
{%- if storage.lvm|length > 0 %}
- linux.storage.lvm
{%- endif %}
diff --git a/tests/pillar/storage.sls b/tests/pillar/storage.sls
index 17f3b9c..0a92f91 100644
--- a/tests/pillar/storage.sls
+++ b/tests/pillar/storage.sls
@@ -50,12 +50,12 @@
device: /dev/vg0/lv03
path: /mnt/lv03
file_system: xfs
- disk1:
- enabled: true
- device: /dev/loop_dev4
- path: /tmp/dummy
- file_system: xfs
- options: "noatime,nobarrier,logbufs=8"
- user: nobody
- group: nogroup
- mode: 755
+ disk:
+ first_drive:
+ name: /tmp/loop_dev4
+ type: gpt
+ partitions:
+ - size: 5
+ type: fat32
+ - size: 5
+ type: fat32