@@ -9,12 +9,12 @@ virtual machines (boxes). This module is useful for:
9
9
- Halting a Vagrant VM without destroying it (` halt ` ).
10
10
- Querying the status of a VM or VMs (` status ` ).
11
11
- 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.
14
14
- Initializing the VM based on a named base box, using init().
15
15
- Adding, Removing, and Listing boxes (` box add ` , ` box remove ` , ` box list ` ).
16
16
- 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 .
18
18
19
19
This project began because I wanted python bindings for Vagrant so I could
20
20
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.
48
48
49
49
Download and install python-vagrant:
50
50
51
- pip install python-vagrant
51
+ ``` shell
52
+ pip install python-vagrant
53
+ ```
52
54
53
55
### Install from github.com
54
56
55
57
Clone and install python-vagrant
56
58
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
+ ```
61
65
62
66
## Usage
63
67
64
68
A contrived example of starting a vagrant box (using a Vagrantfile from the
65
69
current directory) and running a fabric task on it:
66
70
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
73
74
75
+ @task
76
+ def mytask ():
77
+ run(' echo $USER' )
74
78
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
+ ```
81
86
82
87
Another example showing how to use vagrant multi-vm feature with fabric:
83
88
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
+ ```
96
103
97
104
By default python vagrant instances are quiet, meaning that they capture stdout
98
105
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
113
120
114
121
Using ` out_cm ` and ` err_cm ` to redirect stdout and stderr to ` /dev/null ` :
115
122
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
+ ```
118
127
119
128
Using ` quiet_stdout ` and ` quiet_stderr ` to redirect stdout and stderr to
120
129
` /dev/null ` :
121
130
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
+ ```
124
135
125
136
These are functionally equivalent.
126
137
@@ -134,9 +145,11 @@ can be accomplished using the `out_cm` and `err_cm` parameters of
134
145
For example, log the stdout and stderr of the subprocess to the file
135
146
'deployment.log':
136
147
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
+ ```
140
153
141
154
#### Altering the Environment of the Vagrant Subprocess
142
155
@@ -172,8 +185,8 @@ v.up() # will pass env to the vagrant subprocess
172
185
## Contribute
173
186
174
187
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 ) .
177
190
178
191
Please see CHANGELOG.md for a detailed list of contributions and authors.
179
192
@@ -187,11 +200,15 @@ downloading boxes and starting and stopping virtual machines several times.
187
200
188
201
Run the tests from the top-level directory of the repository:
189
202
190
- tox -e py
203
+ ``` shell
204
+ tox -e py
205
+ ```
191
206
192
207
Here is an example of running an individual test:
193
208
194
- tox -e py -- -k tests.test_vagrant:test_boxes
209
+ ``` shell
210
+ tox -e py -- -k tests.test_vagrant:test_boxes
211
+ ```
195
212
196
213
Manual test of functionality for controlling where the vagrant subcommand
197
214
output is sent -- console or devnull:
0 commit comments