11require 'open3'
22Puppet ::Type . type ( :filesystem ) . provide :aix do
3+ desc 'Manages logical volume filesystems on AIX'
34
4- desc "Manages logical volume filesystems on AIX"
5+ confine operatingsystem : :AIX
6+ defaultfor operatingsystem : :AIX
57
6- confine :operatingsystem => :AIX
7- defaultfor :operatingsystem => :AIX
8-
9- commands :crfs => 'crfs' ,
10- :chfs => 'chfs'
8+ commands crfs : 'crfs' ,
9+ chfs : 'chfs'
1110
1211 def exists?
1312 Open3 . popen3 ( "lsfs #{ @resource [ :name ] } " ) [ 3 ] . value . success?
@@ -16,7 +15,7 @@ def exists?
1615 def create
1716 args = [ ]
1817
19- attributes = [
18+ attributes = [
2019 :ag_size ,
2120 :large_files ,
2221 :compress ,
@@ -33,7 +32,7 @@ def create
3332 :agblksize ,
3433 :extended_attributes ,
3534 :mount_options ,
36- :vix
35+ :vix ,
3736 ]
3837
3938 args . push ( *add_attributes ( *attributes ) )
@@ -52,37 +51,37 @@ def create
5251 # size property after creation
5352 if @resource [ :size ]
5453 if size != @resource [ :size ]
55- self . size = ( @resource [ :size ] )
54+ self . size = ( @resource [ :size ] )
5655 end
5756 end
5857 end
5958
6059 def attribute_flag ( pvalue )
6160 {
62- : ag_size => 'ag' ,
63- : large_file => 'bf' ,
64- : initial_size => 'size' ,
65- : size => 'size' ,
66- : extended_attributes => 'ea' ,
67- : mount_options => 'options' ,
68- : encrypted => 'efs'
61+ ag_size : 'ag' ,
62+ large_file : 'bf' ,
63+ initial_size : 'size' ,
64+ size : 'size' ,
65+ extended_attributes : 'ea' ,
66+ mount_options : 'options' ,
67+ encrypted : 'efs' ,
6968 } [ pvalue ] || pvalue . to_s
7069 end
7170
7271 def add_attributes ( *args )
73- attr_args = [ ]
72+ attr_args = [ ]
7473 args . each do |arg |
7574 if @resource [ arg ]
76- ans = parse_boolean ( @resource [ arg ] )
75+ ans = parse_boolean ( @resource [ arg ] )
7776 attr_args . push ( '-a' , "#{ attribute_flag ( arg ) } =#{ @resource [ arg ] } " )
7877 end
7978 end
8079 attr_args
8180 end
8281
83- def add_flag ( flag , param )
82+ def add_flag ( flag , param )
8483 if @resource [ param ]
85- [ "-#{ flag . to_s } " , " #{ parse_boolean ( @resource [ param ] ) } " ]
84+ [ "-#{ flag } " , parse_boolean ( @resource [ param ] ) . to_s ]
8685 end
8786 end
8887
@@ -98,71 +97,71 @@ def parse_boolean(param)
9897 end
9998
10099 def size
101- cursize = 0
102- reqsize = blk_roundup ( val_to_blk ( @resource [ :size ] ) )
100+ cursize = 0
101+ reqsize = blk_roundup ( val_to_blk ( @resource [ :size ] ) )
103102
104- Open3 . popen3 ( "lsfs -q #{ @resource [ :name ] } " ) do |stdin , stdout , stderr |
103+ Open3 . popen3 ( "lsfs -q #{ @resource [ :name ] } " ) do |_stdin , stdout , _stderr |
105104 stdout . each do |line |
106- elements = line . split ( / \s +/ )
105+ elements = line . split ( %r{ \s +} )
107106 if elements [ 2 ] == @resource [ :name ]
108- cursize = elements [ 4 ] . to_i
107+ cursize = elements [ 4 ] . to_i
109108 end
110109 end
111110 end
112111
113112 if cursize == reqsize
114113 @resource [ :size ]
115114 else
116- blk_to_val ( cursize , @resource [ :size ] [ -1 , 1 ] )
115+ blk_to_val ( cursize , @resource [ :size ] [ -1 , 1 ] )
117116 end
118117 end
119118
120- def size = ( newsize )
121- chfs ( '-a' , "size=#{ @resource [ :size ] } " , @resource [ :name ] )
119+ def size = ( _newsize )
120+ chfs ( '-a' , "size=#{ @resource [ :size ] } " , @resource [ :name ] )
122121 end
123122
124123 def val_to_blk ( val )
125- input = val . match ( / (\d +)([^0-9]|)/ ) . to_a
124+ input = val . match ( %r{ (\d +)([^0-9]|)} ) . to_a
126125 case input [ 2 ]
127126 when 'M'
128- input [ 1 ] . to_i * 1024 * 2
127+ input [ 1 ] . to_i * 1024 * 2
129128 when 'G'
130- input [ 1 ] . to_i * 1024 * 1024 * 2
129+ input [ 1 ] . to_i * 1024 * 1024 * 2
131130 else
132131 input [ 1 ] . to_i
133132 end
134133 end
135134
136- def blk_to_val ( blocks , units = nil )
135+ def blk_to_val ( blocks , units = nil )
137136 case units
138137 when 'M'
139- sprintf ( '%gM' , Float ( blocks . to_i / 2 / 1024 ) )
138+ '%gM' % Float ( blocks . to_i / 2 / 1024 )
140139 when 'G'
141- sprintf ( '%gG' , Float ( blocks . to_i / 2 / 1024 / 1024 ) )
140+ '%gG' % Float ( blocks . to_i / 2 / 1024 / 1024 )
142141 else
143142 blocks
144143 end
145144 end
146145
147146 def blk_roundup ( blocks )
148- ppsize = Integer ( pp_size * 1024 * 2 )
149- ppsize * Float ( Float ( blocks ) / ppsize ) . ceil . to_i
147+ ppsize = Integer ( pp_size * 1024 * 2 )
148+ ppsize * Float ( Float ( blocks ) / ppsize ) . ceil . to_i
150149 end
151150
152151 def pp_size
153152 vg = @resource [ :volume_group ] || 'rootvg'
154- Open3 . capture2 ( "lsvg #{ vg } | /bin/grep 'PP SIZE'" ) [ 0 ] . split ( / \s +/ ) [ 5 ] . to_i
153+ Open3 . capture2 ( "lsvg #{ vg } | /bin/grep 'PP SIZE'" ) [ 0 ] . split ( %r{ \s +} ) [ 5 ] . to_i
155154 end
156155
157156 def attribute_flag ( pvalue )
158157 {
159- : ag_size => 'ag' ,
160- : large_file => 'bf' ,
161- : initial_size => 'size' ,
162- : size => 'size' ,
163- : extended_attributes => 'ea' ,
164- : mount_options => 'options' ,
165- : encrypted => 'efs'
158+ ag_size : 'ag' ,
159+ large_file : 'bf' ,
160+ initial_size : 'size' ,
161+ size : 'size' ,
162+ extended_attributes : 'ea' ,
163+ mount_options : 'options' ,
164+ encrypted : 'efs' ,
166165 } [ pvalue ] || pvalue . to_s
167166 end
168167end
0 commit comments