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, 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:



63
64
65
66
67
# 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

Instance Method Details

#activateBoolean

Activates the Firewall

Returns:

  • (Boolean)

    true on success, false otherwise



36
37
38
39
# File 'lib/profitbricks/firewall.rb', line 36

def activate
  response = Profitbricks.request :activate_firewalls, firewall_ids: self.id
  return true
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
# 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

#deactivateBoolean

Deactivates the Firewall

Returns:

  • (Boolean)

    true on success, false otherwise



44
45
46
47
# File 'lib/profitbricks/firewall.rb', line 44

def deactivate
  response = Profitbricks.request :deactivate_firewalls, firewall_ids: self.id
  return true
end

#deleteBoolean

Deletes the Firewall

Returns:

  • (Boolean)

    true on success, false otherwise



52
53
54
55
# File 'lib/profitbricks/firewall.rb', line 52

def delete
  response = Profitbricks.request :delete_firewalls, firewall_ids: self.id
  return true
end