Class: Squall::FirewallRule

Inherits:
Base
  • Object
show all
Defined in:
lib/squall/firewall_rule.rb

Overview

OnApp FirewallRule

Instance Attribute Summary

Attributes inherited from Base

#result, #success

Instance Method Summary (collapse)

Methods inherited from Base

#check_config, #default_params, #key_for_class, #request

Instance Method Details

- (Object) create(vm_id, options = {})

Create a firewall rule for a virtual machine.

Examples:

create(
  command:              "DROP",
  protocol              "TCP",
  network_interface_id: 1
)

Parameters:

  • vm_id

    ID of the virtual machine

  • options (defaults to: {})

    A Hash of options for the firewall rule:

Options Hash (options):

  • :address (Object)

    IP address or range scope for rule. Leave blank to apply to all.

  • :command (Object)

    DROP or ACCEPT

  • :network_interface_id (Object)

    ID of the network interface

  • :port (Object)

    Port address for rule

  • :protocol (Object)

    TCP or UDP

Returns:

  • a Hash.



34
35
36
# File 'lib/squall/firewall_rule.rb', line 34

def create(vm_id, options = {})
  request(:post, "/virtual_machines/#{vm_id}/firewall_rules.json", default_params(options))
end

- (Object) delete(vm_id, id)

Delete a firewall rule.

Parameters:

  • vm_id

    ID of the virtual machine

  • id

    ID of the firewall rule

Returns:

  • a Hash.



55
56
57
# File 'lib/squall/firewall_rule.rb', line 55

def delete(vm_id, id)
  request(:delete, "/virtual_machines/#{vm_id}/firewall_rules/#{id}.json")
end

- (Object) edit(vm_id, id, options = {})

Edit a firewall rule.

Parameters:

  • vm_id

    ID of the virtual machine

  • id

    ID of the firewall rule

  • options (defaults to: {})

    A Hash of options for the firewall rule, see `#create`.

Returns:

  • a Hash.



45
46
47
# File 'lib/squall/firewall_rule.rb', line 45

def edit(vm_id, id, options = {})
  request(:put, "/virtual_machines/#{vm_id}/firewall_rules/#{id}.json", default_params(options))
end

- (Object) list(vm_id)

Lists all firewall rules for a virtual machine.

Parameters:

  • vm_id

    ID of the virtual machine

Returns:

  • an Array.



9
10
11
12
# File 'lib/squall/firewall_rule.rb', line 9

def list(vm_id)
  response = request(:get, "/virtual_machines/#{vm_id}/firewall_rules.json")
  response.collect { |firewall_rule| user['firewall_rule'] }
end