Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#10506 - Machine Readable Global-Status #10884

Merged
merged 12 commits into from
Jun 5, 2019
Merged

#10506 - Machine Readable Global-Status #10884

merged 12 commits into from
Jun 5, 2019

Conversation

SilverPreece
Copy link
Contributor

As noted in #10506, the vagrant global-status --machine-readable command produces a rather unhelpful format for machine processing. It does not specify any @ui.machine outputs, only @ui.info, meaning that the formatted table outputted by this command is fudged into a series of machine-readable lines that are difficult to parse and not particularly useful. This PR adds @ui.machine calls alongside them, to make parsing the output of this command much easier, and consistent with similar commands such as vagrant status --machine-readable.

Before:

1559265195,,ui,info,id       
1559265195,,ui,info,name    
1559265195,,ui,info,provider   
1559265195,,ui,info,state    
1559265195,,ui,info,directory                                                        
1559265195,,ui,info,
1559265195,,ui,info,------------------------------------------------------------------------------------------------------
1559265195,,ui,info,2e5afa9  
1559265195,,ui,info,default 
1559265195,,ui,info,virtualbox 
1559265195,,ui,info,poweroff 
1559265195,,ui,info,/path/to/vagrant/file 
1559265195,,ui,info,
1559265195,,ui,info, \nThe above shows information about all known Vagrant environments\non this machine. This data is cached and may not be completely\nup-to-date (use "vagrant global-status --prune" to prune invalid\nentries). To interact with any of the machines%!(VAGRANT_COMMA) you can go to that\ndirectory and run Vagrant%!(VAGRANT_COMMA) or you can use the ID directly with\nVagrant commands from any directory. For example:\n"vagrant destroy 1a2b3c4d"

After:

1559265166,,metadata,machine-count,1
1559265166,,machine-id,62cfe71
1559265166,,provider-name,virtualbox
1559265166,,machine-home,/path/to/vagrant/file
1559265166,,state,poweroff

Please see the comments for a request for info re: suppressing UI output

I am currently writing a build system wrapper for Vagrant, so I will be using the machine-readable option on most of the available Vagrant commands. If Hashicorp are receptive to patches along similar lines to this one, I would like to help clean up the machine-readable mode and make it more consistent. It's a very useful mode to have, and makes integrating Vagrant with automation/build tools much easier.

@hashicorp-cla
Copy link

hashicorp-cla commented May 31, 2019

CLA assistant check
All committers have signed the CLA.

lib/vagrant/ui.rb Outdated Show resolved Hide resolved
@briancain
Copy link
Member

Hey there @GregJPreece - Thanks for taking the time to make a pull request with Vagrant!

While generally I do agree that the --machine-readable flag needs some love and attention, I don't think we should be removing the ui output as a default behavior. I can only imagine how many users at this point have built up automation around being able to read in the UI level (like for errors) and parse what vagrant prints. Removing this context completely will break those users tools, so I'm 👎 here on removing it.

One enhancement that could be worth making is having a difference between "messages" and general output, but I'm not entirely sure how to do that without adding more columns and keeping it consistent with how it works now 🤔

@SilverPreece
Copy link
Contributor Author

Indeed, as mentioned in my comment I'm not myself in favour of breaking current default behaviour, but I'm not familiar enough with Ruby or Vagrant to know how to get a flag check into the UI lib function. Do you have any suggestions?

Copy link
Member

@chrisroberts chrisroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @GregJPreece, thanks for this PR! I am 👍 on the updates to make the output of the global-status command more useful when in machine readable mode. I don't think there's any reason to remove ui outputs (and mentioned that in the review). Otherwise, there's just a few things to be adjusted and this PR should be good to go.

Cheers!

README.md Show resolved Hide resolved
lib/vagrant/ui.rb Outdated Show resolved Hide resolved
plugins/commands/global-status/command.rb Show resolved Hide resolved
true
}
it "does not output UI type to the machine-readable output" do
expect(subject).to receive(:safe_puts).never
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would expect the UI output to still be included within the machine readable output. A new test should also be added which validates the new machine readable content is output as expected.

Copy link
Member

@chrisroberts chrisroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates. Everything looks great. I did toss in some test coverage on the new behavior, just FYI.

Cheers!

@chrisroberts chrisroberts merged commit bbf8f05 into hashicorp:master Jun 5, 2019
@SilverPreece
Copy link
Contributor Author

SilverPreece commented Jun 5, 2019

Thanks for the updates. Everything looks great. I did toss in some test coverage on the new behavior, just FYI.

Cheers!

You beat me to it! I was going to figure those out this evening. Thanks for taking care of that for me. I may have similar patches to come, based on my experiences with machine-readable mode & automation. I'll keep the comments raised on this PR in mind for those.

@ghost
Copy link

ghost commented Jan 28, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants