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.
Files changed (46) hide show
  1. data/bin/omf_rc +19 -11
  2. data/config/config.yml +0 -5
  3. data/config/config_with_authentication.yml.example +1 -1
  4. data/lib/omf_rc/deferred_process.rb +5 -0
  5. data/lib/omf_rc/omf_error.rb +5 -0
  6. data/lib/omf_rc/resource_factory.rb +17 -5
  7. data/lib/omf_rc/resource_proxy/abstract_resource.rb +186 -85
  8. data/lib/omf_rc/resource_proxy/application.rb +77 -53
  9. data/lib/omf_rc/resource_proxy/net.rb +29 -2
  10. data/lib/omf_rc/resource_proxy/node.rb +53 -2
  11. data/lib/omf_rc/resource_proxy/virtual_machine.rb +5 -0
  12. data/lib/omf_rc/resource_proxy/virtual_machine_factory.rb +5 -0
  13. data/lib/omf_rc/resource_proxy/wlan.rb +41 -2
  14. data/lib/omf_rc/resource_proxy_dsl.rb +68 -8
  15. data/lib/omf_rc/util/common_tools.rb +5 -0
  16. data/lib/omf_rc/util/hostapd.rb +13 -0
  17. data/lib/omf_rc/util/ip.rb +39 -0
  18. data/lib/omf_rc/util/iw.rb +115 -39
  19. data/lib/omf_rc/util/libvirt.rb +5 -0
  20. data/lib/omf_rc/util/mod.rb +20 -1
  21. data/lib/omf_rc/util/openflow_tools.rb +5 -0
  22. data/lib/omf_rc/util/package.rb +5 -0
  23. data/lib/omf_rc/util/platform_tools.rb +5 -0
  24. data/lib/omf_rc/util/sysfs.rb +23 -3
  25. data/lib/omf_rc/util/vmbuilder.rb +5 -0
  26. data/lib/omf_rc/util/wpa.rb +12 -0
  27. data/lib/omf_rc/version.rb +6 -1
  28. data/lib/omf_rc.rb +5 -0
  29. data/omf_rc.gemspec +2 -1
  30. data/test/omf_rc/deferred_process_spec.rb +5 -0
  31. data/test/omf_rc/message_process_error_spec.rb +5 -0
  32. data/test/omf_rc/resource_factory_spec.rb +8 -6
  33. data/test/omf_rc/resource_proxy/abstract_resource_spec.rb +151 -89
  34. data/test/omf_rc/resource_proxy/application_spec.rb +10 -11
  35. data/test/omf_rc/resource_proxy/node_spec.rb +6 -1
  36. data/test/omf_rc/resource_proxy_dsl_spec.rb +31 -6
  37. data/test/omf_rc/util/common_tools_spec.rb +6 -1
  38. data/test/omf_rc/util/ip_spec.rb +9 -3
  39. data/test/omf_rc/util/iw_spec.rb +16 -6
  40. data/test/omf_rc/util/mod_spec.rb +8 -3
  41. data/test/test_helper.rb +6 -0
  42. metadata +26 -13
  43. data/lib/omf_rc/resource_proxy/mock.rb +0 -16
  44. data/lib/omf_rc/util/mock.rb +0 -22
  45. data/test/omf_rc/resource_proxy/mock_spec.rb +0 -20
  46. data/test/omf_rc/util/mock_spec.rb +0 -31
@@ -1,4 +1,8 @@
1
- #require 'omf_rc/deferred_process'
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
+
2
6
  require 'omf_rc/omf_error'
3
7
  require 'securerandom'
4
8
  require 'hashie'
@@ -24,11 +28,49 @@ class OmfRc::ResourceProxy::MPReceived < OML4R::MPBase
24
28
  param :mid, :type => :string # Unique ID this message
25
29
  end
26
30
 
