refactor: colocate ENI allocation with VM runtime

This commit is contained in:
joshsiv-mulga
2026-09-30 15:26:40 +10:00
parent 60c9ed47d7
commit c239fd8973
5 changed files with 6 additions and 9 deletions
+2 -3
View File
@@ -15,7 +15,6 @@ import (
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
"github.com/mulgadc/spinifex/spinifex/runtime/compute/qmp"
"github.com/mulgadc/spinifex/spinifex/runtime/compute/vm"
spxtypes "github.com/mulgadc/spinifex/spinifex/types"
"github.com/mulgadc/spinifex/spinifex/utils"
"github.com/nats-io/nats.go"
"github.com/stretchr/testify/assert"
@@ -118,7 +117,7 @@ func newENIHotPlugFixture(t *testing.T) *eniHotPlugFixture {
ID: "i-hp-test",
Status: vm.StateRunning,
QMPClient: &qmp.QMPClient{},
ENIRequests: spxtypes.ENIRequests{
ENIRequests: vm.ENIRequests{
AvailableSlots: []int{1, 2, 3, 4},
AttachedByENIID: map[string]int{},
},
@@ -352,7 +351,7 @@ func TestHandleDetachNetworkInterface_WrongOwner(t *testing.T) {
otherVM := &vm.VM{
ID: "i-other",
Status: vm.StateRunning,
ENIRequests: spxtypes.ENIRequests{
ENIRequests: vm.ENIRequests{
AvailableSlots: []int{1},
AttachedByENIID: map[string]int{},
},
@@ -11,7 +11,6 @@ import (
"time"
"github.com/mulgadc/spinifex/spinifex/runtime/compute/qmp"
"github.com/mulgadc/spinifex/spinifex/types"
)
// newHotPlugTestVM returns a VM in StateRunning with a non-nil QMPClient
@@ -39,7 +38,7 @@ func newHotPlugTestVMWithPlumber(t *testing.T, slots int) (*Manager, *VM, *StubD
ID: "i-test",
Status: StateRunning,
QMPClient: &qmp.QMPClient{},
ENIRequests: types.ENIRequests{
ENIRequests: ENIRequests{
AvailableSlots: available,
AttachedByENIID: make(map[string]int),
},
@@ -5,7 +5,6 @@ import (
"testing"
"github.com/mulgadc/spinifex/spinifex/runtime/compute/qmp"
"github.com/mulgadc/spinifex/spinifex/types"
)
func TestENISlotFromDeviceID(t *testing.T) {
@@ -67,7 +66,7 @@ func TestAdoptENISlot(t *testing.T) {
}
func TestAdoptENISlot_NilMap(t *testing.T) {
v := &VM{ENIRequests: types.ENIRequests{AvailableSlots: []int{1}}}
v := &VM{ENIRequests: ENIRequests{AvailableSlots: []int{1}}}
m := &Manager{}
m.AdoptENISlot(v, "eni-a", 1)
if got := v.ENIRequests.AttachedByENIID["eni-a"]; got != 1 {
@@ -1,4 +1,4 @@
package types
package vm
import "sync"
+1 -1
View File
@@ -88,7 +88,7 @@ type VM struct {
Config Config `json:"config"`
EBSRequests types.EBSRequests `json:"ebs_requests"`
ENIRequests types.ENIRequests `json:"eni_requests"`
ENIRequests ENIRequests `json:"eni_requests"`
QMPClient *qmp.QMPClient `json:"-"`