Class: Kakine::SecurityGroup
- Inherits:
-
Object
- Object
- Kakine::SecurityGroup
- Defined in:
- lib/kakine/security_group.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#tenant_name ⇒ Object
readonly
Returns the value of attribute tenant_name.
Instance Method Summary collapse
- #!=(target_sg) ⇒ Object
- #==(target_sg) ⇒ Object
- #find_by_rule(target_rule) ⇒ Object
- #get_rule_instances(params) ⇒ Object
- #has_rules? ⇒ Boolean
-
#initialize(tenant_name, params) ⇒ SecurityGroup
constructor
A new instance of SecurityGroup.
- #same_group?(target_sg) ⇒ Boolean
- #same_rule?(a, b) ⇒ Boolean
- #tenant_id ⇒ Object
Constructor Details
#initialize(tenant_name, params) ⇒ SecurityGroup
Returns a new instance of SecurityGroup.
6 7 8 9 10 11 12 |
# File 'lib/kakine/security_group.rb', line 6 def initialize(tenant_name, params) @name = params[0] @tenant_name = tenant_name @id = params[1]["id"] || "" @description = params[1]["description"] || "" @rules = get_rule_instances(params) || [] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/kakine/security_group.rb', line 4 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/kakine/security_group.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/kakine/security_group.rb', line 4 def name @name end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
4 5 6 |
# File 'lib/kakine/security_group.rb', line 4 def rules @rules end |
#tenant_name ⇒ Object (readonly)
Returns the value of attribute tenant_name.
4 5 6 |
# File 'lib/kakine/security_group.rb', line 4 def tenant_name @tenant_name end |
Instance Method Details
#!=(target_sg) ⇒ Object
22 23 24 |
# File 'lib/kakine/security_group.rb', line 22 def !=(target_sg) !(self == target_sg) end |
#==(target_sg) ⇒ Object
18 19 20 |
# File 'lib/kakine/security_group.rb', line 18 def ==(target_sg) same_group?(target_sg) && same_rule?(self, target_sg) && same_rule?(target_sg, self) end |
#find_by_rule(target_rule) ⇒ Object
44 45 46 |
# File 'lib/kakine/security_group.rb', line 44 def find_by_rule(target_rule) @rules.find { |rule| rule == target_rule } end |
#get_rule_instances(params) ⇒ Object
38 39 40 41 42 |
# File 'lib/kakine/security_group.rb', line 38 def get_rule_instances(params) params[1]["rules"].map do |rule| SecurityRule.new(rule, @tenant_name, @name) end unless params[1]["rules"].nil? end |
#has_rules? ⇒ Boolean
48 49 50 |
# File 'lib/kakine/security_group.rb', line 48 def has_rules? @rules.detect {|v| !v.nil?} end |
#same_group?(target_sg) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/kakine/security_group.rb', line 26 def same_group?(target_sg) %i(@name @tenant_name @description).all? do |val| instance_variable_get(val) == target_sg.instance_variable_get(val) end end |
#same_rule?(a, b) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/kakine/security_group.rb', line 32 def same_rule?(a, b) a.rules.all? do |rule| b.find_by_rule(rule) end end |
#tenant_id ⇒ Object
14 15 16 |
# File 'lib/kakine/security_group.rb', line 14 def tenant_id Yao.current_tenant_id end |