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.



69
70
71
72
73
74
75
76
77
# File 'lib/drbd.rb', line 69

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.



61
62
63
# File 'lib/drbd.rb', line 61

def drbd
  @drbd
end

#hostsObject (readonly)

Returns the value of attribute hosts.



61
62
63
# File 'lib/drbd.rb', line 61

def hosts
  @hosts
end

#nameObject (readonly)

Returns the value of attribute name.



61
62
63
# File 'lib/drbd.rb', line 61

def name
  @name
end

#protocolObject (readonly)

Returns the value of attribute protocol.



61
62
63
# File 'lib/drbd.rb', line 61

def protocol
  @protocol
end

#statusObject

Returns the value of attribute status.



62
63
64
# File 'lib/drbd.rb', line 62

def status
  @status
end

Class Method Details

.load_config(raw, drbd) ⇒ Object



64
65
66
67
# File 'lib/drbd.rb', line 64

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

Instance Method Details

#consistent?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/drbd.rb', line 83

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

#down!Object



103
104
105
106
107
108
109
# File 'lib/drbd.rb', line 103

def down!
  args = "down #{self.name}"
  command = "ssh #{drbd.host} \"#{drbd.command} #{args}\""
  system(command)
  drbd.load_status!
  nil
end

#down?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/drbd.rb', line 91

def down?
  status[:cs] == "Unconfigured"
end

#init_metadata!Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/drbd.rb', line 111

def init_metadata!
  if self.down?
    #drbdmeta 0 v08 /dev/mapper/dikobraz-www--emailmaster--cz_root_meta 0 create-md 
    command = "ssh #{drbd.host} \"sudo /sbin/drbdmeta --force #{local_minor} v08 #{local_host.meta_disk} 0 create-md\""
    system(command)
    return true
  else
    return false
  end
end

#local_hostObject



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

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

#local_minorObject



127
128
129
130
# File 'lib/drbd.rb', line 127

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

#resync_running?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/drbd.rb', line 79

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

#stateObject



132
133
134
# File 'lib/drbd.rb', line 132

def state
  status[:cs]
end

#up!Object



95
96
97
98
99
100
101
# File 'lib/drbd.rb', line 95

def up!
  args = "up #{self.name}"
  command = "ssh #{drbd.host} \"#{drbd.command} #{args}\""
  system(command)
  drbd.load_status!
  nil
end

#up?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/drbd.rb', line 87

def up?
  status[:cs] == "Connected" || status[:cs] == "SyncTarget"
end