Skip to content

Vagrantfile,.gitignore: Maintain state between vagrant runs. #607

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

Merged
merged 1 commit into from
Nov 9, 2016
Merged

Vagrantfile,.gitignore: Maintain state between vagrant runs. #607

merged 1 commit into from
Nov 9, 2016

Conversation

erikh
Copy link
Contributor

@erikh erikh commented Nov 4, 2016

This patch implements a state tracker for vagrant runs. It does this by saving your current environment to a file called .vagrant-state in the CWD. It then restores that state (if it exists) for each run, allowing you to do any vagrant command without worrying about supplying environment variables to control it. On destroy, the file is removed.

This is sufficiently advanced ruby, so please do focus on the functionality. Perhaps @dseevr would like to review this one as I know he's more than capable of doing so.

Copy link
Contributor

@dseevr dseevr left a comment

Choose a reason for hiding this comment

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

LGTM!

STATEFILE = ".vagrant-state"

if File.exist?(STATEFILE)
File.open(STATEFILE).read.lines.map { |x| x.split("=", 2) }.each { |x,y| ENV[x] = y }
Copy link
Contributor

Choose a reason for hiding this comment

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

File.open("foo").read can be written as File.read("foo") as of 1.9


def self.up_hook(arg)
unless File.exist?(STATEFILE) # prevent it from writing more than once.
f = File.open(STATEFILE, "w")
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also File.write now, so you could do something like:

data = ENV.map { |x,y| "%s=%s" % [x,y] }.join("\n")
File.write(STATEFILE, data)

@erikh
Copy link
Contributor Author

erikh commented Nov 4, 2016

@gaurav-dalvi tested this and @dseevr reviewed. I think this is ready for merge.

@gaurav-dalvi
Copy link
Contributor

LGTM. Thanks @erikh for taking care of this so quickly

@jojimt
Copy link
Contributor

jojimt commented Nov 4, 2016

Once the tests pass, we can merge.

@dseevr
Copy link
Contributor

dseevr commented Nov 5, 2016

@erikh needs a bumparoo

@erikh
Copy link
Contributor Author

erikh commented Nov 9, 2016

ready for merge

@jojimt jojimt merged commit d2ec4ff into contiv:master Nov 9, 2016
@erikh erikh deleted the vagrant-state branch November 10, 2016 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants