Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ColdHeat/mech
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdHeat committed Aug 21, 2017
2 parents 3311d43 + 23282a6 commit 82df593
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ Options:
--debug Show debug messages.
```

`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.
`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.

# Install

`pip install git+https://github.com/ColdHeat/mech.git` for the lastest or `pip install mech` for what I last pushed to PyPi

# Shared Folders

If the box you init was created properly, you will be able to access the host's current working directory in `/mnt/hgfs/mech`.
2 changes: 1 addition & 1 deletion mech/mech.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def stop(self):
vm = Vmrun(self.vmx)
vm.stop()
puts(colored.green("Stopped", vm))
puts(colored.yellow("Getting IP address..."))


def pause(self):
vm = Vmrun(self.vmx)
Expand Down
38 changes: 35 additions & 3 deletions mech/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import json
import tempfile
import collections


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


def parse_vmx(path):
vmx = collections.OrderedDict()
with open(path) as f:
for line in f:
line = line.strip().split('=', 1)
vmx[line[0]] = line[1]
return vmx


def rewrite_vmx(path):
vmx = parse_vmx(path)
vmx["ethernet0.addresstype"] = "generated"
vmx["ethernet0.bsdname"] = "en0"
vmx["ethernet0.connectiontype"] = "nat"
vmx["ethernet0.displayname"] = "Ethernet"
vmx["ethernet0.linkstatepropagation.enable"] = "FALSE"
vmx["ethernet0.pcislotnumber"] = "32"
vmx["ethernet0.present"] = "TRUE"
vmx["ethernet0.virtualdev"] = "e1000"
vmx["ethernet0.wakeonpcktrcv"] = "FALSE"
with open(path, 'w') as new_vmx:
for key in vmx:
value = vmx[key]
row = "{}={}".format(key, value)
new_vmx.write(row + os.linesep)
return True


def load_mechfile(name=None):
if name:
mechfile = os.path.join(HOME, name, 'mechfile')
Expand Down Expand Up @@ -82,14 +111,16 @@ def setup_url(url, name):
path = os.path.join(HOME, name)
os.mkdir(os.path.join(HOME, name), 0755)

vmx_path = os.path.join(path, vmx)
config = {
'vmx':os.path.join(path, vmx),
'vmx':vmx_path,
'url':url,
'user': prompt.query("What username would you like to save?", default='mech')
}
tar.extractall(path)
save_mechfile(config, path)
save_mechfile(config, '.')
rewrite_vmx(vmx_path)
return os.path.join(path, vmx)
return os.path.abspath(path)

Expand All @@ -116,13 +147,15 @@ def setup_tar(filename, name):
path = os.path.join(HOME, name)
os.mkdir(os.path.join(HOME, name), 0755)
tar.extractall(path)
vmx_path = os.path.join(path, vmx)
config = {
'vmx': os.path.join(path, vmx),
'vmx': vmx_path,
'url': None,
'user': prompt.query("What username would you like to save?", default='mech')
}
save_mechfile(config, path)
save_mechfile(config, '.')
rewrite_vmx(vmx_path)
return os.path.join(path, vmx)


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

while True:
input = raw_input(prompt).strip()
print input
if input == '':
if default == 'y':
return True
Expand Down
16 changes: 16 additions & 0 deletions mech/vmrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,21 @@ def clone( self, dest_vmx, mode, snap_name='binjo' ):
'''
return self.vmrun( 'clone', dest_vmx, mode, snap_name )

def check_tools(self):
'''
checkToolsState Path to vmx file Check the current Tools state
'''
state = self.vmrun('checkToolsState')
if state == 'installed':
return True
else:
return False

def install_tools(self):
'''
installTools Path to vmx file Install Tools in Guest
'''
return self.vmrun('installTools')

if __name__ == '__main__':
print 'Hello World'

0 comments on commit 82df593

Please sign in to comment.