diff --git a/README.md b/README.md index ef5894d..e47d538 100644 --- a/README.md +++ b/README.md @@ -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 ` 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 ` 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`. diff --git a/mech/mech.py b/mech/mech.py index b98dc42..043bf7b 100644 --- a/mech/mech.py +++ b/mech/mech.py @@ -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) diff --git a/mech/utils.py b/mech/utils.py index 6b31c1b..50f711a 100644 --- a/mech/utils.py +++ b/mech/utils.py @@ -12,6 +12,7 @@ import os import json import tempfile +import collections HOME = os.path.expanduser("~/.mech") @@ -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') @@ -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) @@ -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) @@ -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 diff --git a/mech/vmrun.py b/mech/vmrun.py index 34827b9..e0de03e 100644 --- a/mech/vmrun.py +++ b/mech/vmrun.py @@ -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'