Class: Policy
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_rule(rule) ⇒ Object
- #allow_established ⇒ Object
- #allow_ip(ip) ⇒ Object
- #allow_ips(*hosts) ⇒ Object
- #allow_listen(*ports) ⇒ Object
- #allow_ping ⇒ Object
- #allow_slicehost_slices(key) ⇒ Object
- #allow_ssh ⇒ Object
- #clean ⇒ Object
- #config ⇒ Object
- #deny_all ⇒ Object
- #dirty? ⇒ Boolean
-
#initialize(dsl_file, logger) ⇒ Policy
constructor
A new instance of Policy.
- #policy(name = :unnamed) ⇒ Object
- #rules ⇒ Object
- #update(options = {}) ⇒ Object
Methods included from SlicehostSupport
Constructor Details
#initialize(dsl_file, logger) ⇒ Policy
Returns a new instance of Policy.
8 9 10 11 12 13 14 15 16 |
# File 'lib/policy.rb', line 8 def initialize(dsl_file, logger) @stack = [] @top = [] @stack.push(@top) @dirty = false @logger = logger instance_eval File.open(dsl_file).read, dsl_file end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/policy.rb', line 6 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/policy.rb', line 6 def name @name end |
Instance Method Details
#add_rule(rule) ⇒ Object
73 74 75 76 |
# File 'lib/policy.rb', line 73 def add_rule(rule) @dirty = true @stack.last << rule end |
#allow_established ⇒ Object
57 58 59 |
# File 'lib/policy.rb', line 57 def allow_established add_rule IptablesGenerator.allow_established end |
#allow_ip(ip) ⇒ Object
39 40 41 |
# File 'lib/policy.rb', line 39 def allow_ip(ip) add_rule IptablesGenerator.allow_ip ip end |
#allow_ips(*hosts) ⇒ Object
43 44 45 46 |
# File 'lib/policy.rb', line 43 def allow_ips(*hosts) hosts = hosts.first if hosts.length == 1 && hosts.first.instance_of?(Array) add_rule IptablesGenerator.allow_ips hosts end |
#allow_listen(*ports) ⇒ Object
48 49 50 51 |
# File 'lib/policy.rb', line 48 def allow_listen(*ports) ports = ports.first if ports.length == 1 && ports.first.instance_of?(Array) add_rule IptablesGenerator.allow_listen(ports) end |
#allow_ping ⇒ Object
61 62 63 |
# File 'lib/policy.rb', line 61 def allow_ping add_rule IptablesGenerator.allow_ping end |
#allow_slicehost_slices(key) ⇒ Object
53 54 55 |
# File 'lib/policy.rb', line 53 def allow_slicehost_slices(key) add_rule IptablesGenerator.allow_slicehost_slices(key) end |
#allow_ssh ⇒ Object
65 66 67 |
# File 'lib/policy.rb', line 65 def allow_ssh add_rule IptablesGenerator.allow_ssh end |
#clean ⇒ Object
26 27 28 |
# File 'lib/policy.rb', line 26 def clean @dirty = false end |
#config ⇒ Object
30 31 32 |
# File 'lib/policy.rb', line 30 def config yield end |
#deny_all ⇒ Object
69 70 71 |
# File 'lib/policy.rb', line 69 def deny_all add_rule IptablesGenerator.deny_all end |
#dirty? ⇒ Boolean
22 23 24 |
# File 'lib/policy.rb', line 22 def dirty? @dirty end |
#policy(name = :unnamed) ⇒ Object
34 35 36 37 |
# File 'lib/policy.rb', line 34 def policy(name = :unnamed) @name = name yield end |
#rules ⇒ Object
18 19 20 |
# File 'lib/policy.rb', line 18 def rules @top end |
#update(options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/policy.rb', line 78 def update( = {}) index = @stack.last.length @stack.push([]) yield rules = @stack.pop @stack.last[index] = rules period = [:each].to_i if period > 0 EM.add_periodic_timer period do rules.clear @stack.push(rules) yield @stack.pop end end end |