Skip to content

Commit 82df593

Browse files
committed
Merge branch 'master' of github.com:ColdHeat/mech
2 parents 3311d43 + 23282a6 commit 82df593

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ Options:
2727
--debug Show debug messages.
2828
```
2929

30-
`mech init` can be used to pull a box file which will be installed and generate a mechfile in the current directory. Barring that, `mech up <name>` can also be used to specify a vmx file to start.
30+
`mech init` can be used to pull a box file which will be installed and generate a mechfile in the current directory. You can also pull boxes from Vagrant Cloud with `mech init bento/ubuntu-14.04`. Barring that, `mech up <name>` can also be used to specify a vmx file to start.
3131

3232
# Install
3333

3434
`pip install git+https://github.com/ColdHeat/mech.git` for the lastest or `pip install mech` for what I last pushed to PyPi
35+
36+
# Shared Folders
37+
38+
If the box you init was created properly, you will be able to access the host's current working directory in `/mnt/hgfs/mech`.

mech/mech.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def stop(self):
8484
vm = Vmrun(self.vmx)
8585
vm.stop()
8686
puts(colored.green("Stopped", vm))
87-
puts(colored.yellow("Getting IP address..."))
87+
8888

8989
def pause(self):
9090
vm = Vmrun(self.vmx)

mech/utils.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import json
1414
import tempfile
15+
import collections
1516

1617

1718
HOME = os.path.expanduser("~/.mech")
@@ -25,6 +26,34 @@ def locate_vmx(vm_name):
2526
return None
2627

2728

29+
def parse_vmx(path):
30+
vmx = collections.OrderedDict()
31+
with open(path) as f:
32+
for line in f:
33+
line = line.strip().split('=', 1)
34+
vmx[line[0]] = line[1]
35+
return vmx
36+
37+
38+
def rewrite_vmx(path):
39+
vmx = parse_vmx(path)
40+
vmx["ethernet0.addresstype"] = "generated"
41+
vmx["ethernet0.bsdname"] = "en0"
42+
vmx["ethernet0.connectiontype"] = "nat"
43+
vmx["ethernet0.displayname"] = "Ethernet"
44+
vmx["ethernet0.linkstatepropagation.enable"] = "FALSE"
45+
vmx["ethernet0.pcislotnumber"] = "32"
46+
vmx["ethernet0.present"] = "TRUE"
47+
vmx["ethernet0.virtualdev"] = "e1000"
48+
vmx["ethernet0.wakeonpcktrcv"] = "FALSE"
49+
with open(path, 'w') as new_vmx:
50+
for key in vmx:
51+
value = vmx[key]
52+
row = "{}={}".format(key, value)
53+
new_vmx.write(row + os.linesep)
54+
return True
55+
56+
2857
def load_mechfile(name=None):
2958
if name:
3059
mechfile = os.path.join(HOME, name, 'mechfile')
@@ -82,14 +111,16 @@ def setup_url(url, name):
82111
path = os.path.join(HOME, name)
83112
os.mkdir(os.path.join(HOME, name), 0755)
84113

114+
vmx_path = os.path.join(path, vmx)
85115
config = {
86-
'vmx':os.path.join(path, vmx),
116+
'vmx':vmx_path,
87117
'url':url,
88118
'user': prompt.query("What username would you like to save?", default='mech')
89119
}
90120
tar.extractall(path)
91121
save_mechfile(config, path)
92122
save_mechfile(config, '.')
123+
rewrite_vmx(vmx_path)
93124
return os.path.join(path, vmx)
94125
return os.path.abspath(path)
95126

@@ -116,13 +147,15 @@ def setup_tar(filename, name):
116147
path = os.path.join(HOME, name)
117148
os.mkdir(os.path.join(HOME, name), 0755)
118149
tar.extractall(path)
150+
vmx_path = os.path.join(path, vmx)
119151
config = {
120-
'vmx': os.path.join(path, vmx),
152+
'vmx': vmx_path,
121153
'url': None,
122154
'user': prompt.query("What username would you like to save?", default='mech')
123155
}
124156
save_mechfile(config, path)
125157
save_mechfile(config, '.')
158+
rewrite_vmx(vmx_path)
126159
return os.path.join(path, vmx)
127160

128161

@@ -147,7 +180,6 @@ def confirm(prompt, default='y'):
147180

148181
while True:
149182
input = raw_input(prompt).strip()
150-
print input
151183
if input == '':
152184
if default == 'y':
153185
return True

mech/vmrun.py

+16
Original file line numberDiff line numberDiff line change
@@ -476,5 +476,21 @@ def clone( self, dest_vmx, mode, snap_name='binjo' ):
476476
'''
477477
return self.vmrun( 'clone', dest_vmx, mode, snap_name )
478478

479+
def check_tools(self):
480+
'''
481+
checkToolsState Path to vmx file Check the current Tools state
482+
'''
483+
state = self.vmrun('checkToolsState')
484+
if state == 'installed':
485+
return True
486+
else:
487+
return False
488+
489+
def install_tools(self):
490+
'''
491+
installTools Path to vmx file Install Tools in Guest
492+
'''
493+
return self.vmrun('installTools')
494+
479495
if __name__ == '__main__':
480496
print 'Hello World'

0 commit comments

Comments
 (0)