From de996a6047eec4fef61a4795e34b90528e9010e6 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 18 Nov 2021 15:35:56 -0600 Subject: [PATCH] Move box loading to machine --- internal/core/machine.go | 21 +++++++++++++++------ internal/core/project.go | 26 -------------------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/internal/core/machine.go b/internal/core/machine.go index 873cfcf09..911a72a54 100644 --- a/internal/core/machine.go +++ b/internal/core/machine.go @@ -40,16 +40,25 @@ func (m *Machine) SetID(value string) (err error) { func (m *Machine) Box() (b core.Box, err error) { if m.box == nil { - box, err := NewBox( - BoxWithBasis(m.project.basis), - BoxWithBox(m.machine.Box), - BoxWithLogger(m.logger), - ) + // TODO: get provider info here too/generate full machine config? + // We know that these are machines so, save the Machine record + boxes, _ := m.project.Boxes() + b, err := boxes.Find(m.target.Configuration.ConfigVm.Box, "") if err != nil { return nil, err } - m.box = box + if b == nil { + // Add the box + b, err = addBox(m.target.Configuration.ConfigVm.Box, "virtualbox", m.project.basis) + if err != nil { + return nil, err + } + } + m.machine.Box = b.(*Box).ToProto() + m.Save() + m.box = b.(*Box) } + return m.box, nil } diff --git a/internal/core/project.go b/internal/core/project.go index f32fd7604..859bd13bc 100644 --- a/internal/core/project.go +++ b/internal/core/project.go @@ -11,7 +11,6 @@ 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" @@ -441,37 +440,12 @@ func (p *Project) InitTargets() (err error) { 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{} - boxes, _ := p.Boxes() - b, erro := boxes.Find(t.ConfigVm.Box, "") - if erro != nil { - return erro - } - if b == nil { - // Add the box - b, erro = addBox(t.ConfigVm.Box, "virtualbox", p.basis) - if erro != nil { - return nil - } - } - machineRecord.Box = b.(*Box).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, }, }, )