Merge pull request #10884 from GregJPreece/feature/10506-machine-readable-status

#10506 - Machine Readable Global-Status
This commit is contained in:
Chris Roberts 2019-06-05 13:54:47 -07:00 committed by GitHub
commit bbf8f05d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View File

@ -19,6 +19,8 @@ between Windows, Mac OS X, and Linux.
## Quick Start
Package dependencies: Vagrant requires `bsdtar` to be available on your system PATH to run successfully.
For the quick-start, we'll bring up a development machine on
[VirtualBox](https://www.virtualbox.org/) because it is free and works
on all major platforms. Vagrant can, however, work with almost any
@ -56,6 +58,14 @@ Once your Vagrant bundle is installed from Git repository, you can run the test
This will run the unit test suite, which should come back all green!
If you are developing Vagrant on a machine that already has a Vagrant package installation present, both will attempt to use the same folder for their configuration (location of this folder depends on system). This can cause errors when Vagrant attempts to load plugins. In this case, override the `VAGRANT_HOME` environment variable for your development version of Vagrant before running any commands, to be some new folder within the project or elsewhere on your machine. For example, in Bash:
export VAGRANT_HOME=~/.vagrant-dev
You can now run Vagrant commands against the development version:
bundle exec vagrant
Please take time to read the [HashiCorp Community Guidelines](https://www.hashicorp.com/community-guidelines) and the [Vagrant Contributing Guide](https://github.com/hashicorp/vagrant/blob/master/.github/CONTRIBUTING.md).
Then you're good to go!

View File

@ -65,6 +65,17 @@ module VagrantPlugins
@env.machine_index.delete(deletable) if deletable
end
# Machine-readable (non-formatted) output
@env.ui.machine("metadata", "machine-count", entries.length.to_s);
entries.each do |entry|
opts = { "target" => entry.name.to_s }
@env.ui.machine("machine-id", entry.id.to_s[0...7], opts)
@env.ui.machine("provider-name", entry.provider.to_s, opts)
@env.ui.machine("machine-home", entry.vagrantfile_path.to_s, opts)
@env.ui.machine("state", entry.state.to_s, opts)
end
# Human-readable (table formatted) output
total_width = 0
columns.each do |header, method|
header = header.ljust(widths[method]) if widths[method]

View File

@ -10,9 +10,11 @@ describe VagrantPlugins::CommandGlobalStatus::Command do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
env.create_vagrant_env(env_opts)
end
let(:env_opts) { {} }
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
let(:argv) { [] }
@ -37,6 +39,38 @@ describe VagrantPlugins::CommandGlobalStatus::Command do
end
end
describe "with --machine-readable" do
let(:env_opts) { {ui_class: Vagrant::UI::MachineReadable} }
before do
iso_env.machine_index.set(new_entry("foo"))
iso_env.machine_index.set(new_entry("bar"))
allow($stdout).to receive(:puts)
end
after { subject.execute }
it "should include the machine id" do
expect($stdout).to receive(:puts).with(/,machine-id,/).twice
end
it "should include the machine state" do
expect($stdout).to receive(:puts).with(/,state,/).twice
end
it "should include the machine count" do
expect($stdout).to receive(:puts).with(/machine-count,2/)
end
it "should include the machine home path" do
expect($stdout).to receive(:puts).with(/,machine-home,/).twice
end
it "should include the provider name" do
expect($stdout).to receive(:puts).with(/,provider-name,/).twice
end
end
describe "execute with --prune" do
let(:argv) { ["--prune"] }