diff --git a/REFERENCE.md b/REFERENCE.md index 7eff1478..32f34812 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -799,6 +799,7 @@ The following parameters are available in the `logical_volume` type. * [`name`](#-logical_volume--name) * [`no_sync`](#-logical_volume--no_sync) * [`persistent`](#-logical_volume--persistent) +* [`physical_volume`](#-logical_volume--physical_volume) * [`poolmetadatasize`](#-logical_volume--poolmetadatasize) * [`provider`](#-logical_volume--provider) * [`range`](#-logical_volume--range) @@ -844,6 +845,10 @@ An optimization in lvcreate, at least on Linux. Set to true to make the block device persistent +##### `physical_volume` + +Create this logical volume on the specified physical volume + ##### `poolmetadatasize` Change the size of logical volume pool metadata diff --git a/lib/puppet/provider/logical_volume/lvm.rb b/lib/puppet/provider/logical_volume/lvm.rb index 6110bd17..f9493031 100644 --- a/lib/puppet/provider/logical_volume/lvm.rb +++ b/lib/puppet/provider/logical_volume/lvm.rb @@ -120,6 +120,7 @@ def create end args.push('--yes') if @resource[:yes_flag] + args.push(@resource[:physical_volume]) if @resource[:physical_volume] lvcreate(*args) end diff --git a/lib/puppet/type/logical_volume.rb b/lib/puppet/type/logical_volume.rb index 9232ce00..1f98b534 100644 --- a/lib/puppet/type/logical_volume.rb +++ b/lib/puppet/type/logical_volume.rb @@ -119,6 +119,24 @@ def insync?(is) end end + newparam(:physical_volume) do + desc 'The name of the physical volume on which this logical volume will be created' + validate do |val| + unless val.is_a?(::String) || val.is_a?(::Array) + raise ArgumentError, "physical_volume should be String or Array: #{val}" + end + end + + munge do |val| + case val + when ::String + [val] + else + val + end + end + end + newproperty(:stripes) do desc 'The number of stripes to allocate for the new logical volume.' validate do |value| diff --git a/manifests/logical_volume.pp b/manifests/logical_volume.pp index 0f41081b..fe50c5b3 100644 --- a/manifests/logical_volume.pp +++ b/manifests/logical_volume.pp @@ -62,6 +62,8 @@ # # @param yes_flag If set to true, do not prompt for confirmation interactively but always assume the answer yes. # +# @param physical_volume Create this logical volume on the specified physical volume +# define lvm::logical_volume ( String[1] $volume_group, Optional[String[1]] $size = undef, @@ -91,6 +93,7 @@ Optional[Variant[String[1], Integer]] $region_size = undef, Optional[Enum['anywhere', 'contiguous', 'cling', 'inherit', 'normal']] $alloc = undef, Boolean $yes_flag = false, + Optional[Variant[Array[String],String]] $physical_volume = undef, ) { $lvm_device_path = "/dev/${volume_group}/${name}" @@ -153,6 +156,7 @@ region_size => $region_size, alloc => $alloc, yes_flag => $yes_flag, + physical_volume => $physical_volume, } if $createfs { diff --git a/spec/unit/type/logical_volume_spec.rb b/spec/unit/type/logical_volume_spec.rb index d4dac5ce..999206e7 100644 --- a/spec/unit/type/logical_volume_spec.rb +++ b/spec/unit/type/logical_volume_spec.rb @@ -185,6 +185,19 @@ }.not_to raise_error end + it 'raises an ArgumentError when the physical volume is neither string nor array' do + expect { + resource = Puppet::Type.type(:logical_volume).new( + name: 'john', + ensure: :present, + volume_group: 'ernie', + size: '10M', + physical_volume: 42, + ) + }.to raise_error(Puppet::ResourceError, + 'physical_volume should be String or Array: 42') + end + it 'invalid number of stripes raises error' do expect { resource = Puppet::Type.type(:logical_volume).new(