mitchellh/vagrant — pull request #2005 by fgrehm (2013-07-30 04:38:51+00:00)
Title: Kick off support for host capabilities

# !!WORK IN PROGRESS!!

So I've been willing to use Host capabilities to implement some vagrant-lxc host networking specific setup and I'm signing up for implementing support for this from within Vagrant's core.

Here's an initial list of "goals" and notes I've put up for making this happen (subject to change and open to suggestions of course :)

- [x] Allow plugins to register host capabilities
- [ ] Split Host detection from capabilities
- [ ] Support for checking if host is capable of something
- [ ] Support for calling capabilities
- [ ] Make use of host capabilities from within Vagrant's core

### Allow plugins to register host capabilities (DONE)

Pretty much the same as Guest capabilities:

```ruby
class MyPlugin < Vagrant.plugin("2")
name "My Plugin"

host_capability "ubuntu", "my_host_capability" do
require_relative "cap/my_host_capability"
Cap::MyHostCapability
end
end
```

### Split Host detection from capabilities

The idea would be to change the [current host detection mechanism](https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/hosts.rb) to use the same approach [used for Guests](https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/guest.rb#L37), having the [detection logic](https://github.com/mitchellh/vagrant/blob/master/plugins/guests/arch/guest.rb) separated from the [capabilities](https://github.com/mitchellh/vagrant/tree/master/plugins/guests/arch/cap) themselves and keeping a chain of detected hosts around for later usage when dealing with capabilities.

We might also need to introduce some sort of "[Virtual](https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/guest.rb) Host object" to wrap things up but I'm not sure if we need all of this right now as we can probably just add the functionality to the base class (`Vagrant::Plugin::V2::Host`)

### Support for checking if host is capable of something / calling capabilities

Basically the same as we do for guest capabilities, with the difference that the "entry point" would be an instance of `Vagrant::Environment` instead of a `Vagrant::Machine`.

```ruby
# Checking
environment.host.capability?(:capability_name)
# Calling
environment.host.capability(:capability_name, :arg1, :arg2)
```

The definition would also be similar to guest capabilities, with the difference that the first argument passed in would be an instance of `Vagrant::Environment` instead of a `Vagrant::Machine`.

```ruby
module Cap
class MyCustomCapability
def self.capability_name(environment, arg1, arg2)
# implementation
end
end
end
```

### Make use of host capabilities from within Vagrant's core

Looking around current Host's implementation, the only candidates to be converted into Host Capabilities are [NFS related stuff](https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/plugin/v2/host.rb#L38-L62).