nitos_testbed_rc 1.0.0.pre.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.
data/bin/run_proxies ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ libs = []
4
+ # if you need to add libraries add them bellow. Examples:
5
+ # libs << "../lib/master/omf/omf_common/lib/"
6
+ # libs << "../lib/master/omf/omf_rc/lib/"
7
+
8
+ spec = Gem::Specification.find_by_name("nitos_testbed_rc")
9
+ gem_root = spec.gem_dir
10
+
11
+ threads = []
12
+ ["user_proxy", "frisbee_proxy", "cm_proxy"].each do |sc|
13
+ threads << Thread.new do
14
+ if libs.empty?
15
+ puts "EXEC: #{sc}"
16
+ system(sc)
17
+ else
18
+ cmd = "ruby "
19
+ libs.each {|l| cmd += "-I #{l} "}
20
+ cmd += "#{gem_root}/bin/#{sc}"
21
+ puts "EXEC: #{cmd}"
22
+ system(cmd)
23
+ end
24
+ end
25
+ sleep 1
26
+ end
27
+
28
+ threads.each {|t| t.join}
29
+ sleep 1
data/bin/user_proxy ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'omf_rc'
4
+ require 'omf_common'
5
+ require 'yaml'
6
+
7
+ $stdout.sync = true
8
+
9
+ @config = YAML.load_file('/etc/nitos_testbed_rc/user_proxy_conf.yaml')
10
+ # @config = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), '.../etc/user_proxy_conf.yaml'))
11
+ @auth = @config[:auth]
12
+ @xmpp = @config[:xmpp]
13
+
14
+ require 'nitos_testbed_rc/user'
15
+ require 'nitos_testbed_rc/user_factory'
16
+
17
+ user_entity_cert = File.expand_path(@auth[:entity_cert])
18
+ user_entity_key = File.expand_path(@auth[:entity_key])
19
+ user_entity = OmfCommon::Auth::Certificate.create_from_pem(File.read(user_entity_cert))#, File.read(user_entity_key))
20
+
21
+ trusted_roots = File.expand_path(@auth[:root_cert_dir])
22
+
23
+ opts = {
24
+ communication: {
25
+ url: "xmpp://#{@xmpp[:username]}:#{@xmpp[:password]}@#{@xmpp[:server]}",
26
+ auth: {
27
+ authenticate: true,
28
+ pdp: {
29
+ constructor: 'UserPDP'
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ class UserPDP
36
+ def initialize(opts = {})
37
+ debug "AUTH INIT>>> #{opts}"
38
+ end
39
+
40
+ def authorize(msg, &block)
41
+ msg
42
+ end
43
+ end
44
+
45
+ OmfCommon.init(@config[:operationMode], opts) do |el|#communication: { url: "xmpp://#{@xmpp[:proxy_user]}:#{@xmpp[:password]}@#{@xmpp[:server]}", auth: {} }) do
46
+ OmfCommon.comm.on_connected do |comm|
47
+ OmfCommon::Auth::CertificateStore.instance.register_default_certs(trusted_roots)
48
+ user_entity.resource_id = OmfCommon.comm.local_topic.address
49
+ OmfCommon::Auth::CertificateStore.instance.register(user_entity)
50
+
51
+ info "User Factory >> Connected to XMPP server"
52
+ userFact = OmfRc::ResourceFactory.create(:user_factory, { uid: 'user_factory', certificate: user_entity })
53
+
54
+ comm.on_interrupted {
55
+ userFact.disconnect
56
+ }
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ #details to be used for the connection to the xmpp server
2
+ :xmpp:
3
+ :username: cm_proxy
4
+ :password: pw
5
+ :server: testserver
6
+ #x509 certificates to be used by cm_proxy
7
+ :auth:
8
+ :root_cert_dir: ~/.omf/trusted_roots
9
+ :entity_cert: ~/.omf/cm_factory.pem
10
+ :entity_key: ~/.omf/cm_factory.pkey
11
+
12
+ #time (in seconds) before timeout error occurs
13
+ :timeout: 80
14
+ #operation mode for OmfCommon.init (development, production, etc)
15
+ :operationMode: development
16
+ #testbed xmpp topic
17
+ :testbedTopic: am_controller
@@ -0,0 +1,45 @@
1
+ #xmpp details
2
+ :xmpp:
3
+ :username: frisbee_proxy
4
+ :password: pw
5
+ :server: testserver
6
+ #x509 certificates to be used by user_proxy
7
+ :auth:
8
+ :root_cert_dir: ~/.omf/trusted_roots
9
+ :entity_cert: ~/.omf/frisbee_factory.pem
10
+ :entity_key: ~/.omf/frisbee_factory.pkey
11
+
12
+ #operation Mode for OmfCommon.init (development, production, etc)
13
+ :operationMode: development
14
+
15
+ #testbed xmpp topic
16
+ :testbedTopic: am_controller
17
+
18
+ #frisbee and imagezip configuration
19
+ :frisbee:
20
+ # Directory images are stored
21
+ :imageDir: /var/lib/omf-images-6
22
+ #defaultImage: orbit-baseline
23
+ :defaultImage: baseline.ndz
24
+
25
+ # max bandwidth for frisbee server
26
+ :bandwidth: 50000000
27
+
28
+ # Multicast address to use for servicing images
29
+ #mcAddress: 224.0.0.2
30
+ :mcAddress: 224.0.0.1
31
+ # Using ports starting at ...
32
+ :startPort: 7000
33
+
34
+ # Time out frisbee server if nobody requested it within TIMEOUT sec
35
+ :timeout: 3600
36
+
37
+ # Directory to find frisbee daemons
38
+ :frisbeedBin: /usr/sbin/frisbeed
39
+ :frisbeeBin: /usr/sbin/frisbee
40
+ :imagezipClientBin: /usr/bin/imagezip
41
+ :imagezipServerBin: /bin/nc
42
+
43
+ # Local interface to bind to for frisbee traffic
44
+ #multicastIF: 192.168.204.1
45
+ :multicastIF: 10.0.1.200
@@ -0,0 +1,14 @@
1
+ :xmpp:
2
+ :script_user: script_user
3
+ :password: pw
4
+ :server: testserver
5
+ :auth:
6
+ :root_cert_dir: ~/.omf/trusted_roots
7
+ :entity_cert: ~/.omf/user_cert.pem
8
+ :entity_key: ~/.omf/user_cert.pkey
9
+ #operation mode for OmfCommon.init (development, production, etc)
10
+ :operationMode: development
11
+ #omf script configuration
12
+ :omf_script:
13
+ #default last action on load and save commands (reset or shutdown)
14
+ :last_action: reset
@@ -0,0 +1,12 @@
1
+ #xmpp details
2
+ :xmpp:
3
+ :username: user_proxy
4
+ :password: pw
5
+ :server: testserver
6
+ #x509 certificates to be used by user_proxy
7
+ :auth:
8
+ :root_cert_dir: ~/.omf/trusted_roots
9
+ :entity_cert: ~/.omf/user_factory.pem
10
+ :entity_key: ~/.omf/user_factory.pkey
11
+ #operation mode for OmfCommon.init (development, production, etc)
12
+ :operationMode: development
@@ -0,0 +1,419 @@
1
+ #this resource is used to control chassis managers.
2
+ require 'rubygems'
3
+ require 'yaml'
4
+ require 'open-uri'
5
+ require 'nokogiri'
6
+ require 'net/ssh'
7
+
8
+ REBOOT_CMD = "reboot"
9
+ SHUTDOWN_CMD = "shutdown -P now"
10
+
11
+ module OmfRc::ResourceProxy::CMFactory
12
+ include OmfRc::ResourceProxyDSL
13
+
14
+ @config = YAML.load_file('/etc/nitos_testbed_rc/cm_proxy_conf.yaml')
15
+ # @config = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), '../etc/cm_proxy_conf.yaml'))
16
+ @timeout = @config[:timeout]
17
+
18
+ register_proxy :cm_factory
19
+
20
+ configure :state do |res, value|
21
+ debug "Received message '#{value.inspect}'"
22
+ if error_msg = value.error_msg
23
+ res.inform(:error,{
24
+ event_type: "AUTH",
25
+ exit_code: "-1",
26
+ node_name: value[:node],
27
+ msg: error_msg
28
+ }, :ALL)
29
+ next
30
+ end
31
+ nod = {}
32
+ nod[:node_name] = value.node[:resource][:name]
33
+ value.node[:resource][:interfaces].each do |i|
34
+ if i[:role] == "control"
35
+ nod[:node_ip] = i[:ip][:address]
36
+ nod[:node_mac] = i[:mac]
37
+ elsif i[:role] == "cm_network"
38
+ nod[:node_cm_ip] = i[:ip][:address]
39
+ end
40
+ end
41
+ nod[:node_cm_ip] = value.node[:resource][:cmc][:ip][:address]
42
+ # nod = {node_name: "node1", node_ip: "10.0.0.1", node_mac: "00-03-1d-0d-4b-96", node_cm_ip: "10.0.0.101"}
43
+
44
+ case value[:status].to_sym
45
+ when :on then res.start_node(nod, value[:wait])
46
+ when :off then res.stop_node(nod, value[:wait])
47
+ when :reset then res.reset_node(nod, value[:wait])
48
+ when :start_on_pxe then res.start_node_pxe(nod)
49
+ when :start_without_pxe then res.start_node_pxe_off(nod, value[:last_action])
50
+ when :get_status then res.status(nod)
51
+ else
52
+ res.log_inform_warn "Cannot switch node to unknown state '#{value[:status].to_s}'!"
53
+ end
54
+ end
55
+
56
+ work("wait_until_ping") do |res, ip|
57
+ t = 0
58
+ resp = false
59
+ loop do
60
+ sleep 2
61
+ status = system("ping #{ip} -c 2 -w 2")
62
+ if t < @timeout
63
+ if status == true
64
+ resp = true
65
+ break
66
+ end
67
+ else
68
+ resp = false
69
+ break
70
+ end
71
+ t += 2
72
+ end
73
+ resp
74
+ end
75
+
76
+ work("wait_until_no_ping") do |res, ip|
77
+ t = 0
78
+ resp = false
79
+ loop do
80
+ sleep 2
81
+ status = system("ping #{ip} -c 2 -w 2")
82
+ if t < @timeout
83
+ if status == false
84
+ resp = true
85
+ break
86
+ end
87
+ else
88
+ resp = false
89
+ break
90
+ end
91
+ t += 2
92
+ end
93
+ resp
94
+ end
95
+
96
+ #this is used by other methods in this scope
97
+ work("get_status") do |res, node|
98
+ debug "http://#{node[:node_cm_ip].to_s}/state"
99
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/state"))
100
+ resp = doc.xpath("//Response//line//value").text.strip
101
+ debug "state response: #{resp}"
102
+
103
+ if resp == 'on'
104
+ symlink_name = "/tftpboot/pxelinux.cfg/01-#{node[:node_mac]}"
105
+ if File.exists?("#{symlink_name}")
106
+ :on_pxe
107
+ else
108
+ :on
109
+ end
110
+ elsif resp == 'off'
111
+ :off
112
+ end
113
+ end
114
+
115
+ #this is used by the get status call
116
+ work("status") do |res, node|
117
+ debug "Status url: http://#{node[:node_cm_ip].to_s}/state"
118
+ begin
119
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/state"))
120
+ rescue
121
+ res.inform(:error, {
122
+ event_type: "HTTP",
123
+ exit_code: "-1",
124
+ node_name: "#{node[:node_name].to_s}",
125
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
126
+ }, :ALL)
127
+ next
128
+ end
129
+
130
+ res.inform(:status, {
131
+ current: "#{doc.xpath("//Response//line//value").text}",
132
+ node_name: "#{node[:node_name].to_s}"
133
+ }, :ALL)
134
+ sleep 1 #this solves the getting stuck problem.
135
+ end
136
+
137
+ work("start_node") do |res, node, wait|
138
+ debug "Start_node url: http://#{node[:node_cm_ip].to_s}/on"
139
+ begin
140
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/on"))
141
+ rescue
142
+ res.inform(:error, {
143
+ event_type: "HTTP",
144
+ exit_code: "-1",
145
+ node_name: "#{node[:node_name].to_s}",
146
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
147
+ }, :ALL)
148
+ next
149
+ end
150
+
151
+ if doc.xpath("//Response").text == 'ok'
152
+ res.inform(:status, {
153
+ node_name: "#{node[:node_name].to_s}",
154
+ current: :booting,
155
+ desired: :running
156
+ }, :ALL)
157
+ end
158
+
159
+ if wait
160
+ if res.wait_until_ping(node[:node_ip])
161
+ res.inform(:status, {
162
+ node_name: "#{node[:node_name].to_s}",
163
+ current: :running,
164
+ desired: :running
165
+ }, :ALL)
166
+ else
167
+ res.inform(:error, {
168
+ event_type: "TIME_OUT",
169
+ exit_code: "-1",
170
+ node_name: "#{node[:node_name].to_s}",
171
+ msg: "Node '#{node[:node_name].to_s}' timed out while booting."
172
+ }, :ALL)
173
+ end
174
+ end
175
+ sleep 1
176
+ end
177
+
178
+ work("stop_node") do |res, node, wait|
179
+ begin
180
+ debug "Shutting down node '#{node[:node_name]}' through ssh."
181
+ ssh = Net::SSH.start(node[:node_ip], 'root')#, :password => @password)
182
+ resp = ssh.exec!(SHUTDOWN_CMD)
183
+ ssh.close
184
+ debug "shutting down completed with ssh."
185
+ res.inform(:status, {
186
+ node_name: "#{node[:node_name].to_s}",
187
+ current: :running,
188
+ desired: :stopped
189
+ }, :ALL)
190
+ rescue
191
+ begin
192
+ debug "ssh failed, using CM card instead."
193
+ debug "Stop_node url: http://#{node[:node_cm_ip].to_s}/off"
194
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/off"))
195
+ if doc.xpath("//Response").text == 'ok'
196
+ res.inform(:status, {
197
+ node_name: "#{node[:node_name].to_s}",
198
+ current: :running,
199
+ desired: :stopped
200
+ }, :ALL)
201
+ end
202
+ rescue
203
+ res.inform(:error, {
204
+ event_type: "HTTP",
205
+ exit_code: "-1",
206
+ node_name: "#{node[:node_name].to_s}",
207
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
208
+ }, :ALL)
209
+ next
210
+ end
211
+ end
212
+
213
+ if wait
214
+ if res.wait_until_no_ping(node[:node_ip])
215
+ res.inform(:status, {
216
+ node_name: "#{node[:node_name].to_s}",
217
+ current: :stopped,
218
+ desired: :stopped
219
+ }, :ALL)
220
+ else
221
+ res.inform(:error, {
222
+ event_type: "TIME_OUT",
223
+ exit_code: "-1",
224
+ node_name: "#{node[:node_name].to_s}",
225
+ msg: "Node '#{node[:node_name].to_s}' timed out while shutting down."
226
+ }, :ALL)
227
+ end
228
+ end
229
+ sleep 1
230
+ end
231
+
232
+ work("reset_node") do |res, node, wait|
233
+ begin
234
+ debug "Rebooting node '#{node[:node_name]}' through ssh."
235
+ ssh = Net::SSH.start(node[:node_ip], 'root')#, :password => @password)
236
+ resp = ssh.exec!(REBOOT_CMD)
237
+ ssh.close
238
+ debug "Rebooting completed with ssh."
239
+ res.inform(:status, {
240
+ node_name: "#{node[:node_name].to_s}",
241
+ current: :running,
242
+ desired: :resetted
243
+ }, :ALL)
244
+ rescue
245
+ begin
246
+ debug "ssh failed, using CM card instead."
247
+ debug "Reset_node url: http://#{node[:node_cm_ip].to_s}/reset"
248
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/reset"))
249
+ if doc.xpath("//Response").text == 'ok'
250
+ res.inform(:status, {
251
+ node_name: "#{node[:node_name].to_s}",
252
+ current: :running,
253
+ desired: :resetted
254
+ }, :ALL)
255
+ end
256
+ rescue
257
+ res.inform(:error, {
258
+ event_type: "HTTP",
259
+ exit_code: "-1",
260
+ node_name: "#{node[:node_name].to_s}",
261
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
262
+ }, :ALL)
263
+ next
264
+ end
265
+ end
266
+
267
+ if wait
268
+ if res.wait_until_ping(node[:node_ip])
269
+ res.inform(:status, {
270
+ node_name: "#{node[:node_name].to_s}",
271
+ current: :resetted,
272
+ desired: :resetted
273
+ }, :ALL)
274
+ else
275
+ res.inform(:error, {
276
+ event_type: "TIME_OUT",
277
+ exit_code: "-1",
278
+ node_name: "#{node[:node_name].to_s}",
279
+ msg: "Node '#{node[:node_name].to_s}' timed out while reseting."
280
+ }, :ALL)
281
+ end
282
+ end
283
+ sleep 1
284
+ end
285
+
286
+ work("start_node_pxe") do |res, node|
287
+ resp = res.get_status(node)
288
+ if resp == :on
289
+ symlink_name = "/tftpboot/pxelinux.cfg/01-#{node[:node_mac]}"
290
+ if !File.exists?("#{symlink_name}")
291
+ File.symlink("/tftpboot/pxelinux.cfg/omf-5.4", "#{symlink_name}")
292
+ end
293
+ debug "Start_node_pxe RESET: http://#{node[:node_cm_ip].to_s}/reset"
294
+ begin
295
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/reset"))
296
+ rescue
297
+ res.inform(:error, {
298
+ event_type: "HTTP",
299
+ exit_code: "-1",
300
+ node_name: "#{node[:node_name].to_s}",
301
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
302
+ }, :ALL)
303
+ next
304
+ end
305
+ elsif resp == :off
306
+ symlink_name = "/tftpboot/pxelinux.cfg/01-#{node[:node_mac]}"
307
+ if !File.exists?("#{symlink_name}")
308
+ File.symlink("/tftpboot/pxelinux.cfg/omf-5.4", "#{symlink_name}")
309
+ end
310
+ debug "Start_node_pxe ON: http://#{node[:node_cm_ip].to_s}/on"
311
+ begin
312
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/on"))
313
+ rescue
314
+ res.inform(:error, {
315
+ event_type: "HTTP",
316
+ exit_code: "-1",
317
+ node_name: "#{node[:node_name].to_s}",
318
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
319
+ }, :ALL)
320
+ next
321
+ end
322
+ elsif resp == :started_on_pxe
323
+ debug "Start_node_pxe STARTED: http://#{node[:node_cm_ip].to_s}/reset"
324
+ begin
325
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/reset"))
326
+ rescue
327
+ res.inform(:error, {
328
+ event_type: "HTTP",
329
+ exit_code: "-1",
330
+ node_name: "#{node[:node_name].to_s}",
331
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
332
+ }, :ALL)
333
+ next
334
+ end
335
+ end
336
+
337
+ if res.wait_until_ping(node[:node_ip])
338
+ res.inform(:status, {
339
+ node_name: "#{node[:node_name].to_s}",
340
+ current: :pxe_on,
341
+ desired: :pxe_on
342
+ }, :ALL)
343
+ else
344
+ res.inform(:error, {
345
+ event_type: "TIME_OUT",
346
+ exit_code: "-1",
347
+ node_name: "#{node[:node_name].to_s}",
348
+ msg: "Node '#{node[:node_name].to_s}' timed out while trying to boot on PXE."
349
+ }, :ALL)
350
+ end
351
+ sleep 1
352
+ end
353
+
354
+ work("start_node_pxe_off") do |res, node, action|
355
+ symlink_name = "/tftpboot/pxelinux.cfg/01-#{node[:node_mac]}"
356
+ if File.exists?(symlink_name)
357
+ File.delete(symlink_name)
358
+ end
359
+ if action == "reset"
360
+ debug "Start_node_pxe_off RESET: http://#{node[:node_cm_ip].to_s}/reset"
361
+ begin
362
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/reset"))
363
+ rescue
364
+ res.inform(:error, {
365
+ event_type: "HTTP",
366
+ exit_code: "-1",
367
+ node_name: "#{node[:node_name].to_s}",
368
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
369
+ }, :ALL)
370
+ next
371
+ end
372
+
373
+ t = 0
374
+ if res.wait_until_ping(node[:node_ip])
375
+ res.inform(:status, {
376
+ node_name: "#{node[:node_name].to_s}",
377
+ current: :pxe_off,
378
+ desired: :pxe_off
379
+ }, :ALL)
380
+ else
381
+ res.inform(:error, {
382
+ event_type: "TIME_OUT",
383
+ exit_code: "-1",
384
+ node_name: "#{node[:node_name].to_s}",
385
+ msg: "Node '#{node[:node_name].to_s}' timed out while booting."
386
+ }, :ALL)
387
+ end
388
+ elsif action == "shutdown"
389
+ debug "Start_node_pxe_off SHUTDOWN: http://#{node[:node_cm_ip].to_s}/off"
390
+ begin
391
+ doc = Nokogiri::XML(open("http://#{node[:node_cm_ip].to_s}/off"))
392
+ rescue
393
+ res.inform(:error, {
394
+ event_type: "HTTP",
395
+ exit_code: "-1",
396
+ node_name: "#{node[:node_name].to_s}",
397
+ msg: "failed to reach cm, ip: #{node[:node_cm_ip].to_s}."
398
+ }, :ALL)
399
+ next
400
+ end
401
+
402
+ if res.wait_until_no_ping(node[:node_ip])
403
+ res.inform(:status, {
404
+ node_name: "#{node[:node_name].to_s}",
405
+ current: :pxe_off,
406
+ desired: :pxe_off
407
+ }, :ALL)
408
+ else
409
+ res.inform(:error, {
410
+ event_type: "TIME_OUT",
411
+ exit_code: "-1",
412
+ node_name: "#{node[:node_name].to_s}",
413
+ msg: "Node '#{node[:node_name].to_s}' timed out while shutting down."
414
+ }, :ALL)
415
+ end
416
+ end
417
+ sleep 1
418
+ end
419
+ end
@@ -0,0 +1,82 @@
1
+ #frisbee client
2
+ #created by parent :frisbee_factory
3
+ #used in load command
4
+ require 'net/telnet'
5
+ require 'socket'
6
+ require 'timeout'
7
+
8
+ module OmfRc::ResourceProxy::Frisbee #frisbee client
9
+ include OmfRc::ResourceProxyDSL
10
+ require 'omf_common/exec_app'
11
+ @config = YAML.load_file('/etc/nitos_testbed_rc/frisbee_proxy_conf.yaml')
12
+ # @config = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), '../etc/frisbee_proxy_conf.yaml'))
13
+ @fconf = @config[:frisbee]
14
+
15
+ register_proxy :frisbee, :create_by => :frisbee_factory
16
+
17
+ utility :common_tools
18
+ utility :platform_tools
19
+
20
+ property :app_id, :default => nil
21
+ property :binary_path, :default => @fconf[:frisbeeBin] #'/usr/sbin/frisbee'
22
+ property :map_err_to_out, :default => false
23
+
24
+ property :multicast_interface #multicast interface, example 10.0.1.12 for node12 (-i arguement)
25
+ property :multicast_address, :default => @fconf[:mcAddress] #multicast address, example 224.0.0.1 (-m arguement)
26
+ property :port #port, example 7000 (-p arguement)
27
+ property :hardrive, :default => "/dev/sda" #hardrive to burn the image, example /dev/sda (nparguement)
28
+ property :node_topic #the node
29
+
30
+ hook :after_initial_configured do |client|
31
+ Thread.new do
32
+ debug "Received message '#{client.opts.inspect}'"
33
+ if error_msg = client.opts.error_msg
34
+ res.inform(:error,{
35
+ event_type: "AUTH",
36
+ exit_code: "-1",
37
+ node_name: client.property.node_topic,
38
+ msg: error_msg
39
+ }, :ALL)
40
+ next
41
+ end
42
+ nod = {}
43
+ nod[:node_name] = client.opts.node.resource.name
44
+ client.opts.node.resource.interfaces.each do |i|
45
+ if i[:role] == "control"
46
+ nod[:node_ip] = i[:ip][:address]
47
+ nod[:node_mac] = i[:mac]
48
+ end
49
+ end
50
+ nod[:node_cm_ip] = client.opts.node.resource.cmc.ip.address
51
+ #nod = {node_name: "node1", node_ip: "10.0.0.1", node_mac: "00-03-1d-0d-4b-96", node_cm_ip: "10.0.0.101"}
52
+ client.property.multicast_interface = nod[:node_ip]
53
+ client.property.app_id = client.hrn.nil? ? client.uid : client.hrn
54
+
55
+ command = "#{client.property.binary_path} -i #{client.property.multicast_interface} -m #{client.property.multicast_address} -p #{client.property.port} #{client.property.hardrive}"
56
+ debug "Executing command #{command}"
57
+
58
+ host = Net::Telnet.new("Host" => client.property.multicast_interface.to_s, "Timeout" => 200, "Prompt" => /[\w().-]*[\$#>:.]\s?(?:\(enable\))?\s*$/)
59
+ host.cmd(command.to_s) do |c|
60
+ if c != "\n" && (c[0,8] == "Progress" || c[0,5] == "Wrote")
61
+ c = c.sub("\n","\n#{client.property.node_topic}: ")
62
+ client.inform(:status, {
63
+ status_type: 'FRISBEE',
64
+ event: "STDOUT",
65
+ app: client.property.app_id,
66
+ node: client.property.node_topic,
67
+ msg: "#{c.to_s}"
68
+ }, :ALL)
69
+ end
70
+ end
71
+
72
+ client.inform(:status, {
73
+ status_type: 'FRISBEE',
74
+ event: "EXIT",
75
+ app: client.property.app_id,
76
+ node: client.property.node_topic,
77
+ msg: 'frisbee client completed.'
78
+ }, :ALL)
79
+ host.close
80
+ end
81
+ end
82
+ end