def _check_before_rename(self):
        from dvc.machine import validate_name

        validate_name(self.args.new)

        all_config = self.config.load_config_to_level(None)
        if self.args.new in all_config.get("machine", {}):
            raise ConfigError(
                "Rename failed. Machine '{}' already exists.".format(
                    self.args.new
                )
            )
        ui.write(f"Rename machine '{self.args.name}' to '{self.args.new}'.")