We should rethink how we use aliases, as I've been considering how to make this bit more useful, and more in-line with Drush's usual usage of aliases. Originally, I'd intended to use Provision's context system, but it just didn't appear to be worth the effort.
Aliases are saved as a group alias, named after the project (e.g., @project1), with an alias for each VM (e.g., @project1.vm1, @project1.vm2, &c.), and another to specify the project itself (e.g., @project1.project). The idea was to be able to run commands on:
- each vm individually, by using it's alias
- all vms within project, by using the group alias
- the project itself, by using the project alias (i.e., @example.project)
The bit of code that was causing the initial problem was to remove the project alias from the site-list, so that we could accomplish (2).
I think a better solution might be to merge (2) and (3), by specifying which commands operate on the project as a whole (e.g., vagrant-delete, vagrant-aliases, &c.) vs. those meant to operate on individual VMs (vagrant-shell & most native vagrant commands). This could become a maintenance nightmare though, and I don't see any way to reasonably manage commands provided by Vagrant extensions.
Another approach would be to use the group alias as the project alias (which could be tricky to implement), and then add some other method for calling a command on all VMs (such as an @example.all alias). This could turn out to be counter-intuitive for more experienced Drush users, who would probably expect the group alias to act that way...
At very least, reworking the existing code to not interfere with non-vagrant aliases would probably be worthwhile.
Comments
Comment #1
clemens.tolboomAha ... this has to do with the use of an @alias
Comment #2
ergonlogicIndeed, the relevant code in vagrant.drush.load.inc is:
The idea here was to remove the 'project' alias from the site-list, so that we could use the group alias to run commands on all VMs. For the time-being, I've just commented it out, since it doesn't accomplish much of use at this point.
Comment #3
ergonlogicWhile I'd like to figure out a better solution,
This line was a quick hack, and the part that most needs replacing:
Unless things have changed in Drush 5.x, any manipulation of aliases has to happen in hook_drush_load(), at which point we have very minimal context. Perhaps we could add a global option to the alias file that we can test for, to ensure we're only messing with drush-vagrant aliases...
Comment #4
ergonlogicThe original issue should be fixed in http://drupalcode.org/project/drush-vagrant.git/commit/4f4364991c25ea183...
We just check that we're in a group alias and that the 'project-path' option is set in the alias, which should uniquely identify drush-vagrant aliases.
So what remains is to test that this now works with custom aliases, and seeing if we can come up with a better use of aliases.
Comment #5
ergonlogicIn http://drupal.org/node/1779866#comment-6457526, Steven points out that the command array can be extended pretty much however we like. This seems like a good way to proceed with:
So, adding a 'vagrant_scope' parameter that defaults to 'vm', but that allows us to specify 'project' seems like a good start. With that, we can call @project_alias, dropping the '.project', and generally get the desired behaviour. Assuming a vm scope will have drush-vagrant dispatch batch operations, rather than letting Vagrant figure that out on its own, but since we do still have the @project_alias.project notation available, we can override it.
To do so, we'll need to remove @project_alias.project from the 'site list', since it'll likely fail whenever we're calling a batch operation. Ideally we'd remove them from 'drush sa' listings too, since they're just clutter now.
Comment #6
ergonlogicI think we should do this in vagrant_drush_init():
It would load the alias when we are in a project. This would, in turn, allow us to prompt for the VM, if given a command that should only apply to a VM.
Comment #7
ergonlogicWe now load an alias (if available) whenever we're in (or under) a Vagrant project.
Comment #7.0
ergonlogicupdate summary to address the underlying issue