def up(self, arguments): """ Starts and provisions the mech environment. Usage: mech up [options] [<instance>] Options: --gui Start GUI --provision Enable provisioning --insecure Do not validate SSL certificates --cacert FILE CA certificate for SSL download --capath DIR CA certificate directory for SSL download --cert FILE A client SSL cert, if needed --checksum CHECKSUM Checksum for the box --checksum-type TYPE Checksum type (md5, sha1, sha256) --no-cache Do not save the downloaded box -h, --help Print this help """ gui = arguments['--gui'] save = not arguments['--no-cache'] requests_kwargs = utils.get_requests_kwargs(arguments) instance_name = arguments['<instance>'] instance_name = self.activate(instance_name) utils.index_active_instance(instance_name) vmx = utils.init_box(self.box_name, self.box_version, requests_kwargs=requests_kwargs, save=save) vmrun = VMrun(vmx, user=self.user, password=self.password) puts_err(colored.blue("Bringing machine up...")) started = vmrun.start(gui=gui) if started is None: puts_err(colored.red("VM not started")) else: time.sleep(3) puts_err(colored.blue("Getting IP address...")) lookup = self.get("enable_ip_lookup", False) ip = vmrun.getGuestIPAddress(lookup=lookup) puts_err(colored.blue("Sharing current folder...")) vmrun.enableSharedFolders() vmrun.addSharedFolder('mech', os.getcwd(), quiet=True) if ip: if started: puts_err(colored.green("VM started on {}".format(ip))) else: puts_err( colored.yellow( "VM was already started on {}".format(ip))) else: if started: puts_err( colored.green("VM started on an unknown IP address")) else: puts_err( colored.yellow( "VM was already started on an unknown IP address"))
def resume(self, arguments): """ Resume a paused/suspended Mech machine. Usage: mech resume [options] [<instance>] Options: --provision Enable provisioning -h, --help Print this help """ instance_name = arguments['<instance>'] instance_name = self.activate(instance_name) utils.index_active_instance(instance_name) vmrun = VMrun(self.vmx, user=self.user, password=self.password) # Try to unpause if vmrun.unpause(quiet=True) is not None: time.sleep(1) puts_err(colored.blue("Getting IP address...")) lookup = self.get("enable_ip_lookup", False) ip = vmrun.getGuestIPAddress(lookup=lookup) if ip: puts_err(colored.green("VM resumed on {}".format(ip))) else: puts_err(colored.green("VM resumed on an unknown IP address")) # Otherwise try starting else: started = vmrun.start() if started is None: puts_err(colored.red("VM not started")) else: time.sleep(3) puts_err(colored.blue("Getting IP address...")) lookup = self.get("enable_ip_lookup", False) ip = vmrun.getGuestIPAddress(lookup=lookup) puts_err(colored.blue("Sharing current folder...")) vmrun.enableSharedFolders() vmrun.addSharedFolder('mech', os.getcwd(), quiet=True) if ip: if started: puts_err(colored.green("VM started on {}".format(ip))) else: puts_err( colored.yellow( "VM already was started on {}".format(ip))) else: if started: puts_err( colored.green( "VM started on an unknown IP address")) else: puts_err( colored.yellow( "VM already was started on an unknown IP address" ))