Class: RightScale::PolicyManager
- Defined in:
- lib/instance/policy_manager.rb
Overview
Manages policies
Class Attribute Summary collapse
-
.policy ⇒ Object
readonly
Returns the value of attribute policy.
Class Method Summary collapse
-
.fail(bundle) ⇒ Object
Signals the failed execution of a recipe with the given bundle.
-
.get_audit(bundle) ⇒ Object
Returns the audit for the given policy of the bundle.
-
.register(bundle, &block) ⇒ Object
Registers the bundle with the Manager and calls the passed in block when registration completes In a multithreaded environment, the.
- .registered?(bundle) ⇒ Boolean
-
.success(bundle) ⇒ Object
Signals the successful execution of a right script or recipe with the given bundle.
Class Attribute Details
.policy ⇒ Object (readonly)
Returns the value of attribute policy.
32 33 34 |
# File 'lib/instance/policy_manager.rb', line 32 def policy @policy end |
Class Method Details
.fail(bundle) ⇒ Object
Signals the failed execution of a recipe with the given bundle
Parameters
- bundle(ExecutableBundle)
-
bundle containing a RunlistPolicy
Return
- result(Boolean)
-
Return false if the bundle fails to provide a valid runlist policy
91 92 93 94 95 96 |
# File 'lib/instance/policy_manager.rb', line 91 def fail(bundle) policy = get_policy_from_bundle(bundle) return false unless policy policy.fail true end |
.get_audit(bundle) ⇒ Object
Returns the audit for the given policy of the bundle
Parameters
- bundle(ExecutableBundle)
-
An executable bundle
Return
- result(PolicyAudit)
-
a PolicyAudit instance that wraps AuditProxy
105 106 107 108 |
# File 'lib/instance/policy_manager.rb', line 105 def get_audit(bundle) policy = get_policy_from_bundle(bundle) policy ? policy.audit : nil end |
.register(bundle, &block) ⇒ Object
Registers the bundle with the Manager and calls the passed in block when registration completes In a multithreaded environment, the
Parameters
- bundle(ExecutableBundle)
-
bundle containing a RunlistPolicy
- block(Block)
-
block to execute once registration is complete. The block will be called with
Return
- result(Boolean)
-
Return false if the bundle fails to provide a valid runlist policy
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/instance/policy_manager.rb', line 47 def register(bundle, &block) runlist_policy = runlist_policy_from_bundle(bundle) if runlist_policy if registering?(runlist_policy.policy_name) # waiting for a new audit to be created, place the block to be called on the list of callbacks @registrations[runlist_policy.policy_name] << block if block else # this is the first registration, add the callback to the list of callbacks to be executed after the audit has been created @registrations[runlist_policy.policy_name] = (block) ? [block] : [] # request a new audit RightScale::AuditProxy.create(RightScale::InstanceState.identity, "Reconvergence Policy '#{runlist_policy.policy_name}'") do |audit| policy = Policy.new(runlist_policy.policy_name, runlist_policy.audit_period, audit) @policies[policy.policy_name] = policy # drain the pending registrations @registrations[policy.policy_name].each { |blk| blk.call(bundle, policy.audit) } @registrations.delete(policy.policy_name) end end true end false end |
.registered?(bundle) ⇒ Boolean
34 35 36 |
# File 'lib/instance/policy_manager.rb', line 34 def registered?(bundle) @policies.has_key?(policy_name_from_bundle(bundle)) end |
.success(bundle) ⇒ Object
Signals the successful execution of a right script or recipe with the given bundle
Parameters
- bundle(ExecutableBundle)
-
bundle containing a RunlistPolicy
Return
- result(Boolean)
-
Return false if the bundle fails to provide a valid runlist policy
77 78 79 80 81 82 |
# File 'lib/instance/policy_manager.rb', line 77 def success(bundle) policy = get_policy_from_bundle(bundle) return false unless policy policy.success true end |