31
+ # @note Suppose you have read the {file:doc/DEVELOPERS.mkd DEVELOPERS GUIDE} which explains the basic the resource controller system.
32
+ #
33
+ # This is the abstract resource proxy class, which provides the base of all proxy implementations. When creating new resource instances, this abstract class will always be initialised first and then extended by one of the specific resource proxy modules.
34
+ #
35
+ # Instead of initialise abstract resource directly, use {OmfRc::ResourceFactory Resource Factory}'s methods.
36
+ #
37
+ # @example Creating resource using factory method
38
+ # OmfRc::ResourceFactory.create(:node, uid: 'node01')
39
+ #
40
+ # Proxy documentation has grouped FRCP API methods for your convenience.
41
+ #
42
+ # We follow a simple naming convention for request/configure properties.
43
+ #
44
+ # request_xxx() indicates property 'xxx' can be requested using FRCP REQUEST message.
45
+ #
46
+ # configure_xxx(value) indicates property 'xxx' can be configured with 'value' using FRCP CONFIGURE message.
47
+ #
48
+ # Currently official OMF RC gem contains following resource proxies:
49
+ #
50
+ # Representing physical/virtual machine
51
+ # * {OmfRc::ResourceProxy::Node Node}
52
+ #
53
+ # Executing OML enabled application and monitor output
54
+ # * {OmfRc::ResourceProxy::Application Application}
55
+ #
56
+ # Configuring network interfaces
57
+ # * {OmfRc::ResourceProxy::Net Net}
58
+ # * {OmfRc::ResourceProxy::Wlan Wlan}
59
+ #
60
+ # Installing packages
61
+ # * {OmfRc::ResourceProxy::Package Package}
62
+ #
63
+ # Creating virtual machines
64
+ # * {OmfRc::ResourceProxy::VirtualMachineFactory VirtualMachineFactory}
65
+ # * {OmfRc::ResourceProxy::VirtualMachine VirtualMachine}
66
+ #
67
+ # @see OmfRc::ResourceFactory
68
+ # @see OmfRc::ResourceProxyDSL
69
+ #
27
70
  class OmfRc::ResourceProxy::AbstractResource
28
71
  include MonitorMixin
72
+ include OmfRc::ResourceProxyDSL
29
73
 
30
- # Time to wait before shutting down event loop, wait for deleting pubsub topics
31
- DISCONNECT_WAIT = 5
32
74
  # Time to wait before releasing resource, wait for deleting pubsub topics
33
75
  RELEASE_WAIT = 5
34
76
 
@@ -37,8 +79,6 @@ class OmfRc::ResourceProxy::AbstractResource
37
79
  create_children_resources: true
38
80
  }
39
81
 
40
- # @!attribute property
41
- # @return [String] the resource's internal meta data storage
42
82
  attr_accessor :uid, :hrn, :type, :comm, :property, :certificate
43
83
  attr_reader :opts, :children, :membership, :creation_opts, :membership_topics
44
84
 
@@ -58,6 +98,8 @@ class OmfRc::ResourceProxy::AbstractResource
58
98
  # @option creation_opts [Boolean] :create_children_resources Immediately create 'known' children resources, such as interfaces on nodes
59
99
  #
60
100
  def initialize(type, opts = {}, creation_opts = {}, &creation_callback)
101
+ super()
102
+
61
103
  @opts = Hashie::Mash.new(opts)
62
104
  @creation_opts = Hashie::Mash.new(DEFAULT_CREATION_OPTS.merge(creation_opts))
63
105
 
@@ -66,12 +108,11 @@ class OmfRc::ResourceProxy::AbstractResource
66
108
  @hrn = @opts.hrn && @opts.hrn.to_s
67
109
 
68
110
  @children ||= []
69
- @membership ||= []
111
+ @membership = []
70
112
  @topics = []
71
113
  @membership_topics ||= {}
72
114
 
73
- @property = @opts.property || Hashie::Mash.new
74
- @property.merge!(@opts.except([:uid, :hrn, :property, :instrument]))
115
+ @property = Hashie::Mash.new(@opts.property)
75
116
 
76
117
  OmfCommon.comm.subscribe(@uid) do |t|
77
118
  @topics << t
@@ -98,26 +139,30 @@ class OmfRc::ResourceProxy::AbstractResource
98
139
 
99
140
  t.inform(:creation_ok, cprops, copts)
100
141
 
101
- t.on_message(nil, @uid) do |imsg|
142
+ t.on_message(@uid) do |imsg|
102
143
  process_omf_message(imsg, t)
103
144
  end
104
145
  end
105
146
  end
106
-
107
- super()
147
+ configure_membership(@opts.membership) if @opts.membership
108
148
  end
109
149
 
110
- # Return the public 'routable' address for this resource
150
+ # Return the public 'routable' address for this resource or nil if not known yet.
111
151
  #
112
152
  def resource_address()
