DRBD

Ruby wrapper for DRBD

It is usefull for

  • Connect to the server over SSH

  • Parse current running configuration

  • Parse current status

  • Execute essential commands

Limitations

  • Best with DRBD version > 8.3.7

  • Hostname used for connection must be one of the hostnames in drbd.conf (FQDN ideally)

  • It's just one-morning's prototype, take patience

  • Under development, everything may change

  • No tests

  • No documentation

  • Absolutely no warranty, use it at your own risk. Be carefull, you may lost some data!

Installation

gem install drbd

How it works

  • you can connect to remote node with hostname, login will be executed with current user and his key

    d = Drbd.new("fqdn.domain.tld")

    or you can “recycle” existing Net::SSH session to improve performance:

    ssh = Net:SSH.start("fwdn.domain.tld", "root", :password => 'secret')

    d = Drbd.new(ssh)

    specify command to be executed:

    d = Drbd.new("fqdn.domain.tld", :command => 'sudo /sbin/drbdadm')

  • obtain array of configured configured resources

    r = d.resources.first

  • stateless execute command (WARNING! let's check the source what it does)

    r.primary!

    r.primary!(:force => true)

    r.secondary!

    r.connect!

    r.attach!

    r.detach!

    r.up!

    r.down!

  • analyze actual state

    r.resync_running?

    r.consistent?

    r.connected?

    r.down?

    r.primary?

    r.secondary?

  • get resource name

    r.name

  • get resource protocol

    r.protocol

  • get hosts for resource

    r.hosts

  • get node addresses

    r.hosts.map{|h| h.address }

  • get status for resource

    r.status

    resource status is hash with keys:

    :cs, :resynced_percent, :minor, :ro1, :ds1, :ro2, :ds2, :name

    r.status

  • find resource by name

    r = d.find_resource_by_name("r0")

  • find resource by backing disk

    r = d.find_resource_by_disk("/dev/volgroup-logvolume--name")

  • true if both of devices are UpToDate

    r.consinstent?

  • true if resynced_percent is present in status

    r.resync_running?

  • true if resource status is “Connected”

    r.up?

  • true if resource status is “Unconfigured”

    r.down?

  • stateless perform drbdadm up on resource (use at your own risk!)

    r.up!

  • stateless perform drbdadm down on resource (use at your own risk!)

    r.down!

  • stateless perform forced drbdadm create-md on resource (use at your own risk!)

    if resource is not down, returns false and does nothing

    r.init_metadata

  • back-reference to the DRBD object

    r.drbd

  • uptate status of all resources

    r.drbd.load_status!

    d.load_status!

TODO

  • Add states to actions (analyze exit status)

  • Test suite

Copyright © 2011 Adam Kliment, Virtualmaster.cz. See LICENSE for details.