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
- #balance ⇒ Object
- #balance=(balance) ⇒ Object
- #builder_file_path ⇒ Object
- #create ⇒ Object
- #exists? ⇒ Boolean
- #id ⇒ Object
- #id=(id) ⇒ Object
- #meta ⇒ Object
- #meta=(meta) ⇒ Object
- #partitions ⇒ Object
- #partitions=(part) ⇒ Object
- #region ⇒ Object
- #region=(region) ⇒ Object
- #ring ⇒ Object
- #weight ⇒ Object
- #weight=(weight) ⇒ Object
- #zone ⇒ Object
-
#zone=(zone) ⇒ Object
TODO - is updating the zone supported?.
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 |
.lookup_ring ⇒ Object
12 13 14 15 16 17 18 19 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 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 12 def self.lookup_ring object_hash = {} if File.exists?(builder_file_path) if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1] rows.each do |row| # Swift 1.7+ output example: # 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: # 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: # 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 1.8+ output example: if 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*)/ object_hash["#{$4}:#{$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*)/ object_hash["#{$4}:#{$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*)$/ object_hash["#{$3}:#{$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 |
Instance Method Details
#balance ⇒ Object
163 164 165 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 163 def balance ring[resource[:name]][:balance] end |
#balance=(balance) ⇒ Object
167 168 169 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 167 def balance=(balance) raise(Puppet::Error, "Cannot set balance, it is set by rebalancing") end |
#builder_file_path ⇒ Object
81 82 83 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 81 def builder_file_path self.class.builder_file_path end |
#create ⇒ Object
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 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 89 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, 'add', "z#{resource[:zone]}-#{resource[:name]}", resource[:weight] ) else # Swift 1.8+ # Region defaults to 1 if unspecified resource[:region] ||= 1 swift_ring_builder( builder_file_path, 'add', "r#{resource[:region]}z#{resource[:zone]}-#{resource[:name]}", resource[:weight] ) end end |
#exists? ⇒ Boolean
85 86 87 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 85 def exists? ring[resource[:name]] end |
#id ⇒ Object
115 116 117 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 115 def id ring[resource[:name]][:id] end |
#id=(id) ⇒ Object
119 120 121 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 119 def id=(id) raise(Puppet::Error, "Cannot assign id, it is immutable") end |
#meta ⇒ Object
171 172 173 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 171 def ring[resource[:name]][:meta] end |
#meta=(meta) ⇒ Object
175 176 177 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 175 def () raise(Puppet::Error, "Cannot set meta, I am not sure if it makes sense or what it is for") end |
#partitions ⇒ Object
155 156 157 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 155 def partitions ring[resource[:name]][:partitions] end |
#partitions=(part) ⇒ Object
159 160 161 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 159 def partitions=(part) raise(Puppet::Error, "Cannot set partitions, it is set by rebalancing") end |
#region ⇒ Object
123 124 125 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 123 def region ring[resource[:name]][:region] end |
#region=(region) ⇒ Object
127 128 129 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 127 def region=(region) raise(Puppet::Error, "Changing the region of a device is not possible.") end |
#ring ⇒ Object
77 78 79 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 77 def ring self.class.ring end |
#weight ⇒ Object
140 141 142 143 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 140 def weight ring[resource[:name]][:weight] # get the weight end |
#weight=(weight) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 145 def weight=(weight) swift_ring_builder( builder_file_path, 'set_weight', "d#{ring[resource[:name]][:id]}", resource[:weight] ) # requires a rebalance end |
#zone ⇒ Object
131 132 133 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 131 def zone ring[resource[:name]][:zone] end |
#zone=(zone) ⇒ Object
TODO - is updating the zone supported?
136 137 138 |
# File 'lib/puppet/provider/swift_ring_builder.rb', line 136 def zone=(zone) Puppet.warning('Setting zone is not yet supported, I am not even sure if it is supported') end |