113
- @topics[0].address
153
+ if t = @topics[0]
154
+ t.address
155
+ else
156
+ nil # TODO: should we raise Excaption
157
+ end
114
158
  end
115
159
 
160
+ # Get binding of current object, used for ERB eval
116
161
  def get_binding
117
162
  binding
118
163
  end
119
164
 
120
- # Try to clean up pubsub topics, and wait for DISCONNECT_WAIT seconds, then shutdown event machine loop
165
+ # Disconnect using communicator
121
166
  def disconnect
122
167
  OmfCommon.comm.disconnect
123
168
  end
@@ -125,6 +170,7 @@ class OmfRc::ResourceProxy::AbstractResource
125
170
  # Create a new resource in the context of this resource. This resource becomes parent, and newly created resource becomes child
126
171
  #
127
172
  # @param (see #initialize)
173
+ # @return [AbstractResource] new resource has been created
128
174
  def create(type, opts = {}, creation_opts = {}, &creation_callback)
129
175
  unless request_supported_children_type.include?(type.to_sym)
130
176
  raise StandardError, "Resource #{type} is not designed to be created by #{self.type}"
@@ -132,9 +178,15 @@ class OmfRc::ResourceProxy::AbstractResource
132
178
 
133
179
  opts[:parent_certificate] = @certificate if @certificate
134
180
  opts[:parent] = self
135
- before_create(type, opts) if respond_to? :before_create
181
+
182
+ call_hook(:before_create, self, type, opts)
183
+
136
184
  new_resource = OmfRc::ResourceFactory.create(type.to_sym, opts, creation_opts, &creation_callback)
137
- after_create(new_resource) if respond_to? :after_create
185
+
186
+ new_props = opts.reject { |k| [:type, :name, :uid, :hrn, :property, :instrument].include?(k.to_sym) }
187
+ init_configure(new_resource, new_props)
188
+
189
+ call_hook(:after_create, self, new_resource)
138
190
 
139
191
  self.synchronize do
140
192
  children << new_resource
@@ -144,8 +196,7 @@ class OmfRc::ResourceProxy::AbstractResource
144
196
 
145
197
  # Release a child resource
146
198
  #
147
- # @return [AbstractResource] Relsead child or nil if error
148
- #
199
+ # @return [AbstractResource] Released child or nil if error
149
200
  def release(res_id)
150
201
  if (child = children.find { |v| v.uid.to_s == res_id.to_s })
151
202
  if child.release_self()
@@ -165,8 +216,7 @@ class OmfRc::ResourceProxy::AbstractResource
165
216
 
166
217
  # Release this resource. Should ONLY be called by parent resource.
167
218
  #
168
- # Return true if successful
169
- #
219
+ # @return [Boolean] true if successful
170
220
  def release_self
171
221
  # Release children resource recursively
172
222
  children.each do |c|
@@ -180,7 +230,9 @@ class OmfRc::ResourceProxy::AbstractResource
180
230
  return false unless children.empty?
181
231
 
182
232
  info "Releasing hrn: #{hrn}, uid: #{uid}"
183
- self.before_release if self.respond_to? :before_release
233
+
234
+ call_hook(:before_release, self)
235
+
184
236
  props = {
185
237
  res_id: resource_address
186
238
  }
@@ -189,19 +241,24 @@ class OmfRc::ResourceProxy::AbstractResource
189
241
 
190
242
  # clean up topics
191
243
  @topics.each do |t|
192
- t.unsubscribe
244
+ t.unsubscribe(@uid)
193
245
  end
194
246
 
195
247
  @membership_topics.each_value do |t|
196
248
  if t.respond_to? :delete_on_message_cbk_by_id
197
249
  t.delete_on_message_cbk_by_id(@uid)
198
250
  end
199
- t.unsubscribe
251
+ t.unsubscribe(@uid)
200
252
  end
201
253
 
202
254
  true
203
255
  end
204
256
 
257
+ # @!macro group_request
258
+ #
259
+ # Return a list of child resources this resource can create
260
+ #
261
+ # @return [Array<Symbol>]
205
262
  def request_supported_children_type(*args)
206
263
  OmfRc::ResourceFactory.proxy_list.reject { |v| v == @type.to_s }.find_all do |k, v|
207
264
  (v.create_by && v.create_by.include?(@type.to_sym)) || v.create_by.nil?
@@ -210,6 +267,10 @@ class OmfRc::ResourceProxy::AbstractResource
210
267
 
