Class: Vagrant::Smartos::Zones::Util::GlobalZone::SSHInfo

Inherits:
Struct
  • Object
show all
Defined in:
lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config

Returns:

  • (Object)

    the current value of config



6
7
8
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 6

def config
  @config
end

#envObject

Returns the value of attribute env

Returns:

  • (Object)

    the current value of env



6
7
8
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 6

def env
  @env
end

#providerObject

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



6
7
8
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 6

def provider
  @provider
end

Instance Method Details

#forward_agentObject



7
8
9
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 7

def forward_agent
  config.ssh.forward_agent
end

#forward_x11Object



11
12
13
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 11

def forward_x11
  config.ssh.forward_x11
end

#hostObject



15
16
17
18
19
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 15

def host
  return config.ssh.host if config.ssh.host
  return ssh_info[:host] if ssh_info[:host]
  config.ssh.default.host
end

#passwordObject



21
22
23
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 21

def password
  config.ssh.password
end

#portObject



25
26
27
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 25

def port
  port_forward[2]
end

#private_key_pathsObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 29

def private_key_paths
  return [] if password

  @paths ||= [].tap do |paths|
    paths << config.ssh.private_key_path
    paths << config.ssh.default.private_key_path
    paths << env.default_private_key_path
  end.compact.map do |path|
    File.expand_path(path, env.root_path)
  end
end

#proxy_commandObject



41
42
43
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 41

def proxy_command
  config.ssh.proxy_command if config.ssh.proxy_command
end

#to_hashObject

rubocop:disable Metrics/MethodLength



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 52

def to_hash
  # From machine#ssh_info, if provider ssh_info is nil,
  # machine is not ready for SSH.
  return nil if ssh_info.nil?

  {
    host: host,
    port: port,
    private_key_path: private_key_paths,
    username: username,
    password: password,
    proxy_command: proxy_command,
    forward_agent: forward_agent,
    forward_x11: forward_x11
  }.delete_if { |_k, v| v.nil? }
end

#usernameObject



45
46
47
48
49
# File 'lib/vagrant/smartos/zones/util/global_zone/ssh_info.rb', line 45

def username
  return config.ssh.password if config.ssh.password
  return ssh_info[:username] if ssh_info[:username]
  config.ssh.default.username
end