Skip to content

Commit 9d78aac

Browse files
authored
Update README.md (#114)
1 parent 2b7cf6e commit 9d78aac

File tree

1 file changed

+60
-43
lines changed

1 file changed

+60
-43
lines changed

README.md

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ virtual machines (boxes). This module is useful for:
99
- Halting a Vagrant VM without destroying it (`halt`).
1010
- Querying the status of a VM or VMs (`status`).
1111
- Getting ssh configuration information useful for SSHing into the VM. (`host`, `port`, ...)
12-
- Running `vagrant` commands in a multi-VM environment
13-
(http://vagrantup.com/v1/docs/multivm.html) by using `vm_name` parameter.
12+
- Running `vagrant` commands in a [multi-VM environment](http://vagrantup.com/v1/docs/multivm.html)
13+
by using `vm_name` parameter.
1414
- Initializing the VM based on a named base box, using init().
1515
- Adding, Removing, and Listing boxes (`box add`, `box remove`, `box list`).
1616
- Provisioning VMs - up() accepts options like `no_provision`, `provision`, and `provision_with`, and there is a `provision()` method.
17-
- Using sandbox mode from the Sahara gem (https://github.com/jedi4ever/sahara).
17+
- Using sandbox mode from the [Sahara](https://github.com/jedi4ever/sahara) gem.
1818

1919
This project began because I wanted python bindings for Vagrant so I could
2020
programmatically access my vagrant box using Fabric. Drop me a line to let me
@@ -48,51 +48,58 @@ backwards-compatible features or bug fixes are added.
4848

4949
Download and install python-vagrant:
5050

51-
pip install python-vagrant
51+
```shell
52+
pip install python-vagrant
53+
```
5254

5355
### Install from github.com
5456

5557
Clone and install python-vagrant
5658

57-
cd ~
58-
git clone git@github.com:pycontribs/python-vagrant.git
59-
cd python-vagrant
60-
python setup.py install
59+
```shell
60+
cd ~
61+
git clone git@github.com:pycontribs/python-vagrant.git
62+
cd python-vagrant
63+
python setup.py install
64+
```
6165

6266
## Usage
6367

6468
A contrived example of starting a vagrant box (using a Vagrantfile from the
6569
current directory) and running a fabric task on it:
6670

67-
import vagrant
68-
from fabric.api import env, execute, task, run
69-
70-
@task
71-
def mytask():
72-
run('echo $USER')
71+
```python
72+
import vagrant
73+
from fabric.api import env, execute, task, run
7374

75+
@task
76+
def mytask():
77+
run('echo $USER')
7478

75-
v = vagrant.Vagrant()
76-
v.up()
77-
env.hosts = [v.user_hostname_port()]
78-
env.key_filename = v.keyfile()
79-
env.disable_known_hosts = True # useful for when the vagrant box ip changes.
80-
execute(mytask) # run a fabric task on the vagrant host.
79+
v = vagrant.Vagrant()
80+
v.up()
81+
env.hosts = [v.user_hostname_port()]
82+
env.key_filename = v.keyfile()
83+
env.disable_known_hosts = True # useful for when the vagrant box ip changes.
84+
execute(mytask) # run a fabric task on the vagrant host.
85+
```
8186

8287
Another example showing how to use vagrant multi-vm feature with fabric:
8388

84-
import vagrant
85-
from fabric.api import *
86-
87-
@task
88-
def start(machine_name):
89-
"""Starts the specified machine using vagrant"""
90-
v = vagrant.Vagrant()
91-
v.up(vm_name=machine_name)
92-
with settings(host_string= v.user_hostname_port(vm_name=machine_name),
93-
key_filename = v.keyfile(vm_name=machine_name),
94-
disable_known_hosts = True):
95-
run("echo hello")
89+
```python
90+
import vagrant
91+
from fabric.api import *
92+
93+
@task
94+
def start(machine_name):
95+
"""Starts the specified machine using vagrant"""
96+
v = vagrant.Vagrant()
97+
v.up(vm_name=machine_name)
98+
with settings(host_string= v.user_hostname_port(vm_name=machine_name),
99+
key_filename = v.keyfile(vm_name=machine_name),
100+
disable_known_hosts = True):
101+
run("echo hello")
102+
```
96103

97104
By default python vagrant instances are quiet, meaning that they capture stdout
98105
and stderr. For a "loud" instance, use `vagrant.Vagrant(quiet_stdout=False)`.
@@ -113,14 +120,18 @@ using the `out_cm` and `err_cm` parameters, or by using the `quiet_stdout` and
113120

114121
Using `out_cm` and `err_cm` to redirect stdout and stderr to `/dev/null`:
115122

116-
v = vagrant.Vagrant(out_cm=vagrant.devnull_cm, err_cm=vagrant.devnull_cm)
117-
v.up() # normally noisy
123+
```python
124+
v = vagrant.Vagrant(out_cm=vagrant.devnull_cm, err_cm=vagrant.devnull_cm)
125+
v.up() # normally noisy
126+
```
118127

119128
Using `quiet_stdout` and `quiet_stderr` to redirect stdout and stderr to
120129
`/dev/null`:
121130

122-
v = vagrant.Vagrant(quiet_stdout=True, quiet_stderr=True)
123-
v.up() # normally noisy
131+
```python
132+
v = vagrant.Vagrant(quiet_stdout=True, quiet_stderr=True)
133+
v.up() # normally noisy
134+
```
124135

125136
These are functionally equivalent.
126137

@@ -134,9 +145,11 @@ can be accomplished using the `out_cm` and `err_cm` parameters of
134145
For example, log the stdout and stderr of the subprocess to the file
135146
'deployment.log':
136147

137-
log_cm = vagrant.make_file_cm('deployment.log')
138-
v = vagrant.Vagrant(out_cm=log_cm, err_cm=log_cm)
139-
v.up() # normally noisy
148+
```python
149+
log_cm = vagrant.make_file_cm('deployment.log')
150+
v = vagrant.Vagrant(out_cm=log_cm, err_cm=log_cm)
151+
v.up() # normally noisy
152+
```
140153

141154
#### Altering the Environment of the Vagrant Subprocess
142155

@@ -172,8 +185,8 @@ v.up() # will pass env to the vagrant subprocess
172185
## Contribute
173186

174187
If you use python and vagrant and this project does not do what you want,
175-
please open an issue or a pull request on github at
176-
https://github.com/todddeluca/python-vagrant.
188+
please open an issue or a pull request on
189+
[github](https://github.com/pycontribs/python-vagrant/edit/main/README.md).
177190

178191
Please see CHANGELOG.md for a detailed list of contributions and authors.
179192

@@ -187,11 +200,15 @@ downloading boxes and starting and stopping virtual machines several times.
187200

188201
Run the tests from the top-level directory of the repository:
189202

190-
tox -e py
203+
```shell
204+
tox -e py
205+
```
191206

192207
Here is an example of running an individual test:
193208

194-
tox -e py -- -k tests.test_vagrant:test_boxes
209+
```shell
210+
tox -e py -- -k tests.test_vagrant:test_boxes
211+
```
195212

196213
Manual test of functionality for controlling where the vagrant subcommand
197214
output is sent -- console or devnull:

0 commit comments

Comments
 (0)