Add alwaystrue guest plugin
This commit is contained in:
parent
448be2fc84
commit
c19b3683db
70
builtin/otherplugin/guest/alwaystrue.go
Normal file
70
builtin/otherplugin/guest/alwaystrue.go
Normal file
@ -0,0 +1,70 @@
|
||||
package guest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
||||
plugincore "github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
"github.com/hashicorp/vagrant/builtin/otherplugin/guest/cap"
|
||||
)
|
||||
|
||||
type GuestConfig struct {
|
||||
}
|
||||
|
||||
// AlwaysTrueGuest is a Guest implementation for myplugin.
|
||||
type AlwaysTrueGuest struct {
|
||||
config GuestConfig
|
||||
}
|
||||
|
||||
// DetectFunc implements component.Guest
|
||||
func (h *AlwaysTrueGuest) DetectFunc() interface{} {
|
||||
return h.Detect
|
||||
}
|
||||
|
||||
func (h *AlwaysTrueGuest) Detect(t plugincore.Target) bool {
|
||||
m, err := t.Specialize((*plugincore.Machine)(nil))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
machine := m.(plugincore.Machine)
|
||||
machine.ConnectionInfo()
|
||||
// TODO: need a communicator to connect to guest
|
||||
return true
|
||||
}
|
||||
|
||||
// ParentsFunc implements component.Guest
|
||||
func (h *AlwaysTrueGuest) ParentsFunc() interface{} {
|
||||
return h.Parents
|
||||
}
|
||||
|
||||
func (h *AlwaysTrueGuest) Parents() []string {
|
||||
return []string{"force", "guest", "platform", "match"} // We just need to have this be the most of all matches
|
||||
}
|
||||
|
||||
// HasCapabilityFunc implements component.Guest
|
||||
func (h *AlwaysTrueGuest) HasCapabilityFunc() interface{} {
|
||||
return h.CheckCapability
|
||||
}
|
||||
|
||||
func (h *AlwaysTrueGuest) CheckCapability(n *component.NamedCapability) bool {
|
||||
if n.Capability == "hello" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CapabilityFunc implements component.Guest
|
||||
func (h *AlwaysTrueGuest) CapabilityFunc(name string) interface{} {
|
||||
if name == "hello" {
|
||||
return h.WriteHelloCap
|
||||
}
|
||||
return errors.New("invalid capability requested")
|
||||
}
|
||||
|
||||
func (h *AlwaysTrueGuest) WriteHelloCap(m plugincore.Machine) error {
|
||||
return cap.WriteHello(m)
|
||||
}
|
||||
|
||||
var (
|
||||
_ component.Guest = (*AlwaysTrueGuest)(nil)
|
||||
)
|
||||
17
builtin/otherplugin/guest/cap/write_hello.go
Normal file
17
builtin/otherplugin/guest/cap/write_hello.go
Normal file
@ -0,0 +1,17 @@
|
||||
package cap
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
plugincore "github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
)
|
||||
|
||||
func WriteHello(machine plugincore.Machine) (err error) {
|
||||
d1 := []byte("hello\ngo\n")
|
||||
ioutil.WriteFile("/tmp/dat1", d1, 0644)
|
||||
|
||||
machine.ConnectionInfo()
|
||||
// TODO: write something to guest machine
|
||||
// need a communicator
|
||||
return
|
||||
}
|
||||
@ -2,11 +2,13 @@ package otherplugin
|
||||
|
||||
import (
|
||||
sdk "github.com/hashicorp/vagrant-plugin-sdk"
|
||||
"github.com/hashicorp/vagrant/builtin/otherplugin/guest"
|
||||
)
|
||||
|
||||
var CommandOptions = []sdk.Option{
|
||||
sdk.WithComponents(
|
||||
&Command{},
|
||||
&guest.AlwaysTrueGuest{},
|
||||
),
|
||||
sdk.WithName("otherplugin"),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user