Class: Ubicloud::Firewall

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

Instance Attribute Summary

Attributes inherited from Model

#adapter, #values

Instance Method Summary collapse

Methods inherited from Model

[], #[], #check_exists, create, #destroy, #id, #info, #initialize, #inspect, list, #location, #name, resolve_associations, #to_h

Constructor Details

This class inherits a constructor from Ubicloud::Model

Instance Method Details

#add_rule(cidr, start_port: nil, end_port: nil) ⇒ Object

Allow the given cidr (ip address range) access to the given port range.

  • If start_port and end_port are both given, they specify the port range.

  • If only start_port is given, only that single port is allowed.

  • If only end_port is given, all ports up to that end port are allowed.

  • If neither start_port and end_port are given, all ports are allowed.

Returns a hash for the firewall rule.



23
24
25
26
27
28
29
# File 'lib/ubicloud/model/firewall.rb', line 23

def add_rule(cidr, start_port: nil, end_port: nil)
  rule = adapter.post(_path("/firewall-rule"), cidr:, port_range: "#{start_port || 0}..#{end_port || start_port || 65535}")

  self[:firewall_rules]&.<<(rule)

  rule
end

#attach_subnet(subnet) ⇒ Object

Attach the given private subnet to the firewall. Accepts either a PrivateSubnet instance or a private subnet id string. Returns a PrivateSubnet instance.



43
44
45
# File 'lib/ubicloud/model/firewall.rb', line 43

def attach_subnet(subnet)
  subnet_action(subnet, "/attach-subnet")
end

#delete_rule(rule_id) ⇒ Object

Delete the firewall rule with the given id. Returns nil.



32
33
34
35
36
37
38
39
# File 'lib/ubicloud/model/firewall.rb', line 32

def delete_rule(rule_id)
  check_no_slash(rule_id, "invalid rule id format")
  adapter.delete(_path("/firewall-rule/#{rule_id}"))

  self[:firewall_rules]&.delete_if { _1[:id] == rule_id }

  nil
end

#detach_subnet(subnet) ⇒ Object

Detach the given private subnet from the firewall. Accepts either a PrivateSubnet instance or a private subnet id string. Returns a PrivateSubnet instance.



49
50
51
# File 'lib/ubicloud/model/firewall.rb', line 49

def detach_subnet(subnet)
  subnet_action(subnet, "/detach-subnet")
end