Class: Dcmgr::VNet::Tasks::StaticNat

Inherits:
Dcmgr::VNet::Task show all
Includes:
Netfilter
Defined in:
lib/dcmgr/vnet/tasks/static_nat.rb

Instance Attribute Summary collapse

Attributes inherited from Dcmgr::VNet::Task

#rules

Instance Method Summary collapse

Constructor Details

#initialize(inside_ip, outside_ip, mac_address) ⇒ StaticNat

Returns a new instance of StaticNat.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dcmgr/vnet/tasks/static_nat.rb', line 34

def initialize(inside_ip, outside_ip, mac_address)
  super()
  
  self.inside_ip = inside_ip
  self.outside_ip = outside_ip
  self.mac_address = mac_address
  
  self.rules = []
  
  # Reply ARP requests for the outside ip
  self.rules << EbtablesRule.new(:nat,:prerouting,:arp,:incoming,"-p arp --arp-ip-dst #{self.outside_ip} --arp-opcode REQUEST -j arpreply --arpreply-mac #{self.mac_address}")
  
  # Translate the ip
  self.rules << IptablesRule.new(:nat,:postrouting,nil,:outgoing,"-s #{self.inside_ip} -j SNAT --to #{self.outside_ip}")
  self.rules << IptablesRule.new(:nat,:prerouting,nil,:incoming,"-d #{self.outside_ip} -j DNAT --to #{self.inside_ip}")
end

Instance Attribute Details

#inside_ipObject

Returns the value of attribute inside_ip.



30
31
32
# File 'lib/dcmgr/vnet/tasks/static_nat.rb', line 30

def inside_ip
  @inside_ip
end

#mac_addressObject

Returns the value of attribute mac_address.



32
33
34
# File 'lib/dcmgr/vnet/tasks/static_nat.rb', line 32

def mac_address
  @mac_address
end

#outside_ipObject

Returns the value of attribute outside_ip.



31
32
33
# File 'lib/dcmgr/vnet/tasks/static_nat.rb', line 31

def outside_ip
  @outside_ip
end