Driver
What is a Driver
For a higher level overview of drivers from a user viewpoint, see drivers. |
The koble
package uses a Driver
(defined by package pkg/driver)
interface
to control and manage virtual machines and networks.
The Driver
Godoc reference
shows the functions that must be defined for a type to satisfy the interface.
This means that we can have multiple implementations,
and therefore different virtualisation technologies,
without having to change any code in pkg/koble.
There are currently two implementations of the Driver
interface:
-
podman (pkg/driver/podman)
-
uml (pkg/driver/uml)
These provide driver types which have the correct methods to satisfy the interface defined by pkg/driver.
Interface (pkg/driver) | Podman Implementation | UML Implementation |
---|---|---|
Podman Machine |
UML Machine |
|
Podman Network |
UML Network |
Developing a New Driver
The easiest way to create a driver is to look at the Godoc references for the interfaces and create types to satisfy these. Looking at the implementations of the other drivers (particularly in pkg/driver/podman) is likely to help understand how to write driver functions.
To make a driver package available to the koble binary,
it needs to be registered in cmd/kob/driver.go
:
func init() {
driver.RegisterDriver("podman", func() driver.Driver {
return new(podman.PodmanDriver)
})
driver.RegisterDriver("uml", func() driver.Driver {
return new(uml.UMLDriver)
})
// new addition
driver.RegisterDriver("mynewdriver", func() driver.Driver {
return new(mypkg.MYDriver)
})
// end of new addition
err := driver.RegisterDriverCmds(driverCmd)
...
}