2323 def self . instances
2424 get_logical_volumes . collect do |logical_volumes_line |
2525 logical_volumes_properties = get_logical_volume_properties ( logical_volumes_line )
26- new ( logical_volumes_properties )
26+ instance = new ( logical_volumes_properties )
27+ # Save the volume group in the provider so the type can find it
28+ instance . volume_group = logical_volumes_properties [ :volume_group ]
29+ instance
2730 end
2831 end
2932
@@ -46,13 +49,21 @@ def self.get_logical_volume_properties(logical_volumes_line)
4649 output_array = logical_volumes_line . gsub ( /\s +/m , ' ' ) . strip . split ( " " )
4750
4851 # Assign properties based on headers
49- # Just doing name for now...
50- logical_volumes_properties [ :ensure ] = :present
51- logical_volumes_properties [ :name ] = output_array [ 0 ]
52+ logical_volumes_properties [ :ensure ] = :present
53+ logical_volumes_properties [ :name ] = output_array [ 0 ]
54+ logical_volumes_properties [ :volume_group ] = output_array [ 1 ]
5255
5356 logical_volumes_properties
5457 end
5558
59+ # Just assume that the volume group is correct, we don't support changing
60+ # it anyway.
61+ attr_writer :volume_group
62+
63+ def volume_group
64+ @resource ? @resource [ :volume_group ] : @volume_group
65+ end
66+
5667 def create
5768 args = [ ]
5869
@@ -148,12 +159,23 @@ def destroy
148159 end
149160
150161 def exists?
151- lvs ( @resource [ :volume_group ] ) =~ lvs_pattern
162+ begin
163+ lvs ( @resource [ :volume_group ] ) =~ /#{ @resource [ :name ] } /
164+ rescue Puppet ::ExecutionFailure
165+ # lvs fails if we give it an empty volume group name, as would
166+ # happen if we were running `puppet resource`. This should be
167+ # interpreted as "The resource does not exist"
168+ nil
169+ end
152170 end
153171
154172 def size
155173 if @resource [ :size ] =~ /^\d +\. ?\d {0,2}([KMGTPE])/i
156174 unit = $1. downcase
175+ else
176+ # If we are getting the size initially we don't know what the
177+ # units will be, default to GB
178+ unit = 'g'
157179 end
158180
159181 raw = lvs ( '--noheading' , '--unit' , unit , path )
@@ -303,9 +325,6 @@ def mirrorlog=( new_mirror_log_location )
303325 end
304326 end
305327
306-
307-
308-
309328 private
310329
311330 def lvs_pattern
0 commit comments