Class: Dribbled::DrbdResource

Inherits:
Object
  • Object
show all
Defined in:
lib/dribbled/drbd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res, hostname) ⇒ DrbdResource

Returns a new instance of DrbdResource.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/dribbled/drbd.rb', line 143

def initialize(res,hostname)
  @id = res
  @name = nil
  @config = nil
  @ds = nil
  @cs = nil
  @ro = nil
  @activity = nil
  @percent = nil
  @finish = nil
  @primary = { :hostname => nil, :disk => nil, :device => nil }
  @secondary = { :hostname => nil, :disk => nil, :device => nil }
  @in_kernel = false
  @in_configuration = false
end

Instance Attribute Details

#activityObject

Returns the value of attribute activity.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def activity
  @activity
end

#configObject

Returns the value of attribute config.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def config
  @config
end

#csObject

Returns the value of attribute cs.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def cs
  @cs
end

#dsObject

Returns the value of attribute ds.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def ds
  @ds
end

#finishObject

Returns the value of attribute finish.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def finish
  @finish
end

#idObject (readonly)

Returns the value of attribute id.



140
141
142
# File 'lib/dribbled/drbd.rb', line 140

def id
  @id
end

#in_configurationObject

Returns the value of attribute in_configuration.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def in_configuration
  @in_configuration
end

#in_kernelObject

Returns the value of attribute in_kernel.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def in_kernel
  @in_kernel
end

#nameObject

Returns the value of attribute name.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def name
  @name
end

#percentObject

Returns the value of attribute percent.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def percent
  @percent
end

#primaryObject

Returns the value of attribute primary.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def primary
  @primary
end

#roObject

Returns the value of attribute ro.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def ro
  @ro
end

#secondaryObject

Returns the value of attribute secondary.



141
142
143
# File 'lib/dribbled/drbd.rb', line 141

def secondary
  @secondary
end

Instance Method Details

#checkObject



229
230
231
# File 'lib/dribbled/drbd.rb', line 229

def check

end

#in_configuration?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/dribbled/drbd.rb', line 163

def in_configuration?
  @in_configuration
end

#in_kernel?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/dribbled/drbd.rb', line 159

def in_kernel?
  @in_kernel
end

#inspectObject



225
226
227
# File 'lib/dribbled/drbd.rb', line 225

def inspect
  "#{self.class}: #{@id}[#{@name}]: #{@cs},#{@ds},#{@ro}"
end

#statusObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/dribbled/drbd.rb', line 167

def status
  s = :unknown
  o = 'unable to assert health'

  if self.cs == 'Unconfigured'
    [:ok,"#{self.id}[unconfigured]"]
  else
    if self.in_kernel? and self.in_configuration?
      if self.cs == 'Connected' and self.ds == 'UpToDate/UpToDate' and (self.ro == 'Primary/Secondary' or self.ro == 'Secondary/Primary')
        s = :ok
      else
        if ['SyncSource','SyncTarget','VerifyS','VerifyT','PausedSyncS','PausedSyncT','StandAlone'].include? self.cs
          s = :warning
        elsif not self.in_configuration?
          s = :warning
        else
          s = :critical
        end
      end
    else
      s = :unknown
    end
  end

  [s,self.to_s(:concise)]
end

#to_s(mode = :line) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/dribbled/drbd.rb', line 194

def to_s(mode=:line)
  ph = @primary[:hostname].gsub(/\.[a-z0-9-]+\.[a-z0-9-]+$/,'') unless @primary[:hostname].nil?
  sh = @secondary[:hostname].gsub(/\.[a-z0-9-]+\.[a-z0-9-]+$/,'') unless @secondary[:hostname].nil?

  if @ro == 'Primary/Secondary'
    h1 = ph; dev1 = @primary[:device]
    h2 = sh; dev2 = @secondary[:device]
  else
    h1 = sh; dev1 = @secondary[:device]
    h2 = ph; dev2 = @primary[:device]
  end

  percent_finish = @activity.nil? ? nil : '[%3d%% %8s]' % [@percent,@finish]

  case mode
    when :line
      fmt_string = '%2d %6s %-13s %15s %-22s %-20s %10s %-11s %10s %-11s'
      percent_finish = @activity.nil? ? nil : '[%3d%% %8s]' % [@percent,@finish]
    when :concise
      fmt_string = '%s>%s:%s%s:%s:%s'
      percent_finish = @activity.nil? ? nil : '[%d%%,%s]' % [@percent,@finish]
    when :verbose
      fmt_string = '%s'
    else
      fmt_string = '%s'
  end

  fmt_string % [@id,@name,@cs,percent_finish,@ro,@ds,h1,dev1,h2,dev2]

end