Skip to content

Commit 3651066

Browse files
committed
Add yes argument when creating/extending a LV
1 parent c437d99 commit 3651066

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ resources out yourself.
201201
* stripesize (Parameter) - The stripesize to use for the new logical volume.
202202
* thinpool (Parameter) - Default value: `false` - Set to true to create a thin pool or to pool name to create thin volume
203203
* volume_group (Parameter) - The volume group name associated with this logical volume. This will automatically set this volume group as a dependency, but it must be defined elsewhere using the volume_group resource type.
204+
* yes (Parameter) - Default value: `false` - Do not prompt for confirmation interactively but always assume the answer yes.
204205

205206
### physical_volume
206207

lib/puppet/provider/logical_volume/lvm.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def create
118118
else
119119
args << @resource[:volume_group]
120120
end
121+
122+
if @resource[:yes]
123+
args.push('--yes')
124+
end
121125
lvcreate(*args)
122126
end
123127

@@ -183,7 +187,11 @@ def size=(new_size)
183187
end
184188

185189
if resizeable
186-
lvextend('-L', new_size, path) || raise("Cannot extend to size #{new_size} because lvextend failed.")
190+
args = []
191+
if @resource[:yes]
192+
args.push('--yes')
193+
end
194+
lvextend('-L', new_size, path, *args) || raise("Cannot extend to size #{new_size} because lvextend failed.")
187195

188196
unless @resource[:resize_fs] == :false || @resource[:resize_fs] == false || @resource[:resize_fs] == 'false'
189197
begin

lib/puppet/type/logical_volume.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ def insync?(is)
180180
end
181181
end
182182

183+
newparam(:yes) do
184+
desc "Do not prompt for confirmation interactively but always assume the answer yes."
185+
defaultto false
186+
end
187+
183188
autorequire(:volume_group) do
184189
@parameters[:volume_group].value
185190
end

manifests/logical_volume.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
Optional[Boolean] $no_sync = undef,
7979
Optional[Variant[String[1], Integer]] $region_size = undef,
8080
Optional[Enum['anywhere', 'contiguous', 'cling', 'inherit', 'normal']] $alloc = undef,
81+
Optional[Boolean] $yes_flag = false,
8182
) {
8283
$lvm_device_path = "/dev/${volume_group}/${name}"
8384

@@ -139,6 +140,7 @@
139140
no_sync => $no_sync,
140141
region_size => $region_size,
141142
alloc => $alloc,
143+
yes => $yes,
142144
}
143145

144146
if $createfs {

tasks/ensure_lv.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
"region_size": {
8181
"description": "A mirror is divided into regions of this size (in MB), the mirror log uses this granularity to track which regions are in sync. CAN NOT BE CHANGED on already mirrored volume. Take your mirror size in terabytes and round up that number to the next power of 2, using that number as the -R argument.",
8282
"type": "Optional[Integer]"
83-
}
83+
},
84+
"yes": {
85+
"description": "Do not prompt for confirmation interactively but always assume the answer yes.",
86+
"type": "Optional[Boolean]"
87+
}
8488
}
85-
}
89+
}

tasks/ensure_lv.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
logical_volume[:alloc] = params['alloc'] if params['alloc']
5151
logical_volume[:no_sync] = params['no_sync'] if params['no_sync']
5252
logical_volume[:region_size] = params['region_size'] if params['region_size']
53+
logical_volume[:yes] = params['yes'] if params['yes']
5354

5455
# Save the result
5556
_resource, report = Puppet::Resource.indirection.save(logical_volume)

0 commit comments

Comments
 (0)