class Kakine::SecurityRule
Constants
- ATTRIBUTES
Attributes
id[R]
Public Class Methods
new(rule, tenant_name, sg_name)
click to toggle source
# File lib/kakine/security_rule.rb, line 7 def initialize(rule, tenant_name, sg_name) @tenant_name = tenant_name @sg_name = sg_name rule.each do|k,v| instance_variable_set(eval(":@#{k.to_s}"), v) unless k.include?("port") end @port_range_min, @port_range_max = *convert_port_format(rule) end
Public Instance Methods
==(target_sg)
click to toggle source
# File lib/kakine/security_rule.rb, line 18 def ==(target_sg) ATTRIBUTES.all? do |attr| self.public_send(attr) == target_sg.public_send(attr) end end
convert_port_format(rule)
click to toggle source
# File lib/kakine/security_rule.rb, line 24 def convert_port_format(rule) unless format = port?(rule) || icmp?(rule) || range?(rule) raise(Kakine::SecurityRuleError, "no match port format") end format end
icmp?(rule)
click to toggle source
# File lib/kakine/security_rule.rb, line 35 def icmp?(rule) if rule.has_key?('type') && rule.has_key?('code') [rule['type'] ,rule['code']] end end
port?(rule)
click to toggle source
# File lib/kakine/security_rule.rb, line 31 def port?(rule) [rule['port'] ,rule['port']] if rule.has_key?('port') end
range?(rule)
click to toggle source
# File lib/kakine/security_rule.rb, line 41 def range?(rule) if rule.has_key?('port_range_max') && rule.has_key?('port_range_min') [rule['port_range_min'] ,rule['port_range_max']] end end
remote_group_id()
click to toggle source
# File lib/kakine/security_rule.rb, line 47 def remote_group_id if !!@remote_group unless remote_security_group = Kakine::Resource.get(:openstack).security_group(@tenant_name, @remote_group) raise(Kakine::SecurityRuleError, "not exists #{@remote_group}") end remote_security_group.id end end