Detect guest for machine
This commit is contained in:
parent
c19b3683db
commit
6b007f27bb
@ -1,12 +1,14 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
@ -41,8 +43,67 @@ func (m *Machine) Box() (b *core.Box, err error) {
|
||||
|
||||
// Guest implements core.Machine
|
||||
func (m *Machine) Guest() (g core.Guest, err error) {
|
||||
// TODO: need Vagrantfile + communicator
|
||||
return
|
||||
guests, err := m.project.basis.typeComponents(m.ctx, component.GuestType)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var result core.Guest
|
||||
var result_name string
|
||||
|
||||
for name, g := range guests {
|
||||
guest := g.Value.(core.Guest)
|
||||
detected, err := guest.Detect(m.toTarget())
|
||||
if err != nil {
|
||||
m.logger.Error("guest error on detection check",
|
||||
"plugin", name,
|
||||
"type", "Guest",
|
||||
"error", err)
|
||||
|
||||
continue
|
||||
}
|
||||
if result == nil {
|
||||
if detected {
|
||||
result = guest
|
||||
result_name = name
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
gp, err := guest.Parents()
|
||||
if err != nil {
|
||||
m.logger.Error("failed to get parents from guest",
|
||||
"plugin", name,
|
||||
"type", "Guest",
|
||||
"error", err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
rp, err := result.Parents()
|
||||
if err != nil {
|
||||
m.logger.Error("failed to get parents from guest",
|
||||
"plugin", result_name,
|
||||
"type", "Guest",
|
||||
"error", err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if len(gp) > len(rp) {
|
||||
result = guest
|
||||
result_name = name
|
||||
}
|
||||
}
|
||||
|
||||
if result == nil {
|
||||
return nil, fmt.Errorf("failed to detect guest plugin for current platform")
|
||||
}
|
||||
|
||||
m.logger.Info("guest detection complete",
|
||||
"name", result_name)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (m *Machine) Inspect() (printable string, err error) {
|
||||
@ -97,5 +158,9 @@ func (m *Machine) SaveMachine() (err error) {
|
||||
return m.Save()
|
||||
}
|
||||
|
||||
func (m *Machine) toTarget() core.Target {
|
||||
return m
|
||||
}
|
||||
|
||||
var _ core.Machine = (*Machine)(nil)
|
||||
var _ core.Target = (*Machine)(nil)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user