Class: Vagrant::MachineIndex::Entry
- Inherits:
-
Object
- Object
- Vagrant::MachineIndex::Entry
- Defined in:
- lib/vagrant/machine_index.rb,
lib/vagrant/machine_index/remote.rb
Overview
An entry in the MachineIndex.
Defined Under Namespace
Modules: Remote
Instance Attribute Summary collapse
-
#architecture ⇒ String
The name of the architecture.
-
#extra_data ⇒ Hash
Extra data to store with the index entry.
-
#full_state ⇒ MachineState
The last known state of this machine.
-
#id ⇒ String
readonly
The unique ID for this entry.
-
#local_data_path ⇒ Pathname
The path for the "local data" directory for the environment.
-
#name ⇒ String
The name of the machine.
-
#provider ⇒ String
The name of the provider.
-
#state ⇒ String
The last known state of this machine.
-
#updated_at ⇒ DateTime
readonly
The last time this entry was updated.
-
#vagrantfile_name ⇒ Array<String>
The valid Vagrantfile filenames for this environment.
-
#vagrantfile_path ⇒ Pathname
The path to the Vagrantfile that manages this machine.
Instance Method Summary collapse
-
#initialize(id = nil, raw = nil) ⇒ Entry
constructor
Initializes an entry.
-
#to_json_struct ⇒ Object
Converts to the structure used by the JSON.
-
#vagrant_env(home_path, opts = {}) ⇒ Vagrant::Environment
Creates a Environment for this entry.
-
#valid?(home_path) ⇒ Boolean
Returns boolean true if this entry appears to be valid.
Constructor Details
#initialize(id = nil, raw = nil) ⇒ Entry
Initializes an entry.
The parameter given should be nil if this is being created publicly.
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/vagrant/machine_index.rb', line 425 def initialize(id=nil, raw=nil) @logger = Log4r::Logger.new("vagrant::machine_index::entry") @extra_data = {} @id = id # Do nothing if we aren't given a raw value. Otherwise, parse it. return if !raw @local_data_path = raw["local_data_path"] @name = raw["name"] @provider = raw["provider"] @architecture = raw["architecture"] @state = raw["state"] @full_state = raw["full_state"] @vagrantfile_name = raw["vagrantfile_name"] @vagrantfile_path = raw["vagrantfile_path"] # TODO(mitchellh): parse into a proper datetime @updated_at = raw["updated_at"] @extra_data = raw["extra_data"] || {} # Be careful with the paths @local_data_path = nil if @local_data_path == "" @vagrantfile_path = nil if @vagrantfile_path == "" # Convert to proper types @local_data_path = Pathname.new(@local_data_path) if @local_data_path @vagrantfile_path = Pathname.new(@vagrantfile_path) if @vagrantfile_path end |
Instance Attribute Details
#architecture ⇒ String
The name of the architecture.
388 389 390 |
# File 'lib/vagrant/machine_index.rb', line 388 def architecture @architecture end |
#extra_data ⇒ Hash
Extra data to store with the index entry. This can be anything and is treated like a general global state bag.
419 420 421 |
# File 'lib/vagrant/machine_index.rb', line 419 def extra_data @extra_data end |
#full_state ⇒ MachineState
The last known state of this machine.
398 399 400 |
# File 'lib/vagrant/machine_index.rb', line 398 def full_state @full_state end |
#id ⇒ String (readonly)
The unique ID for this entry. This is not the ID for the machine itself (which is provider-specific and in the data directory).
368 369 370 |
# File 'lib/vagrant/machine_index.rb', line 368 def id @id end |
#local_data_path ⇒ Pathname
The path for the "local data" directory for the environment.
373 374 375 |
# File 'lib/vagrant/machine_index.rb', line 373 def local_data_path @local_data_path end |
#name ⇒ String
The name of the machine.
378 379 380 |
# File 'lib/vagrant/machine_index.rb', line 378 def name @name end |
#provider ⇒ String
The name of the provider.
383 384 385 |
# File 'lib/vagrant/machine_index.rb', line 383 def provider @provider end |
#state ⇒ String
The last known state of this machine.
393 394 395 |
# File 'lib/vagrant/machine_index.rb', line 393 def state @state end |
#updated_at ⇒ DateTime (readonly)
The last time this entry was updated.
413 414 415 |
# File 'lib/vagrant/machine_index.rb', line 413 def updated_at @updated_at end |
#vagrantfile_name ⇒ Array<String>
The valid Vagrantfile filenames for this environment.
403 404 405 |
# File 'lib/vagrant/machine_index.rb', line 403 def vagrantfile_name @vagrantfile_name end |
#vagrantfile_path ⇒ Pathname
The path to the Vagrantfile that manages this machine.
408 409 410 |
# File 'lib/vagrant/machine_index.rb', line 408 def vagrantfile_path @vagrantfile_path end |
Instance Method Details
#to_json_struct ⇒ Object
Converts to the structure used by the JSON
515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/vagrant/machine_index.rb', line 515 def to_json_struct { "local_data_path" => @local_data_path.to_s, "name" => @name, "provider" => @provider, "architecture" => @architecture, "state" => @state, "vagrantfile_name" => @vagrantfile_name, "vagrantfile_path" => @vagrantfile_path.to_s, "updated_at" => @updated_at, "extra_data" => @extra_data, } end |
#vagrant_env(home_path, opts = {}) ⇒ Vagrant::Environment
Creates a Environment for this entry.
503 504 505 506 507 508 509 510 511 512 |
# File 'lib/vagrant/machine_index.rb', line 503 def vagrant_env(home_path, opts={}) Vagrant::Util::SilenceWarnings.silence! do Environment.new({ cwd: @vagrantfile_path, home_path: home_path, local_data_path: @local_data_path, vagrantfile_name: @vagrantfile_name, }.merge(opts)) end end |
#valid?(home_path) ⇒ Boolean
Returns boolean true if this entry appears to be valid. The criteria for being valid:
- Vagrantfile directory exists
- Vagrant environment contains a machine with this name and provider.
This method is slow. It should be used with care.
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/vagrant/machine_index.rb', line 466 def valid?(home_path) return false if !vagrantfile_path return false if !vagrantfile_path.directory? # Create an environment so we can determine the active # machines... found = false env = vagrant_env(home_path) env.active_machines.each do |name, provider| if name.to_s == self.name.to_s && provider.to_s == self.provider.to_s found = true break end end # If an active machine of the same name/provider was not # found, it is already false. return false if !found # Get the machine machine = nil begin machine = env.machine(self.name.to_sym, self.provider.to_sym) rescue Errors::MachineNotFound return false end # Refresh the machine state return false if machine.state.id == MachineState::NOT_CREATED_ID true end |