Manage the size of the partition

Now we can choose the size of the partition. Currently you can only use
three disks and the size is in GB. If the size of the disk is not
provided we use all the remaining free space available on the disk. If
you are asking for a size that doesn't fit, installation will fail.

Change-Id: If8c11af99595f899a444fb09f719d441d78c6388
This commit is contained in:
Guillaume Thouvenin 2015-04-17 18:37:01 +02:00
parent 736fa46530
commit 12ff7873e8
6 changed files with 104 additions and 18 deletions

View File

@ -78,6 +78,15 @@ User Guide
5. Scroll down the page, select the "Elasticsearch-Kibana Server plugin" checkbox
and fill-in the required fields.
You can select up to 3 physical disks that will be mounted as a single logical
volume to store the Elasticsearch data. If you specify no disk, the data will
be stored on the root filesystem. In all cases, Elasticsearch data will be
located in the */opt/es-data* directory.
For each disk, you can also specify the allocated size (in GB). If you don't
specify a value, the plugin will use all the free space of the disk.
Testing
-------

View File

@ -2,12 +2,26 @@ $elasticsearch_kibana = hiera('elasticsearch_kibana')
if $elasticsearch_kibana['node_name'] == hiera('user_node_name') {
$disks = regsubst($elasticsearch_kibana['dedicated_disks'], '([a-z]+)', '/dev/\1', 'G')
$array_disks = split($disks, ',')
class { 'disk_management': }
disk_management::partition { $array_disks:
require => Class['disk_management']
if ($elasticsearch_kibana['disk1']) {
disk_management::partition { "/dev/${elasticsearch_kibana['disk1']}":
size => $elasticsearch_kibana['disk1_size'],
require => Class['disk_management'],
}
}
if ($elasticsearch_kibana['disk2']) {
disk_management::partition { "/dev/${elasticsearch_kibana['disk2']}":
size => $elasticsearch_kibana['disk2_size'],
require => Class['disk_management'],
}
}
if ($elasticsearch_kibana['disk3']) {
disk_management::partition { "/dev/${elasticsearch_kibana['disk3']}":
size => $elasticsearch_kibana['disk3_size'],
require => Class['disk_management'],
}
}
}

View File

@ -5,10 +5,13 @@
# RAID 1 with /boot on all disks so we need to deal with that.
# $1 -> The disk (example: "/dev/sdb")
# $2 -> Size of the partition (use all free space if not provided)
set -eux
DISK=$1
DISK_SIZE=${2:-""}
PARTED="$(which parted 2>/dev/null) -s -m"
if ${PARTED} ${DISK} p | grep -q "unrecognised disk label"; then
@ -17,15 +20,22 @@ if ${PARTED} ${DISK} p | grep -q "unrecognised disk label"; then
fi
# We take the free space at the end of the disk.
FREESPACE=$(${PARTED} ${DISK} unit s p free | grep "free" | tail -1 | awk -F: '{print $2, $3}')
FREESPACE=$(${PARTED} ${DISK} unit B p free | grep "free" | tail -1)
if [[ -z "${FREESPACE}" ]]; then
echo "Failed to find free space"
exit 1
fi
BEGIN=$(echo ${FREESPACE} | awk -F: '{print $2}')
if [ -z ${DISK_SIZE} ]; then
END=$(echo ${FREESPACE} | awk -F: '{print $3}')
else
END="$(( $(echo $BEGIN | rev | cut -c 2- | rev) + $(( ${DISK_SIZE}*1024*1024*1024 )) ))B"
fi
# If you create a partition on a mounted disk, this command returns 1
# So we need a different way to catch the error
if ${PARTED} ${DISK} unit s mkpart primary ${FREESPACE} | grep -q "^Error"; then
if ${PARTED} ${DISK} unit B mkpart primary ${BEGIN} ${END} | grep -q "^Error"; then
echo "Failed to create a new primary partition"
exit 1
fi

View File

@ -5,6 +5,8 @@ define disk_management::lvm_fs (
$lv_name,
$vg_name,
$fstype = 'ext3',
$group = 'root',
$owner = 'root',
) {
$directory = $title
@ -21,6 +23,8 @@ define disk_management::lvm_fs (
# create the directory
file { $directory:
ensure => directory,
group => $group,
owner => $owner,
}
# Mount the directory

View File

@ -2,13 +2,15 @@
# If a disk is given as title we check for free space and allocated
# this free space by calling the script given as parameter.
define disk_management::partition {
define disk_management::partition (
$size = undef,
){
include disk_management::params
$disk = $title
$script = $disk_management::params::script_location
$cmd = "${script} ${disk}"
$cmd = "${script} ${disk} ${size}"
exec { $title:
command => $cmd,

View File

@ -7,20 +7,67 @@ attributes:
weight: 10
type: "text"
dedicated_disks:
value: ''
label: 'Dedicated disks'
description: 'Comma-separated list of disk devices used to store Elasticsearch data (for instance "sda,sdb"). Keep it empty means using "/"'
weight: 20
type: "text"
# Parameter hidden in the UI on purpose
data_dir:
value: '/es-data'
value: '/opt/es-data'
label: 'Elasticsearch directory'
description: 'Directory used by elasticsearch to store data'
weight: 30
weight: 15
type: "text"
restrictions:
- condition: true
action: hide
disk1:
value: ''
label: 'Disk 1'
description: 'Disk device used to store Elasticsearch data (for instance sda). Leave it empty to use "/".'
weight: 20
type: "text"
disk1_size:
value: ''
label: 'Size'
description: 'in GB. Leave it empty to use all free space.'
weight: 30
type: "text"
disk2:
value: ''
label: 'Disk 2'
description: 'Disk device used to store Elasticsearch data (for instance sdb).'
weight: 40
type: "text"
restrictions:
- condition: "settings:elasticsearch_kibana.disk1.value == ''"
action: "disable"
disk2_size:
value: ''
label: 'Size'
description: 'in GB. Leave it empty to use all free space.'
weight: 50
type: "text"
restrictions:
- condition: "settings:elasticsearch_kibana.disk1.value == ''"
action: "disable"
disk3:
value: ''
label: 'Disk 3'
description: 'Disk device used to store Elasticsearch data (for instance sdc).'
weight: 60
type: "text"
restrictions:
- condition: "settings:elasticsearch_kibana.disk2.value == ''"
action: "disable"
disk3_size:
value: ''
label: 'Size'
description: 'in GB. Leave it empty to use all free space.'
weight: 70
type: "text"
restrictions:
- condition: "settings:elasticsearch_kibana.disk2.value == ''"
action: "disable"