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

- (Firewall) initialize(hash, parent = nil)

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

+ (Firewall) find(options = {})

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

- (Boolean) activate

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

- (Boolean) add_rules(rules)

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

- (Boolean) deactivate

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

- (Boolean) delete

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