Class: OpenStack::Nova::Compute::Rule
- Defined in:
- lib/open_stack/nova/compute/security_group.rb
Overview
An OpenStack Security Group Rule
Attributes
-
ip_protocol
- Protocol: tcp, udp or icmp -
from_port
- Initial port -
to_port
- Final port -
parent_group_id
- The security group this rule belongs to -
cidr
- A cidr
Instance Method Summary collapse
-
#encode(options = {}) ⇒ Object
Override ActiveRecord::encode method.
-
#icmp? ⇒ Boolean
True if this rule refers to ICMP.
-
#initialize(attributes = {}, persisted = false) ⇒ Rule
constructor
:notnew:.
-
#parent_group ⇒ Object
Parent group for this rule.
-
#parent_group=(group) ⇒ Object
Set the parent security group (if the rule is not persisted).
-
#tcp? ⇒ Boolean
True if this rule refers to TCP.
-
#udp? ⇒ Boolean
True if this rule refers to UDP.
Methods inherited from Base
Methods inherited from Common
collection_path, custom_method_collection_url, element_path
Methods inherited from Base
Methods inherited from ActiveResource::Base
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ Rule
:notnew:
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/open_stack/nova/compute/security_group.rb', line 79 def initialize(attributes = {}, persisted = false) # :notnew: attributes = attributes.with_indifferent_access new_attributes = { :id => attributes[:id], :ip_protocol => attributes[:ip_protocol], :from_port => attributes[:from_port], :to_port => attributes[:to_port], :cidr => attributes[:cidr] || (attributes[:ip_range].present? ? attributes[:ip_range][:cidr] : nil), :parent_group_id => attributes[:parent_group].present? ? attributes[:parent_group].id : nil } super(new_attributes, persisted) end |
Instance Method Details
#encode(options = {}) ⇒ Object
Override ActiveRecord::encode method
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/open_stack/nova/compute/security_group.rb', line 93 def encode(={}) # :nodoc: Custom encoding to deal with openstack API to_encode = { :security_group_rule => { :ip_protocol => ip_protocol, :from_port => from_port, :to_port => to_port, :cidr => cidr, :parent_group_id => parent_group_id, } } to_encode.send("to_#{self.class.format.extension}", ) end |
#icmp? ⇒ Boolean
True if this rule refers to ICMP
125 126 127 |
# File 'lib/open_stack/nova/compute/security_group.rb', line 125 def icmp? ip_protocol == 'icmp' end |
#parent_group ⇒ Object
Parent group for this rule
118 119 120 121 122 |
# File 'lib/open_stack/nova/compute/security_group.rb', line 118 def parent_group unless parent_group_id.nil? @parent_group ||= SecurityGroup.find(parent_group_id) end end |
#parent_group=(group) ⇒ Object
Set the parent security group (if the rule is not persisted)
Attributes
-
group
: An instance of OpenStack::Nova::Compute::SecurityGroup or a security group id
110 111 112 113 114 115 |
# File 'lib/open_stack/nova/compute/security_group.rb', line 110 def parent_group=(group) unless persisted? @parent_group = nil self.parent_group_id = group.is_a?(OpenStack::Nova::Compute::SecurityGroup) ? group.id : group end end |
#tcp? ⇒ Boolean
True if this rule refers to TCP
135 136 137 |
# File 'lib/open_stack/nova/compute/security_group.rb', line 135 def tcp? ip_protocol == 'tcp' end |
#udp? ⇒ Boolean
True if this rule refers to UDP
130 131 132 |
# File 'lib/open_stack/nova/compute/security_group.rb', line 130 def udp? ip_protocol == 'udp' end |