nitos_testbed_rc 1.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/omf6 ADDED
@@ -0,0 +1,679 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'time'
4
+ require 'omf_common'
5
+ require 'optparse'
6
+
7
+ @config = YAML.load_file('/etc/nitos_testbed_rc/omf_script_conf.yaml')
8
+ # @config = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), '.../etc/omf_script_conf.yaml'))
9
+ @auth = @config[:auth]
10
+ @xmpp = @config[:xmpp]
11
+ @omf = @config[:omf_script]
12
+
13
+ options = {}
14
+ opt_parser = OptionParser.new do |opts|
15
+ opts.banner = "Usage: omf6 [COMMAND] [OPTIONS]"
16
+ opts.separator ""
17
+ opts.separator "Commands"
18
+ opts.separator " load : load an image to a group of nodes"
19
+ opts.separator " save : reate an image from a node"
20
+ opts.separator " tell : change the status of a group of nodes (status can be on/off/reset)"
21
+ opts.separator " stat : report the status of a group of nodes"
22
+ opts.separator "Options"
23
+
24
+ opts.on('-i', '--image IMAGE_NAME', 'the image name for load command (if nill default image will be loaded)') { |v| options[:image] = v }
25
+ opts.on('-n', '--node NODE', 'node name for save command') { |v| options[:node] = v }
26
+ opts.on('-a', '--status STATUS', 'the status you want to get the node to. Required only on tell command.') { |v| options[:status] = v }
27
+ opts.on('-t', '--target_nodes NODES', 'target nodes you want to run the command too. Required on commands load, tell and stat.') {|v| options[:target_nodes] = v.split(",") }
28
+
29
+ options[:last_action] = @omf[:last_action] #actions are reset and shutdown
30
+ opts.on('-l', '--last_action ACTION', "action you want to perform after the commands is executed. Optional on commands load and save (last_action can be reset/shutdown. Default #{options[:last_action]})."){|v| options[:last_action] = v}
31
+ options[:wait] = false
32
+ opts.on('-w', '--wait', 'wait until pingable. Used in tell command (default vallue is off)'){|v| options[:wait] = true}
33
+ end
34
+
35
+ entity_cert = File.expand_path(@auth[:entity_cert])
36
+ entity_key = File.expand_path(@auth[:entity_key])
37
+ entity = OmfCommon::Auth::Certificate.create_from_pem(File.read(entity_cert))#, File.read(entity_key))
38
+
39
+ trusted_roots = File.expand_path(@auth[:root_cert_dir])
40
+
41
+ #run frisbee server
42
+ def create_frisbeed(comm, fcontroller, port, options)
43
+ fcontroller.create(:frisbeed, hrn: 'frisbee server', image: options[:image], port: port) do |reply_msg|
44
+ #image "/var/lib/omf-images-5.4/baseline.ndz"
45
+ if reply_msg.success?
46
+ server = reply_msg.resource
47
+ @@server = server
48
+ server.on_subscribed do
49
+ server.on_message do |m|
50
+ if m.operation == :inform
51
+ if m.read_content("event") == "STDOUT"
52
+ puts m.read_content("msg")
53
+ elsif m.read_content("event") == "EXIT"
54
+ puts m.read_content("msg")
55
+ end
56
+ end
57
+ end
58
+ end
59
+ else
60
+ error ">>> Frisbeed resource creation failed - #{reply_msg[:reason]}"
61
+ end
62
+ end
63
+ end
64
+
65
+ #run frisbee client on a node
66
+ def create_frisbee(comm, fcontroller, node, port, options)
67
+ fcontroller.create(:frisbee, hrn: 'frisbee client', port: port, node_topic: "#{node.to_s}") do |reply_msg|
68
+ if reply_msg.success?
69
+ client = reply_msg.resource
70
+ client.on_subscribed do
71
+ client.on_message do |client_msg|
72
+ if client_msg.operation == :inform
73
+ if client_msg.read_property("event") == "STARTED"#only happens when frisbee runs with :application rc
74
+ # @nof_nodes_up_frisbee += 1
75
+ # if @nof_nodes == @nof_nodes_up_frisbee
76
+ # create_frisbeed(fcontroller, port) #frisbee server
77
+ # puts "load operation started."
78
+ # end
79
+ elsif client_msg.read_property("event") == "STDOUT"
80
+ puts "#{client_msg.read_property("node")}: #{client_msg.read_property("msg")}"
81
+ elsif client_msg.read_property("event") == "EXIT"
82
+ puts "#{client_msg.read_property("node")}: #{client_msg.read_property("msg")}"
83
+ comm.subscribe('cm_factory') do |controller|
84
+ controller.on_message do |cm_msg|
85
+ if cm_msg.operation == :inform
86
+ case cm_msg.read_content("itype")
87
+ when 'STATUS'
88
+ unless cm_msg.read_property("current").nil? || cm_msg.read_property("desired").nil?
89
+ if cm_msg.read_property("current").to_sym == :pxe_off && cm_msg.read_property("desired").to_sym == :pxe_off
90
+ n = cm_msg.read_property("node")
91
+ @nodes_up_without_pxe << n
92
+ if @nodes_up_pxe.length == (@nodes_up_without_pxe.length + @nodes_failed_without_pxe.length)
93
+ puts "load proccess completed."
94
+ fcontroller.release(@@server) do |reply_msg|
95
+ comm.disconnect
96
+ end
97
+ end
98
+ end
99
+ end
100
+ when 'ERROR'
101
+ case cm_msg.read_property("event_type")
102
+ when "AUTH"
103
+ logger.info "#{cm_msg.read_property("msg")}, exit code: #{cm_msg.read_property("exit_code")}"
104
+ n = cm_msg.read_property("node_name")
105
+ @nodes_failed_without_pxe << n
106
+ if (@nodes_up_without_pxe.length + @nodes_failed_without_pxe.length) == options[:target_nodes].length
107
+ puts "load proccess completed."
108
+ fcontroller.release(@@server) do |reply_msg|
109
+ comm.disconnect
110
+ end
111
+ end
112
+ when "HTTP"
113
+ logger.info "#{cm_msg.read_property("msg")}, exit code: #{cm_msg.read_property("exit_code")}"
114
+ n = cm_msg.read_property("node_name")
115
+ if @nodes_retrying_without_pxe.include?(n)
116
+ @nodes_retrying_without_pxe.delete(n)
117
+ @nodes_failed_without_pxe << n
118
+ if (@nodes_up_without_pxe.length + @nodes_failed_without_pxe.length) == options[:target_nodes].length
119
+ fcontroller.release(@@server) do |reply_msg|
120
+ comm.disconnect
121
+ end
122
+ end
123
+ else
124
+ @nodes_retrying_without_pxe << n
125
+ controller.configure(state: {node: n.to_sym, status: :start_on_pxe})
126
+ end
127
+ when "TIME_OUT"
128
+ logger.info "#{cm_msg.read_property("msg")}, exit code: #{cm_msg.read_property("exit_code")}"
129
+ n = cm_msg.read_property("node_name")
130
+ @nodes_failed_without_pxe << n
131
+ if (@nodes_up_without_pxe.length + @nodes_failed_without_pxe.length) == options[:target_nodes].length
132
+ fcontroller.release(@@server) do |reply_msg|
133
+ comm.disconnect
134
+ end
135
+ end
136
+ else
137
+ error cm_msg.read_content('reason') if cm_msg.read_content("reason")
138
+ end
139
+ when 'WARN'
140
+ warn cm_msg.read_content('reason') if cm_msg.read_content("reason")
141
+ end
142
+ end
143
+ end
144
+ puts "#{options[:last_action]} node '#{client_msg.read_property("node")}' out of PXE."
145
+ controller.configure(state: {node: node.to_sym, status: :start_without_pxe, last_action: options[:last_action]})
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
151
+ else
152
+ error ">>> Frisbee resource creation failed - #{reply_msg[:reason]}"
153
+ end
154
+ end
155
+ end
156
+
157
+ def load(comm, options)
158
+ comm.subscribe('cm_factory') do |controller|
159
+ #TODO handle the case some nodes are not up and running
160
+ unless controller.error?
161
+ @nof_nodes = options[:target_nodes].length
162
+ @nodes_up_without_pxe = []
163
+ @nodes_failed_without_pxe = []
164
+ @nodes_retrying_without_pxe = []
165
+ @nodes_up_pxe = []
166
+ nodes_failed_pxe = []
167
+ nodes_retrying_pxe = []
168
+ port = nil
169
+ controller.on_message do |m|
170
+ if m.operation == :inform
171
+ case m.read_content("itype")
172
+ when 'STATUS'
173
+ unless m.read_property("current").nil? && m.read_property("desired").nil?
174
+ if m.read_property("current").to_sym == :pxe_on && m.read_property("desired").to_sym == :pxe_on
175
+ n = m.read_property("node_name")
176
+ @nodes_up_pxe << n
177
+ if @nof_nodes == (@nodes_up_pxe.length + nodes_failed_pxe.length) #all nodes are up and running on pxe
178
+ puts "all nodes are up and running on pxe."
179
+ comm.subscribe('frisbee_factory') do |fcontroller|
180
+ puts "requesting available port"
181
+ fcontroller.request([:ports]) do |m|
182
+ port = m.read_property("ports")
183
+ puts "running frisbee server on port '#{port}'"
184
+ create_frisbeed(comm, fcontroller, port, options)
185
+ @nodes_up_pxe.each do |node|
186
+ create_frisbee(comm, fcontroller, node, port, options) #frisbee client
187
+ end
188
+ puts "running frisbee client on specified nodes."
189
+ end
190
+ end
191
+ end
192
+ else
193
+ error "exit code: #{m.read_content('exit_code')}" if m.read_content('exit_code')
194
+ end
195
+ end
196
+ when 'ERROR'
197
+ case m.read_property("event_type")
198
+ when "AUTH"
199
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
200
+ n = m.read_property("node_name")
201
+ nodes_failed_pxe << n
202
+ if @nof_nodes == (@nodes_up_pxe.length + nodes_failed_pxe.length) #all nodes are up and running on pxe
203
+ puts "all nodes are up and running on pxe."
204
+ comm.subscribe('frisbee_factory') do |fcontroller|
205
+ puts "requesting available port"
206
+ fcontroller.request([:ports]) do |m|
207
+ port = m.read_property("ports")
208
+ puts "running frisbee server on port '#{port}'"
209
+ create_frisbeed(comm, fcontroller, port, options)
210
+ @nodes_up_pxe.each do |node|
211
+ create_frisbee(comm, fcontroller, node, port, options) #frisbee client
212
+ end
213
+ puts "running frisbee client on specified nodes."
214
+ end
215
+ end
216
+ end
217
+ when "HTTP"
218
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
219
+ n = m.read_property("node_name")
220
+ if nodes_retrying_pxe.include?(n)
221
+ nodes_retrying_pxe.delete(n)
222
+ nodes_failed_pxe << n
223
+ if @nof_nodes == (@nodes_up_pxe.length + nodes_failed_pxe.length) #all nodes are up and running on pxe
224
+ puts "all nodes are up and running on pxe."
225
+ comm.subscribe('frisbee_factory') do |fcontroller|
226
+ puts "requesting available port"
227
+ fcontroller.request([:ports]) do |m|
228
+ port = m.read_property("ports")
229
+ puts "running frisbee server on port '#{port}'"
230
+ create_frisbeed(comm, fcontroller, port, options)
231
+ @nodes_up_pxe.each do |node|
232
+ create_frisbee(comm, fcontroller, node, port, options) #frisbee client
233
+ end
234
+ puts "running frisbee client on specified nodes."
235
+ end
236
+ end
237
+ end
238
+ else
239
+ nodes_retrying_pxe << n
240
+ controller.configure(state: {node: n.to_sym, status: :start_on_pxe})
241
+ end
242
+ when "TIME_OUT"
243
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
244
+ n = m.read_property("node_name")
245
+ nodes_failed_pxe << n
246
+ if @nof_nodes == (@nodes_up_pxe.length + nodes_failed_pxe.length) #all nodes are up and running on pxe
247
+ puts "all nodes are up and running on pxe."
248
+ comm.subscribe('frisbee_factory') do |fcontroller|
249
+ puts "requesting available port"
250
+ fcontroller.request([:ports]) do |m|
251
+ port = m.read_property("ports")
252
+ puts "running frisbee server on port '#{port}'"
253
+ create_frisbeed(comm, fcontroller, port, options)
254
+ @nodes_up_pxe.each do |node|
255
+ create_frisbee(comm, fcontroller, node, port, options) #frisbee client
256
+ end
257
+ puts "running frisbee client on specified nodes."
258
+ end
259
+ end
260
+ end
261
+ else
262
+ error m.read_content('reason') if m.read_content("reason")
263
+ end
264
+ when 'WARN'
265
+ warn cm_msg.read_content('reason') if m.read_content("reason")
266
+ end
267
+ end
268
+ end
269
+ options[:target_nodes].each do |node|
270
+ controller.configure(state: {node: node.to_sym, status: :start_on_pxe})
271
+ end
272
+ puts "waiting for target nodes to boot on PXE."
273
+ else
274
+ error controller.inspect
275
+ end
276
+ end
277
+ end
278
+
279
+ #run imagezip server
280
+ def create_imagezip_server(comm, fcontroller, port, options)
281
+ fcontroller.create(:imagezip_server, {hrn: 'imagezip server', image: options[:image], port: port}) do |reply_msg|
282
+ if reply_msg.success?
283
+ server = reply_msg.resource
284
+ @@server = server
285
+ server.on_subscribed do
286
+ server.on_message do |m|
287
+ if m.operation == :inform
288
+ if m.read_content("event") == "STDOUT"
289
+ puts m.read_content("msg")
290
+ elsif m.read_content("event") == "EXIT"
291
+ puts m.read_content("msg")
292
+ end
293
+ end
294
+ end
295
+ end
296
+ else
297
+ error ">>> Imagezip Server resource creation failed - #{reply_msg[:reason]}"
298
+ end
299
+ end
300
+ end
301
+
302
+ #run imagezip client on a node
303
+ def create_imagezip_client(comm, fcontroller, node, port, options)
304
+ fcontroller.create(:imagezip_client, {hrn: 'imagezip client', port: port, node_topic: "#{node.to_s}"}) do |reply_msg|
305
+ if reply_msg.success?
306
+ client = reply_msg.resource
307
+ client.on_subscribed do
308
+ client.on_message do |client_msg|
309
+ if client_msg.operation == :inform
310
+ if client_msg.read_property("event") == "STDOUT"
311
+ print "#{client_msg.read_property("msg")}"
312
+ elsif client_msg.read_property("event") == "EXIT"
313
+ puts "#{client_msg.read_property("node")}: #{client_msg.read_property("msg")}"
314
+ comm.subscribe('cm_factory') do |controller|
315
+ controller.on_message do |cm_msg|
316
+ if cm_msg.operation == :inform
317
+ case cm_msg.read_content("itype")
318
+ when 'STATUS'
319
+ unless cm_msg.read_property("current").nil? && cm_msg.read_property("desired").nil?
320
+ if cm_msg.read_property("current").to_sym == :pxe_off && cm_msg.read_property("desired").to_sym == :pxe_off
321
+ puts "save proccess completed. Image was saved in directory '/var/lib/omf-images-6'"
322
+ fcontroller.release(@@server) do |reply_msg|
323
+ comm.disconnect
324
+ end
325
+ end
326
+ end
327
+ when 'ERROR'
328
+ case cm_msg.read_property("event_type")
329
+ when "AUTH"
330
+ logger.info "#{cm_msg.read_property("msg")}, exit code: #{cm_msg.read_property("exit_code")}"
331
+ fcontroller.release(@@server) do |reply_msg|
332
+ comm.disconnect
333
+ end
334
+ when "HTTP"
335
+ logger.info "#{cm_msg.read_property("msg")}, exit code: #{cm_msg.read_property("exit_code")}"
336
+ if @retried
337
+ fcontroller.release(@@server) do |reply_msg|
338
+ comm.disconnect
339
+ end
340
+ else
341
+ @retried = true
342
+ controller.configure(state: {node: node.to_sym, status: :start_without_pxe, last_action: options[:last_action]})
343
+ end
344
+ when "TIME_OUT"
345
+ logger.info "#{cm_msg.read_property("msg")}, exit code: #{cm_msg.read_property("exit_code")}"
346
+ fcontroller.release(@@server) do |reply_msg|
347
+ comm.disconnect
348
+ end
349
+ else
350
+ error cm_msg.read_content('reason') if cm_msg.read_content("reason")
351
+ end
352
+ when 'WARN'
353
+ warn cm_msg.read_content('reason') if cm_msg.read_content("reason")
354
+ end
355
+ end
356
+ end
357
+ puts "#{options[:last_action]} node '#{client_msg.read_property("node")}' out of PXE."
358
+ controller.configure(state: {node: node.to_sym, status: :start_without_pxe, last_action: options[:last_action]})
359
+ end
360
+ end
361
+ end
362
+ end
363
+ end
364
+ else
365
+ error ">>> Frisbee resource creation failed - #{reply_msg[:reason]}"
366
+ end
367
+ end
368
+ end
369
+
370
+ def save(comm, options)
371
+ comm.subscribe('cm_factory') do |controller|
372
+ @retried = false
373
+ unless controller.error?
374
+ port = nil
375
+ controller.on_message do |m|
376
+ if m.operation == :inform
377
+ puts m.inspect
378
+ case m.read_content("itype")
379
+ when 'STATUS'
380
+ unless m.read_property("current").nil? && m.read_property("desired").nil?
381
+ logger.info "#{m.read_property("node_name")}, current: #{m.read_property("current")}, desired: #{m.read_property("desired")}"
382
+ if m.read_property("current").to_sym == :pxe_on && m.read_property("desired").to_sym == :pxe_on
383
+ puts "node is up and running on pxe."
384
+ comm.subscribe('frisbee_factory') do |fcontroller|
385
+ puts "requesting available port"
386
+ fcontroller.request([:ports]) do |m|
387
+ port = m.read_property("ports")
388
+ puts "running imagezip server on port #{port}."
389
+ create_imagezip_server(comm, fcontroller, port, options)
390
+ sleep 2
391
+ puts "running imagezip client on node."
392
+ create_imagezip_client(comm, fcontroller, options[:node], port, options)
393
+ end
394
+ end
395
+ else
396
+ error "exit code: #{m.read_content('exit_code')}" if m.read_content('exit_code')
397
+ end
398
+ end
399
+ when 'ERROR'
400
+ case m.read_property("event_type")
401
+ when "AUTH"
402
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
403
+ comm.disconnect
404
+ when "HTTP"
405
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
406
+ if @retried
407
+ comm.disconnect
408
+ else
409
+ @retried = true
410
+ controller.configure(state: {node: options[:node].to_sym, status: :start_on_pxe})
411
+ end
412
+ when "TIME_OUT"
413
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
414
+ comm.disconnect
415
+ else
416
+ error m.read_content('reason') if m.read_content("reason")
417
+ end
418
+ when 'WARN'
419
+ warn m.read_content('reason') if m.read_content("reason")
420
+ end
421
+ end
422
+ end
423
+
424
+ controller.configure(state: {node: options[:node].to_sym, status: :start_on_pxe})
425
+ puts "waiting for node to boot on PXE."
426
+ else
427
+ error controller.inspect
428
+ end
429
+ end
430
+ end
431
+
432
+ def tell(comm, options)
433
+ comm.subscribe('cm_factory') do |controller|
434
+ unless controller.error?
435
+ nodes_failed = []
436
+ nodes_ok = []
437
+ nodes_retrying = []
438
+ controller.on_message do |m|
439
+ if m.operation == :inform
440
+ case m.read_content("itype")
441
+ when 'STATUS'
442
+ unless m.read_property("current").nil? && m.read_property("desired").nil?
443
+ if m.read_property("current") != m.read_property("desired")
444
+ if options[:wait]
445
+ puts "Waiting for node '#{m.read_property("node_name")}'."
446
+ logger.info "#{m.read_property("node_name")} is #{m.read_property("current")}."
447
+ else
448
+ n = m.read_property("node_name")
449
+ nodes_ok << n
450
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
451
+ puts "all nodes are running." #TODO messages for failed nodes
452
+ comm.disconnect
453
+ end
454
+ end
455
+ else
456
+ n = m.read_property("node_name")
457
+ nodes_ok << n
458
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
459
+ puts "all nodes are #{m.read_property("desired")}." #TODO messages for failed nodes
460
+ comm.disconnect
461
+ end
462
+ end
463
+ end
464
+ when 'ERROR'
465
+ case m.read_property("event_type")
466
+ when "AUTH"
467
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
468
+ n = m.read_property("node_name")
469
+ nodes_failed << n
470
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
471
+ comm.disconnect
472
+ end
473
+ when "HTTP"
474
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
475
+ n = m.read_property("node_name")
476
+ if nodes_retrying.include?(n)
477
+ nodes_retrying.delete(n)
478
+ nodes_failed << n
479
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
480
+ comm.disconnect
481
+ end
482
+ else
483
+ nodes_retrying << n
484
+ info "retrying to send message #{options[:status]} to node #{n}"
485
+ controller.configure(state: {node: n.to_sym, status: options[:status].to_sym})
486
+ end
487
+ when "TIME_OUT"
488
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
489
+ n = m.read_property("node_name")
490
+ nodes_failed << n
491
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
492
+ comm.disconnect
493
+ end
494
+ else
495
+ error m.read_content('reason') if m.read_content("reason")
496
+ comm.disconnect
497
+ end
498
+ when 'WARN'
499
+ warn m.read_content('reason') if m.read_content("reason")
500
+ end
501
+ end
502
+ end
503
+ if options[:status] == "on"
504
+ options[:target_nodes].each do |node|
505
+ controller.configure(state: {node: node.to_sym, status: :on, wait: options[:wait]})
506
+ end
507
+ elsif options[:status] == "off"
508
+ options[:target_nodes].each do |node|
509
+ controller.configure(state: {node: node.to_sym, status: :off, wait: options[:wait]})
510
+ end
511
+ elsif options[:status] == "reset"
512
+ options[:target_nodes].each do |node|
513
+ controller.configure(state: {node: node.to_sym, status: :reset, wait: options[:wait]})
514
+ end
515
+ else
516
+ puts "Invalid value for -a, only on/off/reset values are available."
517
+ puts opt_parser
518
+ comm.disconnect
519
+ end
520
+ unless options[:wait]
521
+ puts "Proccess complete."
522
+ comm.disconnect
523
+ end
524
+ else
525
+ error controller.inspect
526
+ end
527
+ end
528
+ end
529
+
530
+ def stat(comm, options)
531
+ comm.subscribe('cm_factory') do |controller|
532
+ unless controller.error?
533
+ nodes_failed = []
534
+ nodes_ok = []
535
+ nodes_retrying = []
536
+ controller.on_message do |m|
537
+ if m.operation == :inform
538
+ case m.read_content("itype")
539
+ when 'STATUS'
540
+ unless m.read_property("current").nil?
541
+ puts "#{m.read_property("node_name")} is #{m.read_property("current")}"
542
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
543
+ n = m.read_property("node_name")
544
+ nodes_ok << n
545
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
546
+ comm.disconnect
547
+ end
548
+ # elsif m.read_property("event_type") == "EXIT"
549
+ # puts "ERROR: #{m.read_property("node")} - #{m.read_property("msg")}"
550
+ # logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
551
+ # nof_nodes += 1
552
+ # if nof_nodes == options[:target_nodes].length
553
+ # comm.disconnect
554
+ # end
555
+ end
556
+ when 'ERROR'
557
+ case m.read_property("event_type")
558
+ when "AUTH"
559
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
560
+ n = m.read_property("node_name")
561
+ nodes_failed << n
562
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
563
+ comm.disconnect
564
+ end
565
+ when "HTTP"
566
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
567
+ n = m.read_property("node_name")
568
+ if nodes_retrying.include?(n)
569
+ nodes_retrying.delete(n)
570
+ nodes_failed << n
571
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
572
+ comm.disconnect
573
+ end
574
+ else
575
+ nodes_retrying << n
576
+ info "retrying to send message #{options[:status]} to node #{n}"
577
+ controller.configure(state: {node: n.to_sym, status: :get_status})
578
+ end
579
+ when "TIME_OUT"
580
+ logger.info "#{m.read_property("msg")}, exit code: #{m.read_property("exit_code")}"
581
+ n = m.read_property("node_name")
582
+ nodes_failed << n
583
+ if (nodes_ok.length + nodes_failed.length) == options[:target_nodes].length
584
+ comm.disconnect
585
+ end
586
+ else
587
+ error m.read_content('reason') if m.read_content("itype") == 'ERROR'
588
+ comm.disconnect
589
+ end
590
+ when 'WARN'
591
+ warn m.read_content('reason') if m.read_content("itype") == 'WARN'
592
+ end
593
+ end
594
+ end
595
+
596
+ options[:target_nodes].each do |node|
597
+ controller.configure(state: {node: node.to_sym, status: :get_status})
598
+ end
599
+ else
600
+ error controller.inspect
601
+ comm.disconnect
602
+ end
603
+ end
604
+ end
605
+
606
+ opt_parser.parse!
607
+
608
+ OmfCommon.init(@config[:operationMode], communication: { url: "xmpp://#{@xmpp[:script_user]}:#{@xmpp[:password]}@#{@xmpp[:server]}", auth: {} }) do
609
+ OmfCommon.comm.on_connected do |comm|
610
+ OmfCommon::Auth::CertificateStore.instance.register_default_certs(trusted_roots)
611
+ entity.resource_id = OmfCommon.comm.local_topic.address
612
+ OmfCommon::Auth::CertificateStore.instance.register(entity)
613
+
614
+ info "Test script >> Connected to XMPP"
615
+
616
+ case ARGV[0]
617
+ when "load"
618
+ if options[:node].nil? && options[:status].nil? && !options[:target_nodes].nil?
619
+ if options[:last_action] == "reset" || options[:last_action] == "shutdown"
620
+ puts "call load on options #{options.inspect}"
621
+ load(comm, options)
622
+ else
623
+ puts "Invalid value for -l, only reset/shutdown values are available."
624
+ puts opt_parser
625
+ comm.disconnect
626
+ end
627
+ else
628
+ puts "Invalid arguements."
629
+ puts opt_parser
630
+ comm.disconnect
631
+ end
632
+ when "save"
633
+ if options[:image].nil? && !options[:node].nil? && options[:status].nil? && options[:target_nodes].nil?
634
+ if options[:last_action] == "reset" || options[:last_action] == "shutdown"
635
+ puts "call save on options #{options.inspect}"
636
+ save(comm, options)
637
+ else
638
+ puts "Invalid value for -l, only reset/shutdown values are available."
639
+ puts opt_parser
640
+ comm.disconnect
641
+ end
642
+ else
643
+ puts "Invalid arguements."
644
+ puts opt_parser
645
+ comm.disconnect
646
+ end
647
+ when "tell"
648
+ if options[:image].nil? && options[:node].nil? && !options[:status].nil? && !options[:target_nodes].nil?
649
+ if options[:status] == "on" || options[:status] == "off" || options[:status] == "reset"
650
+ puts "call tell on options #{options.inspect}"
651
+ tell(comm, options)
652
+ else
653
+ puts "Invalid value for -a, only on/off/reset values are available."
654
+ puts opt_parser
655
+ comm.disconnect
656
+ end
657
+ else
658
+ puts "Invalid arguements."
659
+ puts opt_parser
660
+ comm.disconnect
661
+ end
662
+ when "stat"
663
+ if options[:image].nil? && options[:node].nil? && options[:status].nil? && !options[:target_nodes].nil?
664
+ puts "call stat on options #{options.inspect}"
665
+ stat(comm, options)
666
+ else
667
+ puts "Invalid arguements."
668
+ puts opt_parser
669
+ comm.disconnect
670
+ end
671
+ else
672
+ puts "Invalid command / options."
673
+ puts opt_parser
674
+ comm.disconnect
675
+ end
676
+
677
+ comm.on_interrupted { comm.disconnect }
678
+ end
679
+ end