def ensure_vm_running(self, vm_location):
import vagrant<EOL>if self.vagrant is None:<EOL><INDENT>vagrant_file = vm_location / "<STR_LIT>"<EOL>if not vagrant_file.exists():<EOL><INDENT>self.init_vagrant(vagrant_file)<EOL><DEDENT>self.vagrant = vagrant.Vagrant(vm_location,<EOL>quiet_stdout=self.quiet,<EOL>quiet_stderr=self.quiet,<EOL>out_cm=self.log_cm,<EOL>err_cm=self.log_cm)<EOL><DEDENT>status = [x for x in self.vagrant.status() if x.name == "<STR_LIT:default>"][<NUM_LIT:0>]<EOL>if status.state != "<STR_LIT>":<EOL><INDENT>try:<EOL><INDENT>self.vagrant.up()<EOL><DEDENT>except subprocess.CalledProcessError:<EOL><INDENT>raise BuildError("<STR_LIT>")<EOL><DEDENT><DEDENT>
Gets or creates a Vagrantfile in ``vm_location`` and calls ``vagrant up`` if the VM is not running.