Class: Fog::Compute::VirtualBox::NATRedirect

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/compute/models/virtual_box/nat_redirect.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

#initialize(attributes = {}) ⇒ NATRedirect

Returns a new instance of NATRedirect.



31
32
33
34
35
36
37
# File 'lib/fog/compute/models/virtual_box/nat_redirect.rb', line 31

def initialize(attributes = {})
  self.name     = ''
  self.protocol = :tcp
  self.host_ip  = ''
  self.guest_ip = ''
  super
end

Instance Attribute Details

#machineObject

Returns the value of attribute machine.



18
19
20
# File 'lib/fog/compute/models/virtual_box/nat_redirect.rb', line 18

def machine
  @machine
end

#nat_engineObject

Returns the value of attribute nat_engine.



18
19
20
# File 'lib/fog/compute/models/virtual_box/nat_redirect.rb', line 18

def nat_engine
  @nat_engine
end

Instance Method Details

#destroyObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/compute/models/virtual_box/nat_redirect.rb', line 20

def destroy
  requires :nat_engine, :name
  with_session do |session|
    raw_network_adapter = session.machine.get_network_adapter(nat_engine.network_adapter.slot)
    raw_nat_engine = raw_network_adapter.nat_driver
    raw_nat_engine.remove_redirect(name)
    session.machine.save_settings
  end
  true
end

#protocol=(new_protocol) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/compute/models/virtual_box/nat_redirect.rb', line 40

def protocol=(new_protocol)
  attributes[:protocol] = case new_protocol
  when '0'
    :udp
  when '1'
    :tcp
  else
    new_protocol
  end
end

#saveObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/compute/models/virtual_box/nat_redirect.rb', line 51

def save
  requires :nat_engine, :name, :protocol, :host_ip, :host_port, :guest_ip, :guest_port
  with_session do |session|
    raw_network_adapter = session.machine.get_network_adapter(nat_engine.network_adapter.slot)
    raw_nat_engine = raw_network_adapter.nat_driver
    raw_nat_engine.add_redirect(name, protocol, host_ip, host_port, guest_ip, guest_port)
    session.machine.save_settings
  end
  true
end