Class: Vagrant::Smartos::Zones::Action::ForwardGZPorts

Inherits:
Object
  • Object
show all
Includes:
Helper, VagrantPlugins::ProviderVirtualBox::Util::CompileForwardedPorts
Defined in:
lib/vagrant/smartos/zones/action/forward_gz_ports.rb

Instance Attribute Summary

Attributes included from Helper

#app, #env

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ForwardGZPorts

Returns a new instance of ForwardGZPorts.



11
12
13
14
# File 'lib/vagrant/smartos/zones/action/forward_gz_ports.rb', line 11

def initialize(app, env)
  @app = app
  @env = env
end

Instance Method Details

#call(env) ⇒ Object

This middleware sets up a VirtualBox port forward to 2222 in the global zone. ipnat in the global zone is configured to route this to 22 in the global zone, even when all other ports are forwarded to a zone.



19
20
21
22
23
# File 'lib/vagrant/smartos/zones/action/forward_gz_ports.rb', line 19

def call(env)
  configure_gz_port_forward if zone_configured?

  app.call(env)
end

#configure_gz_port_forwardObject



25
26
27
28
# File 'lib/vagrant/smartos/zones/action/forward_gz_ports.rb', line 25

def configure_gz_port_forward
  machine.ui.info 'Configuring a port forward to talk to the Global Zone'
  machine.config.vm.network :forwarded_port, port_forward_options
end

#networkObject



30
31
32
# File 'lib/vagrant/smartos/zones/action/forward_gz_ports.rb', line 30

def network
  machine.config.vm.networks.first
end

#port_forward_optionsObject



34
35
36
37
38
39
40
41
# File 'lib/vagrant/smartos/zones/action/forward_gz_ports.rb', line 34

def port_forward_options
  scoped_hash_override(network[1], :virtualbox).merge(
    id: 'gz_ssh',
    guest: machine.config.global_zone.ssh_port,
    host: machine.config.global_zone.forwarded_ssh_port,
    auto_correct: true
  )
end