class Profitbricks::Firewall

Public Class Methods

find(options = {}) click to toggle source

Returns information about the respective firewall. Each rule has an identifier for later modification.

@param [Hash] options currently just :id is supported @option options [String] :id The id of the firewall to locate (required) @return [Firewall] The located Firewall

# File lib/profitbricks/firewall.rb, line 63
def find(options = {})
  response = Profitbricks.request :get_firewall, firewall_id: options[:id]
  # FIXME we cannot load the Firewall without knowing if it is belonging to a NIC or a LoadBalancer
  PB::Firewall.new(response, nil)
end
new(hash, parent=nil) click to toggle source
Calls superclass method Profitbricks::Model::new
# File lib/profitbricks/firewall.rb, line 5
def initialize(hash, parent=nil)
  @parent = parent
  super(hash)
end

Public Instance Methods

activate() click to toggle source

Activates the Firewall

@return [Boolean] true on success, false otherwise

# File lib/profitbricks/firewall.rb, line 36
def activate
  response = Profitbricks.request :activate_firewalls, firewall_ids: self.id
  return true
end
add_rules(rules) click to toggle source

Adds accept-rules to the firewall of a NIC or Load Balancer.

If no firewall exists, a new inactive firewall is created.

@param [Array<FirewallRule>] Array of FirewallRules to add @return [Boolean] true on success, false otherwise

# File lib/profitbricks/firewall.rb, line 17
def add_rules(rules)
  options = {request: []}
  rules.each do |rule|
    options[:request] << rule.attributes
  end
  response = nil
  if @parent.class == Profitbricks::LoadBalancer
    response = Profitbricks.request :add_firewall_rules_to_load_balancer, options.merge(load_balancer_id: @parent.id)
    self.reload
  else
    response = Profitbricks.request :add_firewall_rules_to_nic, options.merge(nic_id: self.nic_id)
    self.reload
  end
  
end
deactivate() click to toggle source

Deactivates the Firewall

@return [Boolean] true on success, false otherwise

# File lib/profitbricks/firewall.rb, line 44
def deactivate
  response = Profitbricks.request :deactivate_firewalls, firewall_ids: self.id
  return true
end
delete() click to toggle source

Deletes the Firewall

@return [Boolean] true on success, false otherwise

# File lib/profitbricks/firewall.rb, line 52
def delete
  response = Profitbricks.request :delete_firewalls, firewall_ids: self.id
  return true
end