Skip to content

Commit

Permalink
Merge pull request #279 from bmlit/yes_arg
Browse files Browse the repository at this point in the history
Add yes argument when creating/extending a LV
  • Loading branch information
jordanbreen28 authored Jul 24, 2023
2 parents c437d99 + 72da9f1 commit 22ba15e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ Lint/Void:
# Offense count: 10
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 83
Max: 85

# Offense count: 11
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 199
Max: 256

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 30
Max: 32

# Offense count: 13
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 44
Max: 50

# Offense count: 1
# Configuration parameters: Max, CountKeywordArgs.
Expand All @@ -67,7 +67,7 @@ Metrics/ParameterLists:
# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 33
Max: 35

# Offense count: 3
Naming/AccessorMethodName:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ resources out yourself.
* stripesize (Parameter) - The stripesize to use for the new logical volume.
* thinpool (Parameter) - Default value: `false` - Set to true to create a thin pool or to pool name to create thin volume
* 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.
* yes_flag (Parameter) - Default value: `false` - If set to true, do not prompt for confirmation interactively but always assume the answer yes.

### physical_volume

Expand Down
7 changes: 6 additions & 1 deletion lib/puppet/provider/logical_volume/lvm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def create
else
args << @resource[:volume_group]
end

args.push('--yes') if @resource[:yes_flag]
lvcreate(*args)
end

Expand Down Expand Up @@ -183,7 +185,10 @@ def size=(new_size)
end

if resizeable
lvextend('-L', new_size, path) || raise("Cannot extend to size #{new_size} because lvextend failed.")
args = []
args.push('--yes') if @resource[:yes_flag]

lvextend('-L', new_size, path, *args) || raise("Cannot extend to size #{new_size} because lvextend failed.")

unless @resource[:resize_fs] == :false || @resource[:resize_fs] == false || @resource[:resize_fs] == 'false'
begin
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/logical_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ def insync?(is)
end
end

newparam(:yes_flag) do
desc 'If set to true, do not prompt for confirmation interactively but always assume the answer yes.'
defaultto false
end

autorequire(:volume_group) do
@parameters[:volume_group].value
end
Expand Down
4 changes: 4 additions & 0 deletions manifests/logical_volume.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
# :inherit
# :normal

# @param yes_flag If set to true, do not prompt for confirmation interactively but always assume the answer yes.

#
define lvm::logical_volume (
String[1] $volume_group,
Expand Down Expand Up @@ -78,6 +80,7 @@
Optional[Boolean] $no_sync = undef,
Optional[Variant[String[1], Integer]] $region_size = undef,
Optional[Enum['anywhere', 'contiguous', 'cling', 'inherit', 'normal']] $alloc = undef,
Boolean $yes_flag = false,
) {
$lvm_device_path = "/dev/${volume_group}/${name}"

Expand Down Expand Up @@ -139,6 +142,7 @@
no_sync => $no_sync,
region_size => $region_size,
alloc => $alloc,
yes_flag => $yes_flag,
}

if $createfs {
Expand Down
8 changes: 6 additions & 2 deletions tasks/ensure_lv.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
"region_size": {
"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.",
"type": "Optional[Integer]"
}
},
"yes_flag": {
"description": "If set to true, do not prompt for confirmation interactively but always assume the answer yes.",
"type": "Boolean"
}
}
}
}
1 change: 1 addition & 0 deletions tasks/ensure_lv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
logical_volume[:alloc] = params['alloc'] if params['alloc']
logical_volume[:no_sync] = params['no_sync'] if params['no_sync']
logical_volume[:region_size] = params['region_size'] if params['region_size']
logical_volume[:yes_flag] = params['yes_flag'] if params['yes_flag']

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

0 comments on commit 22ba15e

Please sign in to comment.