Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for host capabilities #2005

Closed
wants to merge 2 commits into from
Closed

Support for host capabilities #2005

wants to merge 2 commits into from

Conversation

fgrehm
Copy link
Contributor

@fgrehm fgrehm commented Jul 30, 2013

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 :)

  • 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:

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 to use the same approach used for Guests, having the detection logic separated from the capabilities 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 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.

# 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.

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.

@fgrehm
Copy link
Contributor Author

fgrehm commented Jul 30, 2013

So, while I could go ahead and copy & paste the current guest capabilities code to implement this I was wondering if we should have some sort of abstraction to deal with common logic (like looking up and calling capabilities for example)

@mitchellh WDYT?

@mitchellh
Copy link
Contributor

I like this a lot. Yeah, I think lib/vagrant/guest.rb could easily be abstracted into a single class that implements all capability stuff. This is definitely on the right track.

@fgrehm
Copy link
Contributor Author

fgrehm commented Aug 29, 2013

@mitchellh awesome! I'll rebase this branch against current master and will continue working on it later on :)

@fgrehm
Copy link
Contributor Author

fgrehm commented Sep 17, 2013

@mitchellh I did some work on this over the weekend but forgot to push :P In order to keep things simple I ended up copying and pasting Guest code over to the new Host object so that we can have a better idea of what exactly can be abstracted and it is now pretty clear to me. I'm "test driving" it with the code you can find on this gist if you want to try things out.

The next step will probably be to do that extraction but I'll need some help with its name as I really can't think of one! I thought of DistroDispatch but neither Windows or OSX have distros :P

@fgrehm
Copy link
Contributor Author

fgrehm commented Nov 26, 2013

Guys, unfortunately I'm not sure when I'll be able to get back to this =/
It's something that ended up becoming a low priority for me now, so if someone wants to jump in feel free to do so.

@mitchellh if you want to close the PR to keep it out of the radar I'm fine with that too. We can always continue the discussion "offline" if me or someone else is up to resume the work on it.

@mitchellh
Copy link
Contributor

Sure. No problem. I do still want to do this sometime. :) Thanks @fgrehm

@mitchellh mitchellh closed this Nov 27, 2013
@fgrehm fgrehm mentioned this pull request Dec 13, 2013
3 tasks
@helderco
Copy link

Yeah, this would be nice.

@mitchellh mitchellh deleted the host-capabilities branch January 25, 2014 20:27
@ghost ghost locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants