Exemplo n.º 1
0
    def destroy(self, arguments):
        """
        Stops and deletes all traces of the Mech machine.

        Usage: mech destroy [options] [<instance>]

        Options:
            -f, --force                      Destroy without confirmation.
            -h, --help                       Print this help
        """
        force = arguments['--force']

        instance_name = arguments['<instance>']
        instance_name = self.activate(instance_name)

        if instance_name:
            instance = utils.settle_instance(instance_name)
            path = instance['path']
        else:
            path = os.getcwd()
        mech_path = os.path.join(path, '.mech')

        if os.path.exists(mech_path):
            if force or utils.confirm(
                    "Are you sure you want to delete {instance_name} at {path}"
                    .format(instance_name=instance_name, path=path),
                    default='n'):
                puts_err(colored.green("Deleting..."))
                vmrun = VMrun(self.vmx, user=self.user, password=self.password)
                vmrun.stop(mode='hard', quiet=True)
                time.sleep(3)
                vmrun.deleteVM()
                shutil.rmtree(mech_path)
            else:
                puts_err(colored.red("Deletion aborted"))
        else:
            puts_err(colored.red("The box hasn't been initialized."))
Exemplo n.º 2
0
    def down(self, arguments):
        """
        Stops the Mech machine.

        Usage: mech down [options] [<instance>]

        Options:
                --force                      Force a hard stop
            -h, --help                       Print this help
        """
        force = arguments['--force']

        instance_name = arguments['<instance>']
        instance_name = self.activate(instance_name)

        vmrun = VMrun(self.vmx, user=self.user, password=self.password)
        if not force and vmrun.installedTools():
            stopped = vmrun.stop()
        else:
            stopped = vmrun.stop(mode='hard')
        if stopped is None:
            puts_err(colored.red("Not stopped", vmrun))
        else:
            puts_err(colored.green("Stopped", vmrun))