Module: Vagrant::Environment::Remote

Defined in:
lib/vagrant/environment/remote.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



10
11
12
13
14
# File 'lib/vagrant/environment/remote.rb', line 10

def self.prepended(klass)
  klass.class_eval do
    attr_reader :client
  end
end

Instance Method Details

#active_machinesObject



81
82
83
84
85
86
87
88
# File 'lib/vagrant/environment/remote.rb', line 81

def active_machines
  targets = client.active_targets
  names = []
  targets.each do |t|
    names << [t.name, t.provider_name.to_sym]
  end
  names
end

#boxesBoxCollection

Returns the collection of boxes for the environment.

Returns:



93
94
95
96
# File 'lib/vagrant/environment/remote.rb', line 93

def boxes
  box_colletion_client = client.boxes
  @_boxes ||= BoxCollection.new(nil, client: box_colletion_client)
end

#config_loaderObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vagrant/environment/remote.rb', line 98

def config_loader
  return @config_loader if @config_loader

  root_vagrantfile = nil
  if client.respond_to?(:vagrantfile_path) && client.respond_to?(:vagrantfile_name)
    path = client.vagrantfile_path
    name = client.vagrantfile_name
    root_vagrantfile = path.join(name).to_s
  end
  @config_loader = Config::Loader.new(
    Config::VERSIONS, Config::VERSIONS_ORDER)
  @config_loader.set(:root, root_vagrantfile) if root_vagrantfile
  @config_loader
end

#default_provider(**opts) ⇒ Object



113
114
115
# File 'lib/vagrant/environment/remote.rb', line 113

def default_provider(**opts)
  client.default_provider(**opts)
end

#get_target(name, provider) ⇒ Object

Gets a target (machine) by name

return [VagrantPlugins::CommandServe::Client::Machine]

Parameters:

  • machine (String)

    name

  • provider (String)

    name



122
123
124
# File 'lib/vagrant/environment/remote.rb', line 122

def get_target(name, provider)
  client.target(name, provider)
end

#hostClass

Returns the host object associated with this environment.

Returns:

  • (Class)


129
130
131
132
133
134
135
# File 'lib/vagrant/environment/remote.rb', line 129

def host
  if !@host
    h = @client.host
    @host = Vagrant::Host.new(h, nil, nil, self)
  end
  @host
end

#initialize(opts = {}) ⇒ Object

Client can be either a Project or a Basis



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vagrant/environment/remote.rb', line 17

def initialize(opts={})
  @client = opts[:client]
  if @client.nil?
    raise ArgumentError,
      "Remote client is required for `#{self.class.name}'"
  end

  @logger = Log4r::Logger.new("vagrant::environment")

  # Set the default ui class
  opts[:ui_class] ||= UI::Remote

  @cwd = Pathname.new(@client.cwd)
  @home_path = @client.respond_to?(:home) && Pathname.new(@client.home)
  @vagrantfile_name = @client.respond_to?(:vagrantfile_name) && Array(@client.vagrantfile_name)
  @ui = opts.fetch(:ui, opts[:ui_class].new(@client.ui))
  @local_data_path = Pathname.new(@client.local_data)
  @boxes_path = @home_path && @home_path.join("boxes")
  @data_dir = Pathname.new(@client.data_dir)
  @gems_path = Vagrant::Bundler.instance.plugin_gem_path
  @tmp_path = Pathname.new(@client.temp_dir)

  # This is the batch lock, that enforces that only one {BatchAction}
  # runs at a time from {#batch}.
  @batch_lock = Mutex.new
  @locks = {}

  @logger.info("Environment initialized (#{self})")
  @logger.info("  - cwd: #{cwd}")
  @logger.info("  - home path: #{home_path}")

  # TODO: aliases
  @aliases_path = Pathname.new(ENV["VAGRANT_ALIAS_FILE"]).expand_path if ENV.key?("VAGRANT_ALIAS_FILE")
  @aliases_path ||= @home_path && @home_path.join("aliases")

  @default_private_key_path = Pathname.new(@client.default_private_key)
  @default_private_keys_directory = @home_path.join("insecure_private_keys")
  if !@default_private_keys_directory.directory?
    @default_private_keys_directory.mkdir
  end
  @default_private_key_paths = []

  copy_insecure_private_keys

  # Initialize localized plugins
  plugins = Vagrant::Plugin::Manager.instance.localize!(self)
  # Load any environment local plugins
  Vagrant::Plugin::Manager.instance.load_plugins(plugins)

  # Initialize globalize plugins
  plugins = Vagrant::Plugin::Manager.instance.globalize!
  # Load any global plugins
  Vagrant::Plugin::Manager.instance.load_plugins(plugins)

  plugins = process_configured_plugins

  # Call the hooks that does not require configurations to be loaded
  # by using a "clean" action runner
  hook(:environment_plugins_loaded, runner: Action::PrimaryRunner.new(env: self))

  # Call the environment load hooks
  hook(:environment_load, runner: Action::PrimaryRunner.new(env: self))
end

#machine(name, provider, **_) ⇒ Object

return [Vagrant::Machine]

Parameters:

  • machine (String)

    name



139
140
141
# File 'lib/vagrant/environment/remote.rb', line 139

def machine(name, provider, **_)
  client.machine(name, provider)
end

#machine_indexMachineIndex

The MachineIndex to store information about the machines.

Returns:



150
151
152
# File 'lib/vagrant/environment/remote.rb', line 150

def machine_index
  @machine_index ||= Vagrant::MachineIndex.new(client: client.target_index)
end

#machine_namesObject



143
144
145
# File 'lib/vagrant/environment/remote.rb', line 143

def machine_names
  client.target_names
end

#primary_machine_nameObject



154
155
156
# File 'lib/vagrant/environment/remote.rb', line 154

def primary_machine_name
  client.primary_target_name
end

#setup_home_pathObject

def root_path TODO: need the vagrantfile service to be in place in order to be implemented on the Go side end



163
164
165
166
# File 'lib/vagrant/environment/remote.rb', line 163

def setup_home_path
  # no-op
  # Don't setup a home path in ruby
end

#setup_local_data_path(force = false) ⇒ Object



168
169
170
171
# File 'lib/vagrant/environment/remote.rb', line 168

def setup_local_data_path(force=false)
  # no-op
  # Don't setup a home path in ruby
end

#to_protoObject



177
178
179
# File 'lib/vagrant/environment/remote.rb', line 177

def to_proto
  client.proto
end

#vagrantfileObject



173
174
175
# File 'lib/vagrant/environment/remote.rb', line 173

def vagrantfile
  client.vagrantfile
end