ยปGo Plugin Development: Guests
Outside of these components, the caller must provide all other arguments that are required.
The most basic guest plugin is composed of:
- A detection function that determines if the plugin is usable on the system (is the expected guest)
- A set of capabilities that define actions that can be run against the guest
- An entry point defining the plugin options
Note: To quickly get started writing Go guest plugins, clone the vagrant-guest-plugin-skeleton template and follow the Readme.
The file structure of a guest plugin looks like:
Where main.go
defines the plugin options. guest/myguest.go
defines the core plugin
functionality including the detection of the guest. cap/*
has the definitions of
all the guest plugin capabilities. These capabilities are the same as those for Ruby
plugins.
Writing a guest plugin
A guest must satisfy the interface defined for a guest component
Src: https://github.com/hashicorp/vagrant-plugin-sdk/blob/main/component/component.go
GuestDetectFunc
: returns a function that defines the code that determines if the guest is
detected. The returned function must return a bool
.
ParentFunc
: returns a function that defines the code that determines the most immediate parent
plugin. A child plugin will inherit all the capabilities defined in the parent. The
returned function must return a string
.
HasCapabilityFunc
: returns a function that defines a lookup for a capability. The returned
function must return an bool
.
CapabilityFunc
: returns a capability function that is defined by the plugin registered by a given name.
An example guest plugin
In this example, the guest plugin will always be detected. It does not define any capabilities, or have any parent plugins.
Defining and registering guest capabilities
A guest plugin may have capabilities two ways:
- By defining and implementing the capability in the plugin
- By inheriting the capability from a parent guest plugin
Define a capability by writing out a function that returns the desired capability
Make the capability available to the plugin by filling in the capability functions
A guest plugin may inherit the capabilities of a parent function by defining
a parent in the plugin implementation. This is done by setting the return
value of the Parent
function to the name of the desired parent plugin. Go
based guest plugins may use Ruby based plugins as their parent.