omf_rc 6.0.2.pre.2 → 6.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/omf_rc +19 -11
- data/config/config.yml +0 -5
- data/config/config_with_authentication.yml.example +1 -1
- data/lib/omf_rc/deferred_process.rb +5 -0
- data/lib/omf_rc/omf_error.rb +5 -0
- data/lib/omf_rc/resource_factory.rb +17 -5
- data/lib/omf_rc/resource_proxy/abstract_resource.rb +186 -85
- data/lib/omf_rc/resource_proxy/application.rb +77 -53
- data/lib/omf_rc/resource_proxy/net.rb +29 -2
- data/lib/omf_rc/resource_proxy/node.rb +53 -2
- data/lib/omf_rc/resource_proxy/virtual_machine.rb +5 -0
- data/lib/omf_rc/resource_proxy/virtual_machine_factory.rb +5 -0
- data/lib/omf_rc/resource_proxy/wlan.rb +41 -2
- data/lib/omf_rc/resource_proxy_dsl.rb +68 -8
- data/lib/omf_rc/util/common_tools.rb +5 -0
- data/lib/omf_rc/util/hostapd.rb +13 -0
- data/lib/omf_rc/util/ip.rb +39 -0
- data/lib/omf_rc/util/iw.rb +115 -39
- data/lib/omf_rc/util/libvirt.rb +5 -0
- data/lib/omf_rc/util/mod.rb +20 -1
- data/lib/omf_rc/util/openflow_tools.rb +5 -0
- data/lib/omf_rc/util/package.rb +5 -0
- data/lib/omf_rc/util/platform_tools.rb +5 -0
- data/lib/omf_rc/util/sysfs.rb +23 -3
- data/lib/omf_rc/util/vmbuilder.rb +5 -0
- data/lib/omf_rc/util/wpa.rb +12 -0
- data/lib/omf_rc/version.rb +6 -1
- data/lib/omf_rc.rb +5 -0
- data/omf_rc.gemspec +2 -1
- data/test/omf_rc/deferred_process_spec.rb +5 -0
- data/test/omf_rc/message_process_error_spec.rb +5 -0
- data/test/omf_rc/resource_factory_spec.rb +8 -6
- data/test/omf_rc/resource_proxy/abstract_resource_spec.rb +151 -89
- data/test/omf_rc/resource_proxy/application_spec.rb +10 -11
- data/test/omf_rc/resource_proxy/node_spec.rb +6 -1
- data/test/omf_rc/resource_proxy_dsl_spec.rb +31 -6
- data/test/omf_rc/util/common_tools_spec.rb +6 -1
- data/test/omf_rc/util/ip_spec.rb +9 -3
- data/test/omf_rc/util/iw_spec.rb +16 -6
- data/test/omf_rc/util/mod_spec.rb +8 -3
- data/test/test_helper.rb +6 -0
- metadata +26 -13
- data/lib/omf_rc/resource_proxy/mock.rb +0 -16
- data/lib/omf_rc/util/mock.rb +0 -22
- data/test/omf_rc/resource_proxy/mock_spec.rb +0 -20
- data/test/omf_rc/util/mock_spec.rb +0 -31
@@ -1,25 +1,8 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
# THE SOFTWARE.
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
21
5
|
|
22
|
-
#
|
23
6
|
# This module defines a Resource Proxy (RP) for an Application.
|
24
7
|
# For a detailed usage tutorial see {file:doc/RESOURCE\_PROXY.mkd Resource Proxy tutorial}
|
25
8
|
#
|
@@ -89,9 +72,13 @@
|
|
89
72
|
#
|
90
73
|
module OmfRc::ResourceProxy::Application
|
91
74
|
include OmfRc::ResourceProxyDSL
|
75
|
+
# @!macro extend_dsl
|
76
|
+
|
92
77
|
require 'omf_common/exec_app'
|
93
78
|
|
94
79
|
register_proxy :application
|
80
|
+
# @!parse include OmfRc::Util::PlatformTools
|
81
|
+
# @!parse include OmfRc::Util::CommonTools
|
95
82
|
utility :platform_tools
|
96
83
|
utility :common_tools
|
97
84
|
|
@@ -119,10 +106,14 @@ module OmfRc::ResourceProxy::Application
|
|
119
106
|
property :oml_logfile, :default => nil
|
120
107
|
property :oml_loglevel, :default => nil
|
121
108
|
|
109
|
+
# @!macro group_hook
|
110
|
+
#
|
122
111
|
# hook :before_ready do |res|
|
123
112
|
# define_method("on_app_event") { |*args| process_event(self, *args) }
|
124
113
|
# end
|
125
114
|
|
115
|
+
# @!macro hook
|
116
|
+
# @!method after_initial_configured
|
126
117
|
hook :after_initial_configured do |res|
|
127
118
|
# if state was set to running or installing from the create we need
|
128
119
|
# to make sure that this happens!
|
@@ -135,55 +126,71 @@ module OmfRc::ResourceProxy::Application
|
|
135
126
|
end
|
136
127
|
end
|
137
128
|
|
129
|
+
# @!endgroup
|
130
|
+
|
138
131
|
# This method processes an event coming from the application instance, which
|
139
132
|
# was started by this Resource Proxy (RP). It is a callback, which is usually
|
140
133
|
# called by the ExecApp class in OMF
|
141
134
|
#
|
142
135
|
# @param [AbstractResource] res this RP
|
143
136
|
# @param [String] event_type the type of event from the app instance
|
144
|
-
# (STARTED,
|
137
|
+
# (STARTED, EXIT, STDOUT, STDERR)
|
145
138
|
# @param [String] app_id the id of the app instance
|
146
139
|
# @param [String] msg the message carried by the event
|
147
|
-
#
|
148
140
|
def process_event(res, event_type, app_id, msg)
|
149
141
|
logger.info "App Event from '#{app_id}' "+
|
150
142
|
"(##{res.property.event_sequence}) - "+
|
151
143
|
"#{event_type}: '#{msg}'"
|
152
|
-
|
144
|
+
res.property.event_sequence += 1
|
145
|
+
res.property.installed = true if app_id.include?("_INSTALL") &&
|
146
|
+
event_type.to_s.include?('EXIT') &&
|
147
|
+
msg == "0"
|
148
|
+
if event_type == 'EXIT'
|
153
149
|
res.property.state = app_id.include?("_INSTALL") ? :stopped : :completed
|
154
150
|
res.inform(:status, {
|
151
|
+
status_type: 'APP_EVENT',
|
152
|
+
event: event_type.to_s.upcase,
|
153
|
+
app: app_id,
|
154
|
+
exit_code: msg,
|
155
|
+
msg: msg,
|
155
156
|
state: res.property.state,
|
156
|
-
|
157
|
+
seq: res.property.event_sequence,
|
158
|
+
uid: res.uid # do we really need this? Should be identical to 'src'
|
157
159
|
}, :ALL)
|
160
|
+
else
|
161
|
+
res.inform(:status, {
|
162
|
+
status_type: 'APP_EVENT',
|
163
|
+
event: event_type.to_s.upcase,
|
164
|
+
app: app_id,
|
165
|
+
msg: msg,
|
166
|
+
seq: res.property.event_sequence,
|
167
|
+
uid: res.uid
|
168
|
+
}, :ALL)
|
158
169
|
end
|
159
|
-
|
160
|
-
res.inform(:status, {
|
161
|
-
status_type: 'APP_EVENT',
|
162
|
-
event: event_type.to_s.upcase,
|
163
|
-
app: app_id,
|
164
|
-
msg: msg,
|
165
|
-
seq: res.property.event_sequence,
|
166
|
-
uid: res.uid
|
167
|
-
}, :ALL)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
res.property.event_sequence += 1
|
172
|
-
res.property.installed = true if app_id.include?("_INSTALL") &&
|
173
|
-
event_type.to_s.include?('DONE.OK')
|
174
170
|
end
|
175
171
|
|
172
|
+
# @!macro group_request
|
173
|
+
#
|
176
174
|
# Request the platform property of this Application RP
|
177
175
|
# @see OmfRc::ResourceProxy::Application
|
178
176
|
#
|
177
|
+
# @!macro request
|
178
|
+
# @!method request_platform
|
179
179
|
request :platform do |res|
|
180
180
|
res.property.platform = detect_platform if res.property.platform.nil?
|
181
181
|
res.property.platform.to_s
|
182
182
|
end
|
183
183
|
|
184
|
+
# @!endgroup
|
185
|
+
# @!macro group_configure
|
186
|
+
|
184
187
|
# Configure the environments and oml property of this Application RP
|
185
188
|
# @see OmfRc::ResourceProxy::Application
|
186
189
|
#
|
190
|
+
#
|
191
|
+
# @!macro configure
|
192
|
+
# @!method conifgure_environments
|
193
|
+
# @!method conifgure_oml
|
187
194
|
%w(environments oml).each do |prop|
|
188
195
|
configure(prop) do |res, value|
|
189
196
|
if value.kind_of? Hash
|
@@ -197,7 +204,10 @@ module OmfRc::ResourceProxy::Application
|
|
197
204
|
end
|
198
205
|
|
199
206
|
# Configure the parameters property of this Application RP
|
207
|
+
#
|
208
|
+
# @!macro configure
|
200
209
|
# @see OmfRc::ResourceProxy::Application
|
210
|
+
# @!method configure_parameters
|
201
211
|
#
|
202
212
|
configure :parameters do |res, params|
|
203
213
|
if params.kind_of? Hash
|
@@ -235,7 +245,7 @@ module OmfRc::ResourceProxy::Application
|
|
235
245
|
# stopped, running, paused, installing. The semantic of each states are:
|
236
246
|
#
|
237
247
|
# - stopped: the initial state for an Application RP
|
238
|
-
# - completed: the final state for an
|
248
|
+
# - completed: the final state for an application RP. When the application
|
239
249
|
# has been executed and its execution is finished, it enters this state.
|
240
250
|
# When the application is completed it cannot change state again
|
241
251
|
# TODO: maybe in future OMF, we could consider allowing an app to be reset?
|
@@ -257,8 +267,9 @@ module OmfRc::ResourceProxy::Application
|
|
257
267
|
# only when the installatio is done. Supported install methods are: Tarball,
|
258
268
|
# Ubuntu, and Fedora
|
259
269
|
#
|
260
|
-
# @
|
261
|
-
#
|
270
|
+
# @param [String] value the state to set this app into
|
271
|
+
# @!macro configure
|
272
|
+
# @!method configure_state
|
262
273
|
configure :state do |res, value|
|
263
274
|
OmfCommon.eventloop.after(0) do
|
264
275
|
case value.to_s.downcase.to_sym
|
@@ -273,9 +284,14 @@ module OmfRc::ResourceProxy::Application
|
|
273
284
|
res.property.state
|
274
285
|
end
|
275
286
|
|
287
|
+
# @!endgroup
|
288
|
+
|
289
|
+
# @!macro group_work
|
290
|
+
#
|
276
291
|
# Swich this Application RP into the 'installing' state
|
277
292
|
# (see the description of configure :state)
|
278
|
-
#
|
293
|
+
# @!macro work
|
294
|
+
# @!method switch_to_installing
|
279
295
|
work('switch_to_installing') do |res|
|
280
296
|
if res.property.state.to_sym == :stopped
|
281
297
|
if res.property.installed
|
@@ -301,9 +317,11 @@ module OmfRc::ResourceProxy::Application
|
|
301
317
|
end
|
302
318
|
end
|
303
319
|
|
304
|
-
#
|
320
|
+
# Switch this Application RP into the 'stopped' state
|
305
321
|
# (see the description of configure :state)
|
306
322
|
#
|
323
|
+
# @!macro work
|
324
|
+
# @!method switch_to_stopped
|
307
325
|
work('switch_to_stopped') do |res|
|
308
326
|
if res.property.state == :running || res.property.state == :paused
|
309
327
|
id = res.property.app_id
|
@@ -332,6 +350,8 @@ module OmfRc::ResourceProxy::Application
|
|
332
350
|
# Switch this Application RP into the 'running' state
|
333
351
|
# (see the description of configure :state)
|
334
352
|
#
|
353
|
+
# @!macro work
|
354
|
+
# @!method switch_to_running
|
335
355
|
work('switch_to_running') do |res|
|
336
356
|
if res.property.state == :stopped
|
337
357
|
# start a new instance of this app
|
@@ -360,6 +380,8 @@ module OmfRc::ResourceProxy::Application
|
|
360
380
|
# Swich this Application RP into the 'paused' state
|
361
381
|
# (see the description of configure :state)
|
362
382
|
#
|
383
|
+
# @!macro work
|
384
|
+
# @!method switch_to_paused
|
363
385
|
work('switch_to_paused') do |res|
|
364
386
|
if res.property.state == :running
|
365
387
|
# pause this app
|
@@ -375,6 +397,8 @@ module OmfRc::ResourceProxy::Application
|
|
375
397
|
# @yieldparam [Hash] att the Hash holding the parameter's attributs
|
376
398
|
# @see OmfRc::ResourceProxy::Application
|
377
399
|
#
|
400
|
+
# @!macro work
|
401
|
+
# @!method dynamic_parameter_update
|
378
402
|
work('dynamic_parameter_update') do |res,name,att|
|
379
403
|
# Only update a parameter if it is dynamic and the application is running
|
380
404
|
dynamic = false
|
@@ -399,10 +423,10 @@ module OmfRc::ResourceProxy::Application
|
|
399
423
|
# - third if no value is given but a default is given, then perform the same
|
400
424
|
# check as above but using the default in-place of the value
|
401
425
|
#
|
402
|
-
# @
|
403
|
-
#
|
404
|
-
# [Boolean] true or false
|
426
|
+
# @param [Hash] att the Hash holding the parameter's attributs
|
405
427
|
#
|
428
|
+
# @return [Boolean] true or false
|
429
|
+
# @!macro work
|
406
430
|
work('pass_type_checking?') do |res,att|
|
407
431
|
passed = false
|
408
432
|
unless att[:type].nil?
|
@@ -444,8 +468,8 @@ module OmfRc::ResourceProxy::Application
|
|
444
468
|
# this Application Resource Proxy. If the 'use_oml' property is set, then
|
445
469
|
# add to the command line the necessary oml parameters.
|
446
470
|
#
|
447
|
-
# [String] the full command line
|
448
|
-
#
|
471
|
+
# @return [String] the full command line
|
472
|
+
# @!macro work
|
449
473
|
work('build_command_line') do |res|
|
450
474
|
cmd_line = "env -i " # Start with a 'clean' environments
|
451
475
|
res.property.environments.each do |e,v|
|
@@ -509,10 +533,10 @@ module OmfRc::ResourceProxy::Application
|
|
509
533
|
# the corresponsding 'oml_logfile' and 'oml_loglevel' properties are set for
|
510
534
|
# this application resource.
|
511
535
|
#
|
512
|
-
# @
|
513
|
-
#
|
514
|
-
# [String] the resulting command line
|
536
|
+
# @param [String] cmd the String to which OML parameters will be added
|
515
537
|
#
|
538
|
+
# @return [String] the resulting command line
|
539
|
+
# @!macro work
|
516
540
|
work('build_oml_config') do |res, cmd|
|
517
541
|
if !res.property.oml_configfile.nil?
|
518
542
|
if File.exist?(res.property.oml_configfile)
|
@@ -1,8 +1,35 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
6
|
+
# Proxy for managing Ethernet interfaces
|
7
|
+
#
|
8
|
+
# Net resources can be created as children of {OmfRc::ResourceProxy::Node}.
|
9
|
+
#
|
10
|
+
# It is important to set if_name (interface_name) as they are used as identifier for executing ip commands.
|
11
|
+
#
|
12
|
+
# @example Bring up an Ethernet interface eth0 by setting an ip address
|
13
|
+
# eth0 = node.create(:wlan, if_name: 'eth0')
|
14
|
+
# eth0.conifgure_ip_addr("192.168.1.100/24")
|
15
|
+
#
|
16
|
+
# @see OmfRc::Util::Ip
|
1
17
|
module OmfRc::ResourceProxy::Net
|
2
18
|
include OmfRc::ResourceProxyDSL
|
3
|
-
|
19
|
+
# @!macro extend_dsl
|
20
|
+
|
4
21
|
register_proxy :net
|
5
|
-
|
22
|
+
|
23
|
+
# @!parse include OmfRc::Util::Ip
|
24
|
+
# @!parse include OmfRc::Util::Sysfs
|
6
25
|
utility :ip
|
7
26
|
utility :sysfs
|
27
|
+
|
28
|
+
# @!macro group_prop
|
29
|
+
#
|
30
|
+
# @!attribute [rw] if_name
|
31
|
+
# Interface name, default is 'eth0'.
|
32
|
+
# @!macro prop
|
33
|
+
property :if_name, :default => "eth0"
|
34
|
+
# @!endgroup
|
8
35
|
end
|
@@ -1,30 +1,81 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
6
|
+
# This proxy represents physical/virtual machine node, and it is the proxy which standard RC start up script initialised.
|
7
|
+
#
|
8
|
+
# Node proxy is more like a monitor proxy which monitors resource information on the node itself, it is usually created during the bootstrap process and provides an entry point for incoming FRCP messages.
|
9
|
+
#
|
10
|
+
# Resources like application, net, or wlan can be created as children of node resources by sending FRCP create messages to the node's pubsub topic.
|
11
|
+
#
|
12
|
+
# @example Creating an ethernet resource on an existing node 'node01' using communicator
|
13
|
+
# comm.subscribe('node01') do |node|
|
14
|
+
# node.create(:net, if_name: 'eth0')
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# @example Creating an ethernet resource on an existing node 'node01' directly
|
18
|
+
# node = OmfRc::ResourceFactory.create(:node)
|
19
|
+
# node.create(:net, if_name: 'eth0')
|
20
|
+
#
|
21
|
+
# @see OmfRc::ResourceProxy::Application
|
22
|
+
# @see OmfRc::ResourceProxy::Net
|
23
|
+
# @see OmfRc::ResourceProxy::Wlan
|
1
24
|
module OmfRc::ResourceProxy::Node
|
2
25
|
include OmfRc::ResourceProxyDSL
|
26
|
+
# @!macro extend_dsl
|
3
27
|
|
4
28
|
register_proxy :node
|
5
29
|
|
30
|
+
# @!parse include OmfRc::Util::Mod
|
31
|
+
# @!parse include OmfRc::Util::Sysfs
|
6
32
|
utility :mod
|
7
33
|
utility :sysfs
|
8
34
|
|
35
|
+
# @!macro group_request
|
36
|
+
#
|
37
|
+
# Created interfaces
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# [{ name: 'eth0', type: 'net', uid: 'RWED2123' }]
|
41
|
+
# @return [Array<Hash>]
|
42
|
+
# @!macro request
|
43
|
+
# @!method request_interface
|
9
44
|
request :interfaces do |node|
|
10
45
|
node.children.find_all { |v| v.type == :net || v.type == :wlan }.map do |v|
|
11
46
|
{ name: v.property.if_name, type: v.type, uid: v.uid }
|
12
47
|
end.sort { |x, y| x[:name] <=> y[:name] }
|
13
48
|
end
|
14
49
|
|
50
|
+
# Created applications
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# [{ name: 'my_app', type: 'application', uid: 'E232ER1' }]
|
54
|
+
# @return [Array<Hash>]
|
55
|
+
# @!macro request
|
56
|
+
# @!method request_applications
|
15
57
|
request :applications do |node|
|
16
58
|
node.children.find_all { |v| v.type =~ /application/ }.map do |v|
|
17
59
|
{ name: v.hrn, type: v.type, uid: v.uid }
|
18
60
|
end.sort { |x, y| x[:name] <=> y[:name] }
|
19
61
|
end
|
20
62
|
|
63
|
+
# @!endgroup
|
64
|
+
|
65
|
+
# @!macro group_hook
|
66
|
+
#
|
67
|
+
# Check if device exists
|
68
|
+
#
|
69
|
+
# @raise [StandardError] if device not found on the node
|
70
|
+
#
|
71
|
+
# @!method before_create
|
21
72
|
hook :before_create do |node, type, opts|
|
22
73
|
if type.to_sym == :net
|
23
74
|
net_dev = node.request_devices.find do |v|
|
24
75
|
v[:name] == opts[:if_name]
|
25
76
|
end
|
26
|
-
raise "Device '#{opts[:if_name]}' not found" if net_dev.nil?
|
77
|
+
raise StandardError, "Device '#{opts[:if_name]}' not found" if net_dev.nil?
|
27
78
|
end
|
28
79
|
end
|
29
|
-
|
80
|
+
# @!endgroup
|
30
81
|
end
|
@@ -1,3 +1,8 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
1
6
|
#
|
2
7
|
# Copyright (c) 2012 National ICT Australia (NICTA), Australia
|
3
8
|
#
|
@@ -1,3 +1,8 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
1
6
|
#
|
2
7
|
# Copyright (c) 2012 National ICT Australia (NICTA), Australia
|
3
8
|
#
|
@@ -1,15 +1,53 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
6
|
+
# Proxy module for managing wifi devices
|
7
|
+
#
|
8
|
+
# Wlan resources can be created as children of {OmfRc::ResourceProxy::Node}.
|
9
|
+
#
|
10
|
+
# It is important to set if_name (interface_name) and phy (physical device name) as they are used as identifier for executing iw and ip commands.
|
11
|
+
#
|
12
|
+
# @example Set up a wifi interface wlan0 as managed mode
|
13
|
+
# wlan0 = node.create(:wlan, if_name: 'wlan0', phy: 'phy0')
|
14
|
+
# wlan0.configure_mode(mode: :master, hw_mode: 'g', channel: 1, essid: 'bob')
|
15
|
+
#
|
16
|
+
# @example Configure IP address of interface wlan0
|
17
|
+
# wlan0.conifgure_ip_addr("192.168.1.100/24")
|
18
|
+
#
|
19
|
+
# @see OmfRc::Util::Iw
|
1
20
|
module OmfRc::ResourceProxy::Wlan
|
2
21
|
include OmfRc::ResourceProxyDSL
|
22
|
+
# @!macro extend_dsl
|
3
23
|
|
4
24
|
register_proxy :wlan
|
5
25
|
|
6
|
-
|
7
|
-
|
26
|
+
# @!parse include OmfRc::Util::Iw
|
27
|
+
# @!parse include OmfRc::Util::Mod
|
28
|
+
# @!parse include OmfRc::Util::Sysfs
|
8
29
|
utility :iw
|
30
|
+
utility :mod
|
9
31
|
utility :sysfs
|
10
32
|
|
33
|
+
# @!macro group_prop
|
34
|
+
#
|
35
|
+
# @!attribute [rw] if_name
|
36
|
+
# Interface name, default is 'wlan0'
|
37
|
+
# @!macro prop
|
11
38
|
property :if_name, :default => "wlan0"
|
39
|
+
# @!attribute [rw] phy
|
40
|
+
# Device's physical name
|
41
|
+
# @!macro prop
|
42
|
+
property :phy
|
43
|
+
|
44
|
+
# @!endgroup
|
12
45
|
|
46
|
+
# @!macro group_hook
|
47
|
+
#
|
48
|
+
# Stop hostapd or wpa instances before releasing wifi device
|
49
|
+
# @!macro hook
|
50
|
+
# @!method before_release
|
13
51
|
hook :before_release do |device|
|
14
52
|
case device.property.mode.to_sym
|
15
53
|
when :master
|
@@ -20,4 +58,5 @@ module OmfRc::ResourceProxy::Wlan
|
|
20
58
|
#TODO need to remove all virtual interfaces of that phy device
|
21
59
|
#device.remove_all_interfaces
|
22
60
|
end
|
61
|
+
# @!endgroup
|
23
62
|
end
|
@@ -1,11 +1,30 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
1
6
|
# DSL contains some helper methods to ease the process defining resource proxies
|
2
7
|
#
|
8
|
+
# DSL methods are defined under {OmfRc::ResourceProxyDSL::ClassMethods}
|
3
9
|
module OmfRc::ResourceProxyDSL
|
10
|
+
# Default directory contains proxy definition files
|
4
11
|
PROXY_DIR = "omf_rc/resource_proxy"
|
12
|
+
# Default directory contains utility definition files
|
5
13
|
UTIL_DIR = "omf_rc/util"
|
6
14
|
|
7
|
-
|
15
|
+
# Default property access rights through FRCP
|
16
|
+
DEFAULT_PROP_ACCESS = [:configure, :request]
|
17
|
+
|
18
|
+
# Calling a hook within a given resource context
|
19
|
+
#
|
20
|
+
# @param [Symbol] hook_name
|
21
|
+
# @param [Symbol] context in which resource this hook will be called
|
22
|
+
def call_hook(hook_name, context, *params)
|
23
|
+
context.send(hook_name, *params) if context.respond_to? hook_name
|
24
|
+
end
|
8
25
|
|
26
|
+
# When this module included, methods defined under ClassMethods will be available in resource definition files
|
27
|
+
#
|
9
28
|
def self.included(base)
|
10
29
|
base.extend(ClassMethods)
|
11
30
|
end
|
@@ -123,6 +142,11 @@ module OmfRc::ResourceProxyDSL
|
|
123
142
|
end
|
124
143
|
end
|
125
144
|
|
145
|
+
# @see ResourceProxyDSL#call_hook
|
146
|
+
def call_hook(hook_name, context, *params)
|
147
|
+
context.send(hook_name, *params) if context.respond_to? hook_name
|
148
|
+
end
|
149
|
+
|
126
150
|
# Include the utility by providing a name
|
127
151
|
#
|
128
152
|
# The utility file can be added to the default utility directory UTIL_DIR, or defined inline.
|
@@ -136,6 +160,7 @@ module OmfRc::ResourceProxyDSL
|
|
136
160
|
# # Simply include this util module
|
137
161
|
# utility :iw
|
138
162
|
# end
|
163
|
+
#
|
139
164
|
def utility(name)
|
140
165
|
name = name.to_s
|
141
166
|
begin
|
@@ -188,7 +213,6 @@ module OmfRc::ResourceProxyDSL
|
|
188
213
|
# end
|
189
214
|
# end
|
190
215
|
# end
|
191
|
-
#
|
192
216
|
def configure(name, ®ister_block)
|
193
217
|
define_method("configure_#{name.to_s}") do |*args, &block|
|
194
218
|
args[0] = Hashie::Mash.new(args[0]) if args[0].class == Hash
|
@@ -215,6 +239,7 @@ module OmfRc::ResourceProxyDSL
|
|
215
239
|
# end
|
216
240
|
# end
|
217
241
|
# end
|
242
|
+
#
|
218
243
|
def request(name, ®ister_block)
|
219
244
|
define_method("request_#{name.to_s}") do |*args, &block|
|
220
245
|
args[0] = Hashie::Mash.new(args[0]) if args[0].class == Hash
|
@@ -321,29 +346,64 @@ module OmfRc::ResourceProxyDSL
|
|
321
346
|
alias_method "orig_request_#{request_name}", "request_#{request_name}"
|
322
347
|
end
|
323
348
|
|
324
|
-
# Define internal property
|
349
|
+
# Define internal property. Refer to options section to see supported options.
|
350
|
+
#
|
351
|
+
# @param [Symbol] name of the property
|
352
|
+
#
|
353
|
+
# @option opts [Object] :default default value of the property
|
354
|
+
# @option opts [Array<Symbol>, Symbol] :access defines access to the property
|
355
|
+
# it could be defined as an array, listing access rights, which by default is [:configure, :request]
|
356
|
+
# or it could be defined as one of the predefined symbols :configure, :read_only, or :init_only
|
357
|
+
#
|
358
|
+
# @example
|
359
|
+
# # Read-only property, i.e. could not be modified through FRCP protocol
|
360
|
+
# property :bob, default: 1, access: :configure
|
361
|
+
#
|
362
|
+
# # Read & Write property, i.e. could be modified through FRCP protocol
|
363
|
+
# property :bob, default: 1, access: :read_only
|
364
|
+
#
|
365
|
+
# # Read & could be modified ONLY through FRCP CREATE message
|
366
|
+
# property :bob, default: 1, access: :init_only
|
325
367
|
def property(name, opts = {})
|
326
368
|
opts = Hashie::Mash.new(opts)
|
327
369
|
|
328
|
-
define_method("
|
370
|
+
define_method("default_property_#{name}") do |*args, &block|
|
329
371
|
self.property[name] ||= opts[:default]
|
330
372
|
end
|
331
373
|
|
332
|
-
|
374
|
+
if opts.access.instance_of? Array
|
375
|
+
access = opts.access
|
376
|
+
elsif opts.access.instance_of? Symbol
|
377
|
+
access = case opts.access
|
378
|
+
when :configure
|
379
|
+
[:configure, :request]
|
380
|
+
when :init_only
|
381
|
+
[:init, :request]
|
382
|
+
when :read_only
|
383
|
+
[:request]
|
384
|
+
else
|
385
|
+
raise ArgumentError, "Unknown property access mode '#{opts.access}'"
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
access ||= DEFAULT_PROP_ACCESS
|
390
|
+
|
333
391
|
access.each do |a|
|
334
392
|
case a
|
335
393
|
when :configure
|
336
394
|
define_method("configure_#{name}") do |val|
|
337
395
|
self.property[name] = val
|
338
396
|
end
|
339
|
-
|
397
|
+
when :init
|
398
|
+
define_method("initialise_#{name}") do |val|
|
399
|
+
self.property[name] = val
|
400
|
+
end
|
340
401
|
when :request
|
341
402
|
define_method("request_#{name}") do
|
342
403
|
self.property[name]
|
343
404
|
end
|
344
|
-
|
345
405
|
else
|
346
|
-
raise "Unnown access type '#{a}'"
|
406
|
+
raise ArgumentError, "Unnown access type '#{a}'"
|
347
407
|
end
|
348
408
|
end
|
349
409
|
end
|
@@ -1,3 +1,8 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
1
6
|
#
|
2
7
|
# Copyright (c) 2012 National ICT Australia (NICTA), Australia
|
3
8
|
#
|
data/lib/omf_rc/util/hostapd.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
|
+
# Copyright (c) 2012 National ICT Australia Limited (NICTA).
|
2
|
+
# This software may be used and distributed solely under the terms of the MIT license (License).
|
3
|
+
# You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
|
4
|
+
# By downloading or using this software you accept the terms and the liability disclaimer in the License.
|
5
|
+
|
1
6
|
require 'hashie'
|
2
7
|
require 'cocaine'
|
3
8
|
require 'tempfile'
|
4
9
|
|
10
|
+
# Manage Hostapd instances
|
5
11
|
module OmfRc::Util::Hostapd
|
6
12
|
include OmfRc::ResourceProxyDSL
|
7
13
|
include Cocaine
|
14
|
+
# @!macro extend_dsl
|
8
15
|
|
16
|
+
# @!macro group_work
|
9
17
|
# Initialise access point conf and pid location
|
10
18
|
#
|
19
|
+
# @!method init_ap_conf_pid
|
11
20
|
work :init_ap_conf_pid do |device|
|
12
21
|
device.property.ap_conf = Tempfile.new(["hostapd.#{device.property.if_name}", ".conf"]).path
|
13
22
|
device.property.ap_pid = Tempfile.new(["hostapd.#{device.property.if_name}", ".pid"]).path
|
14
23
|
end
|
24
|
+
|
15
25
|
# Set up and run a hostapd instance
|
16
26
|
#
|
27
|
+
# @!method hostapd
|
17
28
|
work :hostapd do |device|
|
18
29
|
device.init_ap_conf_pid
|
19
30
|
|
@@ -35,6 +46,7 @@ module OmfRc::Util::Hostapd
|
|
35
46
|
:ap_conf => device.property.ap_conf).run
|
36
47
|
end
|
37
48
|
|
49
|
+
# @!method stop_hostapd
|
38
50
|
work :stop_hostapd do |device|
|
39
51
|
begin
|
40
52
|
File.open(device.property.ap_pid,'r') do |f|
|
@@ -50,4 +62,5 @@ module OmfRc::Util::Hostapd
|
|
50
62
|
logger.warn e.message
|
51
63
|
end
|
52
64
|
end
|
65
|
+
# @!endgroup
|
53
66
|
end
|