corosync 0.0.1

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.
@@ -0,0 +1,105 @@
1
+ module Corosync
2
+ class Cluster
3
+ COMMAND = "crm"
4
+
5
+ def initialize
6
+ parse
7
+ end
8
+
9
+ def healthy
10
+ if @online.size < @nodes_configured
11
+ false
12
+ elsif @resources_started.size < @resources_configured
13
+ false
14
+ elsif @failed_actions.size != 0
15
+ false
16
+ else
17
+ true
18
+ end
19
+ end
20
+
21
+ def health_description
22
+ description = ""
23
+ ok = healthy
24
+
25
+ if ok
26
+ description += "OK"
27
+ else
28
+ description += "ERROR"
29
+ end
30
+ description += ", #{@nodes_configured} nodes configured"
31
+ if @online.size != 0
32
+ description += ", #{@online.size} nodes online #{@online.inspect}"
33
+ end
34
+ if !ok && @offline.size != 0
35
+ description += ", #{@offline.size} nodes offline #{@offline.inspect}"
36
+ end
37
+ description += ", #{@resources_configured} resources configured"
38
+ if @resources_started.size != 0
39
+ description += ", #{@resources_started.size} resources started #{@resources_started.inspect}"
40
+ end
41
+ if !ok && @resources_stopped.size != 0
42
+ description += ", #{@resources_stopped.size} resources stopped #{@resources_stopped.inspect}"
43
+ end
44
+ if !ok && @failed_actions.size != 0
45
+ description += ", Failed actions #{@failed_actions.inspect}"
46
+ end
47
+ description.gsub("\"", "")
48
+ end
49
+
50
+ private
51
+
52
+ def parse
53
+ # get status info
54
+ cmd = COMMAND + " status"
55
+ output = `#{cmd}`
56
+
57
+ # parse output
58
+ @nodes_configured = []
59
+ if /(\d+) Nodes configured/.match(output)
60
+ @nodes_configured = Regexp.last_match[1].to_i
61
+ else
62
+ raise "Can't parse output"
63
+ end
64
+
65
+ @resources_configured = []
66
+ if /(\d+) Resources configured/.match(output)
67
+ @resources_configured = Regexp.last_match[1].to_i
68
+ else
69
+ raise "Can't parse output"
70
+ end
71
+
72
+ @online = []
73
+ if /Online: \[ ([\w ]*) \]/.match(output)
74
+ @online = Regexp.last_match[1].split(' ')
75
+ end
76
+
77
+ @offline = []
78
+ if /OFFLINE: \[ ([\w ]*) \]/.match(output)
79
+ @offline = Regexp.last_match[1].split(' ')
80
+ end
81
+
82
+ raise "Can't parse output" if @online.empty? && @offline.empty?
83
+
84
+ @resources_started = []
85
+ @resources_stopped = []
86
+ resources = output.scan(/^\s*(\w+)\s*\([\w:]+\):\s*([\w ]*)$/)
87
+ resources.each do |res|
88
+ status = res[1].split(' ')
89
+ if status.include? 'Started'
90
+ @resources_started << res[0]
91
+ else
92
+ @resources_stopped << res[0]
93
+ end
94
+ end
95
+
96
+ raise "Can't parse output" if @resources_started.empty? && @resources_stopped.empty?
97
+
98
+ @failed_actions = []
99
+ if (/Failed actions:.*/m).match(output)
100
+ failed = Regexp.last_match[0].scan(/^\s+.*$/)
101
+ @failed_actions = failed.map { |e| e.lstrip }
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,34 @@
1
+ module Corosync
2
+ class Resource
3
+ COMMAND = "crm resource"
4
+
5
+ attr_reader :status, :started_on, :started_locally
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ parse
10
+ end
11
+
12
+ private
13
+
14
+ def parse
15
+ # get status info
16
+ cmd = COMMAND + " status #{@name}"
17
+ output = `#{cmd}`
18
+
19
+ # parse it
20
+ if output.include? "NOT running"
21
+ @status = "stopped"
22
+ elsif /is running on: (\w*)/.match(output)
23
+ @status = "started"
24
+ @started_on = Regexp.last_match[1]
25
+
26
+ # get hostname of the current machine
27
+ current_hostname = `hostname`.gsub!("\n", "")
28
+ @started_locally = @started_on == current_hostname
29
+ else
30
+ raise "Can't parse output"
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/corosync.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'corosync/resource'
2
+ require 'corosync/cluster'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: corosync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pavel Ivanov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: ivpavig@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/corosync.rb
21
+ - lib/corosync/resource.rb
22
+ - lib/corosync/cluster.rb
23
+ homepage:
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.11
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: A simple wrapper for corosync cmd tool 'crm'
47
+ test_files: []