Class: Profitbricks::Firewall

Inherits:
Model
  • Object
show all
Defined in:
lib/profitbricks/firewall.rb

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • options (Hash) (defaults to: {})

    currently just :id is supported

Options Hash (options):

  • :id (String)

    The id of the firewall to locate (required)

Returns:



69
70
71
72
73
# File 'lib/profitbricks/firewall.rb', line 69

def find(options = {})
  response = Profitbricks.request :get_firewall, "<firewallId>#{options[: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

#activateBoolean

Activates the Firewall

Returns:

  • (Boolean)

    true on success, false otherwise



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.

Parameters:

Returns:

  • (Boolean)

    true on success, false otherwise



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

#deactivateBoolean

Deactivates the Firewall

Returns:

  • (Boolean)

    true on success, false otherwise



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

#deleteBoolean

Deletes the Firewall

Returns:

  • (Boolean)

    true on success, false otherwise



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