Vagrant commands should be able to output machine-readable format #1098

Closed
foxx opened this Issue Sep 3, 2012 · 10 comments

Projects

None yet

5 participants

@foxx

It would be nice if the vagrant commands themselves were scriptable.

For example:

 root@envprov1 [/mnt/ds1/vagrant/projects/pm2] > vagrant status
Current VM states:

prodclone1               not created
slice21                  running

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

Trying to filter through that requires a not very sane approach, it would be better if you had something like:

 root@envprov1 [/mnt/ds1/vagrant/projects/pm2] > vagrant status -t
prodclone1,not created
slice21,running

I.e. making the output script friendly.

Thoughts?

@foxx

For example, to convert this:

Current VM states:

prodclone1               not created
slice21                  running

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

Into this:

[('prodclone1', 'not created'), ('slice21', 'running')]

Required the following python code:

        _slices = self._execute("vagrant status")
        _slices = _slices.split("\n\n", 2)
        _slices = _slices[1]
        _slices = _slices.split("\n")
        _slices = map(lambda x: x.split(" ", 1), _slices)
        _slices = map(lambda x: (x[0].strip(), x[1].strip()), _slices)
        print _slices

Although it is scriptable, it's not exactly clean/sane, and any future changes to status command output could break this.

@patcon

Good call. json output would be nifty :)

@mitchellh
Owner

I agree. Marking this as a feature requests, and I changed the subject a little bit.

I think I'd rather output in a format that is easily sliceable with unix tools, so: not JSON. Line-oriented output separated by a delimiter or whitespace would be best so you can grep/awk/sed it.

@foxx

+1 for grep/awk/sed friendly.

@patcon

👍

@michaeltwofish

*nix tool friendly status output would be great.

In the meantime, this awk script works for my purposes, relying on only the blank line around the statuses.

vagrant status|awk '/^$/ {stat = !stat;next}; stat == 1 {print}'
@zpatten

@mitchellh Do you have an ETA on this? Based on your comments on my Cucumber-Chef project I had expected, at minimum, a basic implementation of this with the "new" vagrant. I have not been able to find this functionality in the latest release of vagrant (i.e. 1.1.2). Am I missing something obvious? Thanks in advance!

@mitchellh
Owner

I would've loved to have had it in 1.1, but I had to cut the release at some point, and it was already a pretty huge release. At this point I'm targeting 1.3, but will put it into 1.2 if I find time.

@zpatten

Awesome; sounds good! I know how it goes, was just curious as to the status of it; as long as it is still on your radar :)

Thanks for the quick response!

@mitchellh
Owner

This is done!

@mitchellh mitchellh closed this Nov 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment