Class: Profitbricks::Firewall
- Defined in:
- lib/profitbricks/firewall.rb
Class Method Summary collapse
-
.find(options = {}) ⇒ Firewall
Returns information about the respective firewall.
Instance Method Summary collapse
-
#activate ⇒ Boolean
Activates the Firewall.
-
#add_rules(rules) ⇒ Boolean
Adds accept-rules to the firewall of a NIC or Load Balancer.
-
#deactivate ⇒ Boolean
Deactivates the Firewall.
-
#delete ⇒ Boolean
Deletes the Firewall.
-
#initialize(hash, parent = nil) ⇒ Firewall
constructor
A new instance of Firewall.
Methods inherited from Model
#attributes, belongs_to, get_xml_and_update_attributes, #get_xml_and_update_attributes, has_many, #reload
Constructor Details
#initialize(hash, parent = nil) ⇒ Firewall
Returns a new instance of Firewall.
5 6 7 8 |
# File 'lib/profitbricks/firewall.rb', line 5 def initialize(hash, parent=nil) @parent = parent super(hash) end |
Class Method Details
.find(options = {}) ⇒ Firewall
Returns information about the respective firewall. Each rule has an identifier for later modification.
69 70 71 72 73 |
# File 'lib/profitbricks/firewall.rb', line 69 def find( = {}) response = Profitbricks.request :get_firewall, "<firewallId>#{[:id]}</firewallId>" # FIXME we cannot load the Firewall without knowing if it is belonging to a NIC or a LoadBalancer PB::Firewall.new(response.to_hash[:get_firewall_response][:return], nil) end |
Instance Method Details
#activate ⇒ Boolean
Activates the Firewall
42 43 44 45 |
# File 'lib/profitbricks/firewall.rb', line 42 def activate response = Profitbricks.request :activate_firewalls, "<firewallIds>#{self.id}</firewallIds>" return true if response[:activate_firewalls_response][:return] end |
#add_rules(rules) ⇒ Boolean
Adds accept-rules to the firewall of a NIC or Load Balancer.
If no firewall exists, a new inactive firewall is created.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/profitbricks/firewall.rb', line 17 def add_rules(rules) xml = "" rules.each do |rule| xml += "<request>" xml += rule.get_xml_and_update_attributes rule.attributes, rule.attributes.keys xml += "</request>" end response = nil if @parent.class == Profitbricks::LoadBalancer xml += "<loadBalancerId>#{@parent.id}</loadBalancerId>" response = Profitbricks.request :add_firewall_rules_to_load_balancer, xml update_attributes(response.to_hash[:add_firewall_rules_to_load_balancer_response][:return]) return true if response.to_hash[:add_firewall_rules_to_load_balancer_response][:return] else xml += "<nicId>#{self.nic_id}</nicId>" response = Profitbricks.request :add_firewall_rules_to_nic, xml update_attributes(response.to_hash[:add_firewall_rules_to_nic_response][:return]) return true if response.to_hash[:add_firewall_rules_to_nic_response][:return] end end |
#deactivate ⇒ Boolean
Deactivates the Firewall
50 51 52 53 |
# File 'lib/profitbricks/firewall.rb', line 50 def deactivate response = Profitbricks.request :deactivate_firewalls, "<firewallIds>#{self.id}</firewallIds>" return true if response[:deactivate_firewalls_response][:return] end |
#delete ⇒ Boolean
Deletes the Firewall
58 59 60 61 |
# File 'lib/profitbricks/firewall.rb', line 58 def delete response = Profitbricks.request :delete_firewalls, "<firewallIds>#{self.id}</firewallIds>" return true if response[:delete_firewalls_response][:return] end |