From 2b93a26b50909937d1fafadabbf41411c7fd2b96 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 10 Nov 2021 16:35:09 -0600 Subject: [PATCH] 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. --- internal/core/machine.go | 2 -- internal/core/project.go | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/internal/core/machine.go b/internal/core/machine.go index 72bd8538c..2f89a20df 100644 --- a/internal/core/machine.go +++ b/internal/core/machine.go @@ -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 diff --git a/internal/core/project.go b/internal/core/project.go index bc596959e..ebd84227e 100644 --- a/internal/core/project.go +++ b/internal/core/project.go @@ -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, }, }, )