Class: DRBD::Resource

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nokogiri_resource, drbd) ⇒ Resource

Returns a new instance of Resource.



129
130
131
132
133
134
135
136
137
# File 'lib/drbd.rb', line 129

def initialize nokogiri_resource, drbd
  xml = nokogiri_resource
  @drbd = drbd
  @name = xml['name']
  @protocol = xml['protocol']
  @hosts = xml.xpath(".//host").to_a.map do |host_xml|
    Host.new host_xml
  end
end

Instance Attribute Details

#drbdObject (readonly)

Returns the value of attribute drbd.



121
122
123
# File 'lib/drbd.rb', line 121

def drbd
  @drbd
end

#hostsObject (readonly)

Returns the value of attribute hosts.



121
122
123
# File 'lib/drbd.rb', line 121

def hosts
  @hosts
end

#nameObject (readonly)

Returns the value of attribute name.



121
122
123
# File 'lib/drbd.rb', line 121

def name
  @name
end

#protocolObject (readonly)

Returns the value of attribute protocol.



121
122
123
# File 'lib/drbd.rb', line 121

def protocol
  @protocol
end

#statusObject

Returns the value of attribute status.



122
123
124
# File 'lib/drbd.rb', line 122

def status
  @status
end

Class Method Details

.load_config(raw, drbd) ⇒ Object



124
125
126
127
# File 'lib/drbd.rb', line 124

def self.load_config raw, drbd
  xml = Nokogiri::XML(raw)    
  xml.xpath("//config/resource").map{|r| Resource.new r, drbd }
end

Instance Method Details

#attach!Object



224
225
226
227
228
229
230
# File 'lib/drbd.rb', line 224

def attach!
  args = "attach #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#connect!Object



201
202
203
204
205
206
207
# File 'lib/drbd.rb', line 201

def connect!
  args = "connect #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#connected?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/drbd.rb', line 147

def connected?
  status[:cs] == "Connected" 
end

#consistent?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/drbd.rb', line 143

def consistent?
  status[:ds1] == "UpToDate" && status[:ds2] == "UpToDate" && status[:resynced_percent] == nil
end

#detach!Object



232
233
234
235
236
237
238
# File 'lib/drbd.rb', line 232

def detach!
  args = "detach #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#disconnect!Object



209
210
211
212
213
214
215
# File 'lib/drbd.rb', line 209

def disconnect!
  args = "disconnect #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#down!Object



248
249
250
251
252
253
254
# File 'lib/drbd.rb', line 248

def down!
  args = "down #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#down?Boolean

Returns:

  • (Boolean)


151
152
153
154
155
# File 'lib/drbd.rb', line 151

def down?
  return true if status.nil?                                                                                              
  return true if status[:cs] == "Unconfigured"                                                                            
  return false
end

#init_metadata!Object



256
257
258
259
260
261
262
263
264
265
# File 'lib/drbd.rb', line 256

def init_metadata!
  if self.down?
    args = "-- --force create-md #{self.name}"
    command = "#{drbd.command} #{args}"
    self.drbd.ssh_exec(command)
    return true
  else
    return false
  end
end

#local_diskObject



272
273
274
275
# File 'lib/drbd.rb', line 272

def local_disk
  return nil if local_host == nil
  local_host.disk
end

#local_hostObject



268
269
270
# File 'lib/drbd.rb', line 268

def local_host
  hosts.select{|h| h.name == drbd.host}.first
end

#local_minorObject



277
278
279
280
# File 'lib/drbd.rb', line 277

def local_minor
  return nil if local_host == nil
  local_host.minor
end

#primary!(opts = {}) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/drbd.rb', line 165

def primary!(opts = {})

  if opts[:force] == true
    args = "-- --overwrite-data-of-peer primary #{self.name}"
  else
    args = "primary #{self.name}"
  end

  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#primary?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/drbd.rb', line 157

def primary?
  status[:ro1] == "Primary"
end

#resize!Object



217
218
219
220
221
222
# File 'lib/drbd.rb', line 217

def resize!
  args = "-- --assume-peer-has-space resize #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
end

#resync_running?Boolean

Returns:

  • (Boolean)


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

def resync_running?
  not status[:resynced_percent] == nil
end

#roleObject



197
198
199
# File 'lib/drbd.rb', line 197

def role
  status[:ro1]
end

#secondary!Object



180
181
182
183
184
185
186
# File 'lib/drbd.rb', line 180

def secondary!
  args = "-- --overwrite-data-of-peer secondary #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#secondary?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/drbd.rb', line 161

def secondary?
  stutus[:ro1] == "Secondary"
end

#stateObject



282
283
284
# File 'lib/drbd.rb', line 282

def state
  status[:cs]
end

#syncer!Object



188
189
190
191
192
193
194
195
# File 'lib/drbd.rb', line 188

def syncer!
  args = "syncer #{self.name}"

  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end

#up!Object



240
241
242
243
244
245
246
# File 'lib/drbd.rb', line 240

def up!
  args = "up #{self.name}"
  command = "#{drbd.command} #{args}"
  self.drbd.ssh_exec(command)
  drbd.load_status!
  nil
end