drbd 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +45 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/drbd.rb +107 -0
- data/spec/drbd_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +109 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Adam Kliment
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= DRBD
|
2
|
+
|
3
|
+
Ruby wrapper for DRBD
|
4
|
+
|
5
|
+
== It is usefull for
|
6
|
+
|
7
|
+
* Connect to server over SSH
|
8
|
+
* Parse current running configuration
|
9
|
+
* Parse current status
|
10
|
+
|
11
|
+
== Limitations
|
12
|
+
|
13
|
+
* Just one-morning prototype
|
14
|
+
* Best with drbd version > 8.3.7
|
15
|
+
* No tests
|
16
|
+
* No documentation
|
17
|
+
* Absolutely no warranty, use it at your own risk
|
18
|
+
|
19
|
+
|
20
|
+
== How it works
|
21
|
+
|
22
|
+
d = Drbd.new("fqdn.domain.tld")
|
23
|
+
|
24
|
+
r = d.resources.first
|
25
|
+
|
26
|
+
r.name
|
27
|
+
|
28
|
+
r.hosts.map{|h| h.address }
|
29
|
+
|
30
|
+
r.status
|
31
|
+
|
32
|
+
r = d.find_resource_by_name("r0")
|
33
|
+
|
34
|
+
r.consinstent?
|
35
|
+
|
36
|
+
r = d.find_resource_by_disk("/dev/volgroup-logvolume--name")
|
37
|
+
|
38
|
+
r.resync_running?
|
39
|
+
|
40
|
+
r.status[:resynced_percent]
|
41
|
+
|
42
|
+
|
43
|
+
== Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2011 Adam Kliment. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "drbd"
|
8
|
+
gem.summary = "Ruby wrapper for DRBD"
|
9
|
+
gem.description = "Ruby wrapper for DRBD - RAID 1 over TCP/IP"
|
10
|
+
gem.email = "adam.kliment@virtualmaster.cz"
|
11
|
+
gem.homepage = "http://github.com/n1k/drbd"
|
12
|
+
gem.authors = ["Adam Kliment"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "nokogiri", ">= 1.4.4"
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "drbd #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/drbd.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
class DRBD
|
4
|
+
attr_reader :resources
|
5
|
+
|
6
|
+
def initialize host
|
7
|
+
@host = host
|
8
|
+
load!
|
9
|
+
end
|
10
|
+
|
11
|
+
def load!
|
12
|
+
load_resources!
|
13
|
+
load_status!
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_resources!
|
17
|
+
@resources = Config.new(IO.popen("ssh #{@host} \"sudo /sbin/drbdadm dump-xml\"")).resources
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_status!
|
21
|
+
raw_xml = IO.popen("ssh #{@host} \"sudo /sbin/drbdadm status\"")
|
22
|
+
statuses = Status.new(raw_xml).resources
|
23
|
+
set_resources_status statuses
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_resources_status statuses
|
27
|
+
statuses.each do |status|
|
28
|
+
resource = find_resource_by_name(status[:name])
|
29
|
+
resource.status = status
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_resource_by_name given_name
|
34
|
+
@resources.select{|r| r.name == given_name}.first
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_resource_by_disk disk_name
|
38
|
+
@resources.select{|r| r.hosts.inject(false){|sum,h| (h.disk == disk_name && sum == false) ? true : sum}}.first
|
39
|
+
end
|
40
|
+
|
41
|
+
class Config
|
42
|
+
attr_reader :xml
|
43
|
+
|
44
|
+
def initialize xml
|
45
|
+
@xml = Nokogiri::XML(xml)
|
46
|
+
end
|
47
|
+
|
48
|
+
def resources
|
49
|
+
@xml.xpath("//config/resource").map{|r| Resource.new r }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Host
|
54
|
+
attr_reader :name, :device, :disk, :address, :meta_disk
|
55
|
+
def initialize host
|
56
|
+
@name = host['name']
|
57
|
+
@device = host.xpath(".//device").text
|
58
|
+
@disk = host.xpath(".//disk").text
|
59
|
+
@address = host.xpath(".//address").text
|
60
|
+
@meta_disk = host.xpath(".//meta-disk").text
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Resource
|
65
|
+
attr_reader :name, :device, :disk, :address, :meta_disk, :hosts
|
66
|
+
attr_accessor :status
|
67
|
+
def initialize nokogiri_resource
|
68
|
+
xml = nokogiri_resource
|
69
|
+
@name = xml['name']
|
70
|
+
@protocol = xml['protocol']
|
71
|
+
@hosts = xml.xpath(".//host").to_a.map do |host_xml|
|
72
|
+
Host.new host_xml
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def resync_running?
|
77
|
+
not status[:resynced_percent] == nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def consistent?
|
81
|
+
status[:ds1] == "UpToDate" && status[:ds2] == "UpToDate" && status[:resynced_percent] == nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Status
|
86
|
+
attr_reader :resources
|
87
|
+
def initialize raw
|
88
|
+
xml = Nokogiri::XML(raw)
|
89
|
+
resources = xml.xpath("//drbd-status/resources/resource")
|
90
|
+
@resources = resources.map do |resource|
|
91
|
+
r = {}
|
92
|
+
r[:name] = resource["name"]
|
93
|
+
r[:minor] = resource["minor"]
|
94
|
+
r[:cs] = resource["cs"]
|
95
|
+
r[:ro1] = resource["ro1"]
|
96
|
+
r[:ro2] = resource["ro2"]
|
97
|
+
r[:ds1] = resource["ds1"]
|
98
|
+
r[:ds2] = resource["ds2"]
|
99
|
+
r[:resynced_percent] = resource["resynced_percent"]
|
100
|
+
r
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
data/spec/drbd_spec.rb
ADDED
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: drbd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Adam Kliment
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-17 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: nokogiri
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 4
|
50
|
+
version: 1.4.4
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Ruby wrapper for DRBD - RAID 1 over TCP/IP
|
54
|
+
email: adam.kliment@virtualmaster.cz
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files:
|
60
|
+
- LICENSE
|
61
|
+
- README.rdoc
|
62
|
+
files:
|
63
|
+
- .document
|
64
|
+
- .gitignore
|
65
|
+
- LICENSE
|
66
|
+
- README.rdoc
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- lib/drbd.rb
|
70
|
+
- spec/drbd_spec.rb
|
71
|
+
- spec/spec.opts
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/n1k/drbd
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --charset=UTF-8
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.3.7
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Ruby wrapper for DRBD
|
107
|
+
test_files:
|
108
|
+
- spec/drbd_spec.rb
|
109
|
+
- spec/spec_helper.rb
|