Class: Ey::Core::Client::FirewallRule

Inherits:
Model
  • Object
show all
Extended by:
Associations
Defined in:
lib/ey-core/models/firewall_rule.rb

Instance Method Summary collapse

Methods included from Associations

assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader

Methods inherited from Model

#destroy, range_parser, #save, #to_s, #update!, #url

Instance Method Details

#destroy!Object



38
39
40
# File 'lib/ey-core/models/firewall_rule.rb', line 38

def destroy!
  connection.requests.new(self.connection.destroy_firewall_rule("id" => self.id).body["request"])
end

#save!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ey-core/models/firewall_rule.rb', line 18

def save!
  requires :firewall_id

  self.port_range ||= "0-65535"

  params = {
    "url"           => self.collection.url,
    "firewall_rule" => {
      "port_range" => "#{self.port_range.min}-#{self.port_range.max}",
      "source"     => self.source     || "0.0.0.0/0",
    },
    "firewall" => self.firewall_id,
  }

  if new_record?
    self.connection.requests.new(self.connection.create_firewall_rule(params).body["request"])
  else raise NotImplementedError
  end
end

#source_firewallObject



12
13
14
15
16
# File 'lib/ey-core/models/firewall_rule.rb', line 12

def source_firewall
  unless source.match(Ey::Core::IP_REGEX)
    self.connection.firewalls.get(self.source)
  end
end