211
268
  # Return a list of all properties can be requested and configured
212
269
  #
270
+ # @example
271
+ # { request: [:ip_addr, :frequency], configure: [:ip_address] }
272
+ #
273
+ # @return [Hashie::Mash]
213
274
  def request_available_properties(*args)
214
275
  Hashie::Mash.new(request: [], configure: []).tap do |mash|
215
276
  methods.each do |m|
@@ -223,14 +284,11 @@ class OmfRc::ResourceProxy::AbstractResource
223
284
  uid
224
285
  end
225
286
 
287
+ # Make type accessible through pubsub interface
226
288
  def request_type(*args)
227
289
  type
228
290
  end
229
291
 
230
- def configure_type(*args)
231
- @type = type
232
- end
233
-
234
292
  # Make hrn accessible through pubsub interface
235
293
  def request_hrn(*args)
236
294
  hrn
@@ -238,22 +296,28 @@ class OmfRc::ResourceProxy::AbstractResource
238
296
 
239
297
  alias_method :request_name, :request_hrn
240
298
  alias_method :name, :hrn
299
+ alias_method :name=, :hrn=
241
300
 
242
- # Make hrn configurable through pubsub interface
243
- def configure_hrn(hrn)
244
- self.synchronize do
245
- @hrn = hrn
246
- end
247
- @hrn
301
+ # Query resource's membership
302
+ def request_membership(*args)
303
+ @membership
248
304
  end
249
305
 
250
- alias_method :configure_name, :configure_hrn
251
- alias_method :name=, :hrn=
306
+ # Request child resources
307
+ #
308
+ # @return [Hashie::Mash] child resource mash with uid and hrn
309
+ def request_child_resources(*args)
310
+ #children.map { |c| Hashie::Mash.new({ uid: c.uid, name: c.hrn }) }
311
+ children.map { |c| c.to_hash }
312
+ end
313
+
314
+ # @!endgroup
315
+ #
316
+ # @!macro group_configure
252
317
 
253
318
  # Make resource part of the group topic, it will overwrite existing membership array
254
319
  #
255
- # @param [String] name of group topic
256
- # @param [Array] name of group topics
320
+ # @param [String|Array] args name of group topic/topics
257
321
  def configure_membership(*args)
258
322
  new_membership = [args[0]].flatten
259
323
 
@@ -272,7 +336,7 @@ class OmfRc::ResourceProxy::AbstractResource
272
336
  self.inform(:status, { membership: @membership }, t)
273
337
  end
274
338
 
275
- t.on_message(nil, @uid) do |imsg|
339
+ t.on_message(@uid) do |imsg|
276
340
  process_omf_message(imsg, t)
277
341
  end
278
342
  end
@@ -282,22 +346,12 @@ class OmfRc::ResourceProxy::AbstractResource
282
346
  @membership
283
347
  end
284
348
 
285
- # Query resource's membership
286
- def request_membership(*args)
287
- @membership
288
- end
289
-
290
- # Request child resources
291
- # @return [Hashie::Mash] child resource mash with uid and hrn
292
- def request_child_resources(*args)
293
- #children.map { |c| Hashie::Mash.new({ uid: c.uid, name: c.hrn }) }
294
- children.map { |c| c.to_hash }
295
- end
349
+ # @!endgroup
296
350
 
297
351
  # Parse omf message and execute as instructed by the message
298
352
  #
299
- # @param [OmfCommon::Message]
300
- # @param [OmfCommon::Comm::Topic]
353
+ # @param [OmfCommon::Message] message FRCP message
354
+ # @param [OmfCommon::Comm::Topic] topic subscribed to
301
355
  def process_omf_message(message, topic)
302
356
  return unless check_guard(message)
303
357
 
@@ -317,6 +371,11 @@ class OmfRc::ResourceProxy::AbstractResource
317
371
  end
318
372
  end
319
373
 
374
+ # Execute operation based on the type of the message
375
+ #
376
+ # @param [OmfCommon::Message] message FRCP message
377
+ # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
378
+ # @param [OmfCommon::Comm::Topic] topic subscribed to
320
379
  def execute_omf_operation(message, obj, topic)
321
380
  begin
322
381
  response_h = handle_message(message, obj)
@@ -342,6 +401,9 @@ class OmfRc::ResourceProxy::AbstractResource
342
401
  end
