DRBD

Ruby wrapper for DRBD

It is usefull for

  • Connect to server over SSH

  • Parse current running configuration

  • Parse current status

Limitations

  • Best with drbd version > 8.3.7

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

  • It’sJust one-morning’s prototype, take patience

  • No tests

  • No documentation

  • Absolutely no warranty, use it at your own risk

Installation

gem install drbd

How it works

  • simply fetch data from remote host

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

    you can 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

  • get resource name

    r.name

  • get resource protocol

    r.protocol

  • get hosts for resource

    r.hosts

  • get status for resource

    r.status

  • get node addresses

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

  • get 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

  • Replace IO.popen(“ssh …”) with native ruby net/ssh

  • Add states to actions (analyze exit status)

  • Test suite

Copyright © 2011 Adam Kliment. See LICENSE for details.