Class: Puppet::Provider::SwiftRingBuilder
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::SwiftRingBuilder
- Defined in:
- lib/puppet/provider/swift_ring_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #address_string(address) ⇒ Object
- #balance ⇒ Object
- #balance=(balance) ⇒ Object
- #builder_file_path(policy_index) ⇒ Object
- #create ⇒ Object
- #device_path ⇒ Object
- #exists? ⇒ Boolean
- #id ⇒ Object
- #id=(id) ⇒ Object
- #lookup_ring ⇒ Object
- #meta ⇒ Object
- #meta=(meta) ⇒ Object
- #partitions ⇒ Object
- #partitions=(part) ⇒ Object
- #policy_index ⇒ Object
- #region ⇒ Object
- #region=(region) ⇒ Object
- #weight ⇒ Object
- #weight=(weight) ⇒ Object
- #zone ⇒ Object
- #zone=(zone) ⇒ Object
Class Method Details
.instances ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 3 def self.instances # TODO iterate through the databases # and add the database that we used a property ring.keys.collect do |name| new(:name => name) end end |
Instance Method Details
#address_string(address) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 11 def address_string(address) ip = IPAddr.new(address) if ip.ipv6? '[' + ip.to_s + ']' else ip.to_s end end |
#balance ⇒ Object
240 241 242 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 240 def balance ring[resource[:name]][:balance] end |
#balance=(balance) ⇒ Object
244 245 246 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 244 def balance=(balance) raise(Puppet::Error, "Cannot set balance, it is set by rebalancing") end |
#builder_file_path(policy_index) ⇒ Object
144 145 146 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 144 def builder_file_path(policy_index) self.class.builder_file_path(policy_index) end |
#create ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 152 def create [:zone, :weight].each do |param| raise(Puppet::Error, "#{param} is required") unless resource[param] end if :region == 'none' # Prior to Swift 1.8.0, regions did not exist. swift_ring_builder( builder_file_path(policy_index), 'add', "z#{resource[:zone]}-#{device_path}_#{resource[:meta]}", resource[:weight] ) else # Swift 1.8+ # Region defaults to 1 if unspecified resource[:region] ||= 1 swift_ring_builder( builder_file_path(policy_index), 'add', "r#{resource[:region]}z#{resource[:zone]}-#{device_path}_#{resource[:meta]}", resource[:weight] ) end end |
#device_path ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 177 def device_path if resource[:name].split(/^\d+:/)[1].nil? return resource[:name] else return resource[:name].split(/^\d+:/)[1] end end |
#exists? ⇒ Boolean
148 149 150 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 148 def exists? ring[resource[:name]] end |
#id ⇒ Object
193 194 195 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 193 def id ring[resource[:name]][:id] end |
#id=(id) ⇒ Object
197 198 199 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 197 def id=(id) raise(Puppet::Error, "Cannot assign id, it is immutable") end |
#lookup_ring ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 20 def lookup_ring object_hash = {} if File.exists?(builder_file_path(policy_index)) # Swift < 2.2.2 Skip first 4 info lines from swift-ring-builder output if rows = swift_ring_builder(builder_file_path(policy_index)).split("\n")[4..-1] # Skip "Ring file ... is up-to-date" message, if printed. if !rows[0].nil? and rows[0] =~ /Ring file\b.*\bis up-to-date/ rows.shift end # Swift 2.2.2+ Skip additional line to account for Overload info if !rows[0].nil? and rows[0].start_with?('Devices:') rows.shift end rows.each do |row| # Swift 1.7+ output example: # /etc/swift/object.builder, build version 1 # 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion # The minimum number of hours before a partition can be reassigned is 1 # Devices: id region zone ip address port name weight partitions balance meta # 0 1 2 127.0.0.1 6022 2 1.00 262144 0.00 # 0 1 3 192.168.101.15 6002 1 1.00 262144 -100.00 # # Swift 1.8.0 output example: # /etc/swift/object.builder, build version 1 # 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion # The minimum number of hours before a partition can be reassigned is 1 # Devices: id region zone ip address port name weight partitions balance meta # 2 1 2 192.168.101.14 6002 1 1.00 262144 200.00 m2 # 0 1 3 192.168.101.15 6002 1 1.00 262144-100.00 m2 # # Swift 1.8+ output example: # /etc/swift/object.builder, build version 1 # 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion # The minimum number of hours before a partition can be reassigned is 1 # Devices: id region zone ip address port replication ip replication port name weight partitions balance meta # 0 1 2 127.0.0.1 6021 127.0.0.1 6021 2 1.00 262144 0.00 # # Swift 2.2.2+ output example: # /etc/swift/object.builder, build version 1 # 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion # The minimum number of hours before a partition can be reassigned is 1 # The overload factor is 0.00% (0.000000) # Devices: id region zone ip address port replication ip replication port name weight partitions balance meta # 0 1 2 127.0.0.1 6021 127.0.0.1 6021 2 1.00 262144 0.00 # Swift 2.9.1+ output example: # /etc/swift/object.builder, build version 1 # 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion # The minimum number of hours before a partition can be reassigned is 1 # The overload factor is 0.00% (0.000000) # Devices: id region zone ip address:port replication ip:replication port name weight partitions balance meta # 0 1 2 127.0.0.1:6021 127.0.0.1:6021 2 1.00 262144 0.00 # Swift 2.9.1+ output example: if row =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+):(\d+)\s+\S+:\d+\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s*((-|\s-?)?\d+\.\d+)\s*(\S*)/ address = address_string("#{$4}") if !policy_index.nil? policy = "#{policy_index}:" else policy = '' end object_hash["#{policy}#{address}:#{$5}/#{$6}"] = { :id => $1, :region => $2, :zone => $3, :weight => $7, :partitions => $8, :balance => $9, :meta => $11, :policy_index => "#{policy_index}" } # Swift 1.8+ output example: elsif row =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+\S+\s+\d+\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s*((-|\s-?)?\d+\.\d+)\s*(\S*)/ address = address_string("#{$4}") if !policy_index.nil? policy = "#{policy_index}:" else policy = '' end object_hash["#{policy}#{address}:#{$5}/#{$6}"] = { :id => $1, :region => $2, :zone => $3, :weight => $7, :partitions => $8, :balance => $9, :meta => $11 } # Swift 1.8.0 output example: elsif row =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s*((-|\s-?)?\d+\.\d+)\s*(\S*)/ address = address_string("#{$4}") object_hash["#{address}:#{$5}/#{$6}"] = { :id => $1, :region => $2, :zone => $3, :weight => $7, :partitions => $8, :balance => $9, :meta => $11 } # This regex is for older swift versions elsif row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/ address = address_string("#{$3}") object_hash["#{address}:#{$4}/#{$5}"] = { :id => $1, :region => 'none', :zone => $2, :weight => $6, :partitions => $7, :balance => $8, :meta => $9 } else Puppet.warning("Unexpected line: #{row}") end end end end object_hash end |
#meta ⇒ Object
248 249 250 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 248 def ring[resource[:name]][:meta] end |
#meta=(meta) ⇒ Object
252 253 254 255 256 257 258 259 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 252 def () swift_ring_builder( builder_file_path(policy_index), 'set_info', "d#{ring[device_path][:id]}", "_#{resource[:meta]}" ) end |
#partitions ⇒ Object
232 233 234 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 232 def partitions ring[resource[:name]][:partitions] end |
#partitions=(part) ⇒ Object
236 237 238 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 236 def partitions=(part) raise(Puppet::Error, "Cannot set partitions, it is set by rebalancing") end |
#policy_index ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 185 def policy_index if resource[:name].split(/^\d+:/)[1].nil? return nil else Integer("#{resource[:name].match(/^\d+/)}") end end |
#region ⇒ Object
201 202 203 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 201 def region ring[resource[:name]][:region] end |
#region=(region) ⇒ Object
205 206 207 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 205 def region=(region) raise(Puppet::Error, "Changing the region of a device is not yet supported.") end |
#weight ⇒ Object
217 218 219 220 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 217 def weight ring[resource[:name]][:weight] # get the weight end |
#weight=(weight) ⇒ Object
222 223 224 225 226 227 228 229 230 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 222 def weight=(weight) swift_ring_builder( builder_file_path(policy_index), 'set_weight', "d#{ring[device_path][:id]}", resource[:weight] ) # requires a rebalance end |
#zone ⇒ Object
209 210 211 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 209 def zone ring[resource[:name]][:zone] end |
#zone=(zone) ⇒ Object
213 214 215 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 213 def zone=(zone) raise(Puppet::Error, "Changing the zone of a device is not yet supported.") end |