343
402
 
344
403
  # Handling all messages, then delegate them to individual handler
404
+ #
405
+ # @param [OmfCommon::Message] message FRCP message
406
+ # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
345
407
  def handle_message(message, obj)
346
408
  response = message.create_inform_reply_message(nil, {}, src: resource_address)
347
409
  response.replyto replyto_address(obj, message.replyto)
@@ -350,7 +412,7 @@ class OmfRc::ResourceProxy::AbstractResource
350
412
  when :create
351
413
  handle_create_message(message, obj, response)
352
414
  when :request
353
- response = handle_request_message(message, obj, response)
415
+ handle_request_message(message, obj, response)
354
416
  when :configure
355
417
  handle_configure_message(message, obj, response)
356
418
  when :release
@@ -366,45 +428,31 @@ class OmfRc::ResourceProxy::AbstractResource
366
428
  response
367
429
  end
368
430
 
431
+ # FRCP CREATE message handler
432
+ #
433
+ # @param [OmfCommon::Message] message FRCP message
434
+ # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
435
+ # @param [OmfCommon::Message] response initialised FRCP INFORM message object
369
436
  def handle_create_message(message, obj, response)
370
437
  new_name = message[:name] || message[:hrn]
371
- mprops = message.properties.merge({ hrn: new_name })
372
- exclude = [:type, :hrn, :name, :uid]
373
- props = {}
374
- copts = {}
375
- mprops.each do |k, v|
376
- if exclude.include?(k)
377
- copts[k] = v
378
- else
379
- props[k] = v
380
- end
381
- end
382
- new_obj = obj.create(message[:type], copts, &lambda do |new_obj|
438
+ msg_props = message.properties.merge({ hrn: new_name })
439
+
440
+ obj.create(message[:type], msg_props, &lambda do |new_obj|
383
441
  begin
384
442
  response[:res_id] = new_obj.resource_address
443
+ response[:uid] = new_obj.uid
385
444
 
386
- props.each do |key, value|
387
- method_name = "configure_#{key}"
388
-
389
- if new_obj.respond_to? method_name
390
- response[key] = new_obj.__send__(method_name, value)
391
- elsif new_obj.respond_to? "request_#{key}"
392
- # For read only props, they won't have "configure" method defined,
393
- # we can still set them directly during this creation.
394
- new_obj.property[key] = value
395
- response[key] = value
445
+ msg_props.each do |key, value|
446
+ if new_obj.respond_to? "request_#{key}"
447
+ response[key] = new_obj.__send__("request_#{key}")
448
+ elsif new_obj.respond_to? key
449
+ response[key] = new_obj.__send__(key)
396
450
  end
397
451
  end
398
452
 
399
- response[:hrn] = new_obj.hrn
400
- response[:uid] = new_obj.uid
401
- response[:type] = new_obj.type
402
453
  if (cred = new_obj.certificate)
403
454
  response[:cert] = cred.to_pem_compact
404
455
  end
405
-
406
- new_obj.after_initial_configured if new_obj.respond_to? :after_initial_configured
407
-
408
456
  # self here is the parent
409
457
  self.inform(:creation_ok, response)
410
458
  rescue => ex
@@ -418,6 +466,11 @@ class OmfRc::ResourceProxy::AbstractResource
418
466
  end)
419
467
  end
420
468
 
469
+ # FRCP CONFIGURE message handler
470
+ #
471
+ # @param [OmfCommon::Message] message FRCP message
472
+ # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
473
+ # @param [OmfCommon::Message] response initialised FRCP INFORM message object
421
474
  def handle_configure_message(message, obj, response)
422
475
  message.each_property do |key, value|
423
476
  method_name = "#{message.operation.to_s}_#{key}"
@@ -426,6 +479,11 @@ class OmfRc::ResourceProxy::AbstractResource
426
479
  end
427
480
  end
428
481
 
482
+ # FRCP REQUEST message handler
483
+ #
484
+ # @param [OmfCommon::Message] message FRCP message
485
+ # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
486
+ # @param [OmfCommon::Message] response initialised FRCP INFORM message object
429
487
  def handle_request_message(message, obj, response)
430
488
  request_props = if message.has_properties?
431
489
  message.properties.keys.map(&:to_sym) & obj.request_available_properties.request
@@ -439,10 +497,13 @@ class OmfRc::ResourceProxy::AbstractResource
439
497
  value = obj.__send__(method_name)
440
498
  response[p_name] = value if value
441
499
  end
442
-
443
- response
444
500
  end
445
501
 
502
+ # FRCP RELEASE message handler
503
+ #
504
+ # @param [OmfCommon::Message] message FRCP message
505
+ # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
506
+ # @param [OmfCommon::Message] response initialised FRCP INFORM message object
446
507
  def handle_release_message(message, obj, response)
447
508
  res_id = message.res_id
448
509
  released_obj = obj.release(res_id)
@@ -461,6 +522,15 @@ class OmfRc::ResourceProxy::AbstractResource
461
522
  # @param [String] topic Name of topic to send it. :ALL means to uid as well s all members
462
523
  #
463
524
  def inform(itype, inform_data, topic = nil)
525
+ inform_data = inform_data.dup # better make a copy
526
+ unless address = resource_address
527
+ OmfCommon.eventloop.after(1) do
528
+ # try again in a bit and see if address has been set by then
529
+ inform(itype, inform_data, topic = nil)
530
+ end
531
+ warn "INFORM message delayed as resource's address is not known yet"
532
+ return
533
+ end
464
534
  if topic == :ALL
465
535
  inform(itype, inform_data)
466
536
  membership_topics.each {|m| inform(itype, inform_data, m[1])}
@@ -472,7 +542,7 @@ class OmfRc::ResourceProxy::AbstractResource
472
542
  inform_data = Hashie::Mash.new(inform_data) if inform_data.class == Hash
473
543
  #idata = inform_data.dup
474
544
  idata = {
475
- src: @topics.first.address,
545
+ src: address,
476
546
  type: self.type # NOTE: Should we add the object's type as well???
477
547
  }
478
548
  message = OmfCommon::Message.create_inform_message(itype.to_s.upcase, inform_data, idata)
@@ -508,13 +578,18 @@ class OmfRc::ResourceProxy::AbstractResource
508
578
  end
509
579
 
510
580
  # Return a hash describing a reference to this object
511
- def to_hash(options={})
581
+ #
582
+ # @return [Hash]
583
+ def to_hash
512
584
  { uid: @uid, address: resource_address() }
513
585
  end
514
586
 
515
587
  private
516
588
 
517
- # Find resource object based on topic name
589
+ # To deal with FRCP messages published to a group topic, we need to find out what resources belongs to that topic.
590
+ #
591
+ # @param [String] name of the topic
592
+ # @return [Array<OmfRc::ResourceProxy::AbstractResource>]
518
593
  def objects_by_topic(name)
519
594
  if name == uid || membership.include?(name)
520
595
  objs = [self]
@@ -523,10 +598,18 @@ class OmfRc::ResourceProxy::AbstractResource
523
598
  end
524
599
  end
525
600
 
601
+ # Retrieve replyto address
602
+ #
603
+ # @param [OmfRc::ResourceProxy::AbstractResource] obj resource object
604
+ # @param [String] replyto address where reply should send to
526
605
  def replyto_address(obj, replyto = nil)
527
606
  replyto || obj.uid
528
607
  end
529
608
 
609
+ # Checking if current object met the condition set by message guard section
610
+ #
611
+ # @param [OmfCommon::Message] message FRCP message
612
+ # @return [Boolean]
530
613
  def check_guard(message)
531
614
  guard = message.guard
532
615
 
@@ -543,4 +626,22 @@ class OmfRc::ResourceProxy::AbstractResource
543
626
  end
544
627
  end
545
628
  end
629
+
630
+ # Used for setting properties came with FRCP CREATE message.
631
+ #
632
+ # @param [OmfRc::ResourceProxy::AbstractResource] res_ctx resource object it applies to
633
+ # @param [Hash] props a set of key value pair of properties configuration
634
+ def init_configure(res_ctx, props)
635
+ props.each do |key, value|
636
+ if res_ctx.respond_to? "configure_#{key}"
637
+ res_ctx.__send__("configure_#{key}", value)
638
+ elsif res_ctx.respond_to? "initialise_#{key}"
639
+ # For read only props, they won't have "configure" method defined,
640
+ # we can still set them directly during this creation.
641
+ res_ctx.__send__("initialise_#{key}", value)
642
+ end
643
+ end
644
+
645
+ call_hook(:after_initial_configured, res_ctx)
646
+ end
546
647
  end