Inject a box into the machine

This should be updated once the box collection and provider are
implemented in order to select the right box from the box
collection.
This commit is contained in:
sophia 2021-11-10 16:35:09 -06:00 committed by Paul Hinze
parent 4335d9e7dd
commit 2b93a26b50
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 29 additions and 13 deletions

View File

@ -42,9 +42,7 @@ func (m *Machine) Box() (b core.Box, err error) {
box, err := NewBox(
BoxWithBasis(m.project.basis),
BoxWithBox(m.machine.Box),
// BoxWithName(m.target.Configuration.ConfigVm.Box),
BoxWithLogger(m.logger),
// BoxWithDirectory("/Users/sophia/project/vagrant-ruby/cmd/vagrant/boxes/hashicorp-VAGRANTSLASH-bionic64/1.0.282/virtualbox/"),
)
if err != nil {
return nil, err

View File

@ -4,6 +4,7 @@ import (
"context"
"errors"
"os"
"path/filepath"
"strings"
"sync"
@ -11,6 +12,7 @@ import (
"github.com/hashicorp/go-argmapper"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"google.golang.org/protobuf/types/known/anypb"
"github.com/hashicorp/vagrant-plugin-sdk/component"
"github.com/hashicorp/vagrant-plugin-sdk/core"
@ -427,26 +429,42 @@ func (p *Project) InitTargets() (err error) {
updated := false
for _, t := range p.project.Configuration.MachineConfigs {
for _, et := range existingTargets {
if t.Name == et {
p.logger.Trace("target already exists within project",
"project", p.Name(),
"target", t.Name,
)
t = nil
break
}
}
if t == nil {
continue
}
// TODO: get provider info here too/generate full machine config?
// We know that these are machines so, save the Machine record
machineRecord := &vagrant_server.Target_Machine{}
// TODO: create a new box for now. This should be querying the box collection
// for a box that matches the provided provider and name
doxDir := filepath.Join(p.basis.dir.DataDir().String(), "boxes/hashicorp-VAGRANTSLASH-bionic64/1.0.282/virtualbox/")
b, erro := NewBox(
BoxWithBasis(p.basis),
BoxWithName(t.ConfigVm.Box),
// TODO: need to get this box info from the vagrantfile/provider
BoxWithProvider("virtualbox"),
BoxWithVersion("1.0.282"),
BoxWithDirectory(doxDir),
)
if erro != nil {
return erro
}
machineRecord.Box = b.ToProto()
machineRecordAny, erro := anypb.New(machineRecord)
if err != nil {
p.logger.Debug("Error generating machine record for target",
"project", p.Name(),
"target", t.Name,
)
return erro
}
_, err = p.Client().UpsertTarget(p.ctx,
&vagrant_server.UpsertTargetRequest{
Target: &vagrant_server.Target{
Name: t.Name,
Project: p.Ref().(*vagrant_plugin_sdk.Ref_Project),
Configuration: t,
Record: machineRecordAny,
},
},
)