tiebreaker 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,265 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require "ntap"
4
+ require 'net/ping'
5
+ require "common"
6
+ require 'logger'
7
+
8
+
9
+ class WORKER
10
+
11
+
12
+ def initialize(config)
13
+ @config = config
14
+
15
+ @logger = Logger.new(File.join(File.dirname(__FILE__),"../logs/#{@config['config_name']}.log"), 'weekly')
16
+ @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
17
+ @logger.info "Started"
18
+
19
+ @allvars = ALLVARS.new
20
+ @mtex = @allvars.mutex
21
+
22
+ @checkofseparation = {}
23
+ #@logger.info @allvars.isseparated
24
+ @primary_vsm_properties = {"luns"=>[]}
25
+ @secondary_vsm_properties = {"management_lifs"=>[],"data_lifs"=>[]}
26
+
27
+ fillup_svm_details(true)
28
+
29
+ @vsms_properties = {"primary_vsm_properties"=>@primary_vsm_properties, "secondary_vsm_properties"=>@secondary_vsm_properties}
30
+ #puts @vsms_properties.inspect
31
+ lun_scan_cycle = 0
32
+ while true & (not @allvars.isseparated)
33
+ @logger.info "In while"
34
+ @checkofseparation = checkifseparated
35
+ if @checkofseparation["primary_is_alive"] | @checkofseparation["secondary_is_alive"] then # ha nem separated
36
+ if not @checkofseparation["primary_is_alive"] then # ha a primary nem erheto el a 3. site-rol, akkor megnezi, hogy a secondary-rol elerheto e a primary
37
+ @logger.warn "#{@config['config_name']}: Primary site is not alive from 3. site check wheter netapp on secondary site is able to reach"
38
+ netappinst = NETAPP.new(@config, @logger,@vsms_properties)
39
+ if not netappinst.ping_primary_from_secondary then
40
+ @logger.error "#{@config['config_name']}: Failover started..."
41
+ if netappinst.failover then
42
+ @logger.info "#{@config_name}: Failover has been succeeded"
43
+ exit
44
+ else
45
+ @logger.fatal "#{@config_name}: Failover has not been succeeded"
46
+ exit
47
+ end
48
+
49
+ end # do site failover
50
+ end
51
+ end # if ( @checkofseparation["primary_is_alive"] | @checkofseparation["secondary_is_alive"] )
52
+
53
+ lun_scan_cycle+=1
54
+
55
+ if lun_scan_cycle==5 then
56
+ fillup_svm_details(false)
57
+ lun_scan_cycle = 0
58
+ end
59
+
60
+ sleep 2
61
+ end # while true & (not @allvars.isseparated
62
+ end
63
+
64
+ def checkifseparated
65
+ # egyik ip sem ok. felteszem
66
+ primary_is_alive = false
67
+ secondary_is_alive = false
68
+
69
+ # a primary ipk netan elerhetok
70
+ @config["ips_to_check_on_primary"].each do |ip_to_check_on_primary|
71
+ if not primary_is_alive then
72
+ # primary_is_alive = Net::Ping::External.new(ip_to_check_on_primary).ping?
73
+ primary_is_alive = do_ping(ip_to_check_on_primary,1)
74
+ if primary_is_alive then
75
+ @logger.info "#{@config['config_name']}: The IP on primary site: #{ip_to_check_on_primary} is alive from 3. site"
76
+ else
77
+ @logger.warn "#{@config['config_name']}: The IP on primary site: #{ip_to_check_on_primary} is not alive from 3. site"
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+ @config["ips_to_check_on_secondary"].each do |ip_to_check_on_secondary|
84
+ if not secondary_is_alive then
85
+ #secondary_is_alive = Net::Ping::External.new(ip_to_check_on_secondary).ping?
86
+ secondary_is_alive = do_ping(ip_to_check_on_secondary,1)
87
+ if secondary_is_alive then
88
+ @logger.info "#{@config['config_name']}: The IP on secondary site: #{ip_to_check_on_secondary} is alive = #{secondary_is_alive} from 3. site"
89
+ else
90
+ @logger.warn "#{@config['config_name']}: The IP on secondary site: #{ip_to_check_on_secondary} is not alive = #{secondary_is_alive} from 3. site"
91
+ end
92
+
93
+ end
94
+ end
95
+
96
+ sitestate={"primary_is_alive"=>primary_is_alive, "secondary_is_alive"=>secondary_is_alive}
97
+
98
+ if not primary_is_alive then # ha az elsodleges site nem megy, akkor megnezi, hogy a masodlagos megy e
99
+ if not secondary_is_alive then # ha a masodlagos sem megy, akkor beallitja a setseparated-et true-ra
100
+ @mtex.synchronize do
101
+ if ! @allvars.isseparated then
102
+ @logger.fatal "#{@config['config_name']}: Setting separated!!!!"
103
+ @allvars.setseparated(true)
104
+ end
105
+ end
106
+ else
107
+ # dummy
108
+ end
109
+ end
110
+ @logger.info "#{@config['config_name']}: The state of sites: #{sitestate}"
111
+ return sitestate # azert van return, hogy 1 forduloban lehessen is ellenorizni
112
+ end
113
+
114
+
115
+ def do_ping(hostname,ping_count)
116
+ pcount=0
117
+ ping = Net::Ping::External.new(host = hostname, timeout = 10, count=10)
118
+ while !ping.ping? && pcount < ping_count
119
+ pcount+=1
120
+ end
121
+ return ping.ping?
122
+ end # do_ping
123
+
124
+
125
+ def svm_get_management_lifs(primary_or_secondary)
126
+ netappinst = NETAPP.new(@config, @logger,{})
127
+ return netappinst.get_management_interfaces(primary_or_secondary)
128
+ end # first_check_health
129
+
130
+ def svm_get_data_lifs(primary_or_secondary,protocol)
131
+ netappinst = NETAPP.new(@config, @logger,{})
132
+ return netappinst.get_data_interfaces(primary_or_secondary,protocol)
133
+ end # first_check_health
134
+
135
+ def svm_get_luns_primary
136
+ netappinst = NETAPP.new(@config, @logger,{})
137
+ return netappinst.get_primary_luns
138
+ end # first_check_health
139
+
140
+ def check_connection_to_netapp(destination,caller)
141
+ netappinst = NETAPP.new(@config, @logger,{})
142
+ return netappinst.test_connection(destination, caller)
143
+ end # first_check_health
144
+
145
+
146
+ def fillup_svm_details(isfirst)
147
+ if isfirst then
148
+
149
+ ###################
150
+ # query manaement interfaces, trouble if no results
151
+
152
+ =begin for future use
153
+ primary_svm_management_lifs = svm_get_management_lifs("primary")
154
+ puts primary_svm_management_lifs.inspect
155
+ if ! (primary_svm_management_lifs.class.name.eql?("NilClass") ) then
156
+ if primary_svm_management_lifs.count > 0 then
157
+ anymanagementinterfaceisup = false
158
+ primary_svm_management_lifs.each { |vsm_management_interface|
159
+ anymanagementinterfaceisup = true if vsm_management_interface["operational-status"].eql?("up")
160
+ }
161
+ if ! anymanagementinterfaceisup then
162
+ @logger.fatal "#{@config_name}: No management interfaces have operational-status UP"
163
+ exit
164
+ end #! anymanagementinterfaceisup then
165
+ else
166
+ @logger.fatal "#{@config_name}: No management interfaces definied on primary SVM"
167
+ exit
168
+ end #if primary_svm_management_lifs.count == 0 then
169
+ else #! (primary_svm_management_lifs.class.name.eql?("NilClass") ) then
170
+ @logger.fatal "#{@config_name}: Unable to retrieve management interfaces from primary SVM"
171
+ exit
172
+ end
173
+ =end # for future use
174
+ secondary_svm_management_lifs = svm_get_management_lifs("secondary")
175
+ if ! (secondary_svm_management_lifs.class.name.eql?("NilClass") ) then
176
+ if secondary_svm_management_lifs.count > 0 then
177
+ any_management_interfaces_are_admin_up = false
178
+ secondary_svm_management_lifs.each { |vsm_management_interface|
179
+ any_management_interfaces_are_admin_up= true if vsm_management_interface["administrative-status"].eql?("up")
180
+ }
181
+ if ! any_management_interfaces_are_admin_up then
182
+ @logger.fatal "#{@config_name}: No management interfaces have administrative-status UP on secondary"
183
+ exit
184
+ end #! any_management_interfaces_are_admin_up then
185
+ else
186
+ @logger.fatal "#{@config_name}: No management interfaces definied on secondary SVM"
187
+ exit
188
+ end
189
+ else
190
+ @logger.fatal "#{@config_name}: Unable to retrieve management interfaces of secondary SVM"
191
+ end
192
+ @secondary_vsm_properties["management_lifs"] = secondary_svm_management_lifs
193
+ # / query management interfaces, trouble if no results
194
+
195
+ # query data interfaces, no trouble if no results
196
+
197
+ =begin # for future use
198
+ primary_svm_data_lifs = []
199
+ data_protocols = ["nfs","cifs","iscsi","fcp","fcache"]
200
+ data_protocols.each{ |protocol|
201
+ primary_svm_data_lifs.concat(svm_get_data_lifs("primary",protocol))
202
+ }
203
+ =end # for future use
204
+
205
+ secondary_svm_data_lifs = []
206
+ data_protocols = ["nfs","cifs","iscsi","fcp","fcache"]
207
+ data_protocols.each{ |protocol|
208
+ secondary_svm_data_lifs.concat(svm_get_data_lifs("secondary",protocol))
209
+ }
210
+ @secondary_vsm_properties["data_lifs"] = secondary_svm_data_lifs
211
+
212
+ #get luns from primary
213
+ @primary_vsm_properties["luns"] = svm_get_luns_primary
214
+
215
+ else # if isfirst then
216
+
217
+ # @primary_vsm_properties["luns"] = svm_get_luns_primary if check_connection_to_netapp("primary_cluster", "Refreshing luns on primary SVM")
218
+
219
+ ##### ===== @primary_vsm_properties["luns"] = svm_get_luns_primary if check_connection_to_netapp("primary_cluster", "Refreshing luns on primary SVM")
220
+ if check_connection_to_netapp("primary_cluster", "Refreshing luns of primary SVM") then
221
+ #puts "sleeping for 10 sec: luns"
222
+ #sleep 10
223
+ #puts "end sleeping"
224
+ tmp = svm_get_luns_primary
225
+ if ! tmp.class.name.eql?("NilClass") then
226
+ @primary_vsm_properties["luns"] = tmp
227
+ else #! tmp.class.name.eql?("NilClass") then
228
+
229
+ end # ! tmp.class.name.eql?("NilClass") then
230
+ end
231
+ ##### /===== @primary_vsm_properties["luns"] = svm_get_luns_primary if check_connection_to_netapp("primary_cluster", "Refreshing luns on primary SVM")
232
+
233
+ ## periodical data lif checking
234
+ if check_connection_to_netapp("secondary_cluster", "Refreshing data lifs of secondary SVM") then
235
+ #puts "sleeping for 10 sec: data lifs"
236
+ #sleep 10
237
+ #puts "end sleeping"
238
+
239
+ secondary_svm_data_lifs = []
240
+ data_protocols = ["nfs","cifs","iscsi","fcp","fcache"]
241
+ tmp_error = false
242
+ data_protocols.each{ |protocol|
243
+ if ! tmp_error then
244
+ tmp = svm_get_data_lifs("secondary",protocol)
245
+ if ! tmp.class.name.eql?("NilClass") then
246
+ secondary_svm_data_lifs.concat(tmp)
247
+ else # if ! tmp.class.name.eql?("NilClass") then
248
+ tmp_error = true
249
+ end # if ! tmp.class.name.eql?("NilClass") then
250
+ end # if ! tmp_error then
251
+ }
252
+ @secondary_vsm_properties["data_lifs"] = secondary_svm_data_lifs if ! tmp_error
253
+ end # if check_connection_to_netapp("secondary_cluster", "Refreshing data lifs from secondary SVM") then
254
+ ## data lif checking
255
+
256
+ end
257
+
258
+
259
+
260
+ end # fillup_svm_details(isfirst)
261
+
262
+
263
+
264
+ end # end class
265
+
@@ -0,0 +1,90 @@
1
+ {
2
+ "configs":[
3
+ {
4
+ "config_name":"config0",
5
+ "primary_site_name":"siteA",
6
+ "primary_ip":"X.X.X.X",
7
+ "primary_user":"admin",
8
+ "primary_password":"netapp_cluster_admin_password",
9
+ "secondary_ip":"Y.Y.Y.X",
10
+ "secondary_user":"admin",
11
+ "secondary_password":"netapp_cluster_admin_password",
12
+ "primary_svm":"NAME_OF_PRIMARY_SVM",
13
+ "secondary_svm":"NAME_OF_DR_SVM",
14
+ "primary_svm_user":"vsadmin",
15
+ "primary_svm_password":"netapp_cluster_vsadmin_password",
16
+ "secondary_svm_user":"vsadmin",
17
+ "secondary_svm_password":"netapp_cluster_vsadmin_password",
18
+ "fc_topology_check":true,
19
+ "ips_to_check_on_primary":
20
+ [
21
+ "X.X.X.X",
22
+ "X.X.X.Y",
23
+ "X.X.X.Z"
24
+ ],
25
+ "ips_to_check_on_secondary":
26
+ [
27
+ "Y.Y.Y.X",
28
+ "Y.Y.Y.Y",
29
+ "Y.Y.Y.Z"
30
+ ],
31
+ "ips_to_check_on_primary_from_secondary":
32
+ [
33
+ "X.X.X.X",
34
+ "X.X.X.Y",
35
+ "X.X.X.Z",
36
+ "Z.Z.Z.X",
37
+ "Z.Z.Z.Y",
38
+ "Z.Z.Z.Z"
39
+ ],
40
+ "check_fc_switches_on_primary":
41
+ [
42
+ "FC_SWITCH_NAME_ON_PRIMARY_SITE#1",
43
+ "FC_SWITCH_NAME_ON_PRIMARY_SITE#2"
44
+ ]
45
+ },
46
+ {
47
+ "config_name":"config1",
48
+ "primary_site_name":"siteB",
49
+ "primary_ip":"Y.Y.Y.X",
50
+ "primary_user":"admin",
51
+ "primary_password":"netapp_cluster_admin_password",
52
+ "secondary_ip":"X.X.X.X",
53
+ "secondary_user":"admin",
54
+ "secondary_password":"netapp_cluster_admin_password",
55
+ "primary_svm":"NAME_OF_PRIMARY_SVM",
56
+ "secondary_svm":"NAME_OF_DR_SVM",
57
+ "primary_svm_user":"vsadmin",
58
+ "primary_svm_password":"netapp_cluster_vsadmin_password",
59
+ "secondary_svm_user":"vsadmin",
60
+ "secondary_svm_password":"netapp_cluster_vsadmin_password",
61
+ "fc_topology_check":true,
62
+ "ips_to_check_on_primary":
63
+ [
64
+ "Y.Y.Y.X",
65
+ "Y.Y.Y.Y",
66
+ "Y.Y.Y.Z"
67
+ ],
68
+ "ips_to_check_on_secondary":
69
+ [
70
+ "X.X.X.X",
71
+ "X.X.X.Y",
72
+ "X.X.X.Z"
73
+ ],
74
+ "ips_to_check_on_primary_from_secondary":
75
+ [
76
+ "Y.Y.Y.X",
77
+ "Y.Y.Y.Y",
78
+ "Y.Y.Y.Z",
79
+ "Z.Z.Z.X",
80
+ "Z.Z.Z.Y",
81
+ "Z.Z.Z.Z"
82
+ ],
83
+ "check_fc_switches_on_primary":
84
+ [
85
+ "FC_SWITCH_NAME_ON_PRIMARY_SITE#1",
86
+ "FC_SWITCH_NAME_ON_PRIMARY_SITE#2"
87
+ ]
88
+ }
89
+ ]
90
+ }
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.dirname(__FILE__)
3
+
4
+ require 'daemons'
5
+ options = {
6
+ :dir => '../pids',
7
+ :ontop => true,
8
+ :logfilename => 'clog.log',
9
+ :output_logfilename => 'cout.txt'
10
+ }
11
+
12
+ Daemons.run(File.join(File.dirname(__FILE__), 'classes/main.rb'), options)
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiebreaker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Akos Kuczi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: net-ping
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.7'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.7.8
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.7'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.7.8
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.8'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.8'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.8.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: daemons
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.2'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.3
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.2.3
93
+ description: Tiebreaker for NetApp SVM DR
94
+ email: akos.kuczi@dimensiondata.com
95
+ executables: []
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - "./classes/NaElement.rb"
100
+ - "./classes/NaErrno.rb"
101
+ - "./classes/NaServer.rb"
102
+ - "./classes/common.rb"
103
+ - "./classes/confreader.rb"
104
+ - "./classes/main.rb"
105
+ - "./classes/ntap.rb"
106
+ - "./classes/worker.rb"
107
+ - "./config.json"
108
+ - "./logs/config0.log"
109
+ - "./pids/pid"
110
+ - "./tiebreaker.rb"
111
+ homepage: http://www.dimensiondata.com
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - "./logs"
119
+ - "./pids"
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.8
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: tiebreaker
136
+ test_files: []