» Plugin Development: Guests
Warning: Advanced Topic! Developing plugins is anadvanced topic that only experienced Vagrant users who are reasonablycomfortable with Ruby should approach.
Vagrant has many features that requires doing guest OS-specificactions, such as mounting folders, configuring networks, etc. Thesetasks vary from operating system to operating system. If you find thatone of these does not work for your operating system, then maybe theguest implementation is incomplete or incorrect.
Within the context of a plugin definition, new guests can be definedlike so:
Implementations of guests subclass Vagrant.plugin("2", "guest")
. Withinthis implementation, only the method needs to be implemented.
The detect?
method is called by Vagrant at some point after the machineis booted in order to determine what operating system the guest is running.If you detect that it is your operating system, return true
from .Otherwise, return false
.
Communication channels to the machine are guaranteed to be running at thispoint, so the most common way to detect the operating system is to dosome basic testing:
Vagrant also supports a form of inheritance for guests, since sometimesoperating systems stem from a common root. A good example of this is Linuxis the root of Debian, which further is the root of Ubuntu in many cases.Inheritance allows guests to share a lot of common behavior while allowingdistro-specific overrides.
Inheritance is not done via standard Ruby class inheritance because Vagrantuses a custom capability-based system.Vagrant handles inheritance dispatch for you.
To subclass another guest, specify that guest's name as a second parameterin the guest definition:
When detecting operating systems with detect?
, Vagrant always does adepth-first search by searching the children operating systems beforechecking their parents. Therefore, it is guaranteed in the above examplethat the method on "ubuntu" will be called before "debian."