Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions provider/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ func (m *machineSpec) Validate() error {
// SetSpecFromImage looks for aditional info in the image metadata that can be set
// on a machine for later retrieval.
func (m *machineSpec) SetSpecFromImage(img images.Image) {
if m.Properties == nil {
m.Properties = make(map[string]string)
}
m.Properties["image_id"] = img.ID

if os_name, ok := img.Properties["os_distro"]; ok {
val, ok := os_name.(string)
if ok {
Expand Down
8 changes: 8 additions & 0 deletions provider/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ import (
"github.com/cloudbase/garm-provider-common/cloudconfig"
"github.com/cloudbase/garm-provider-common/params"
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/v2/openstack/image/v2/images"
"github.com/stretchr/testify/assert"

"github.com/cloudbase/garm-provider-openstack/config"
)

func TestMachineSpecSetSpecFromImageAddsImageID(t *testing.T) {
m := &machineSpec{Properties: map[string]string{}}
m.SetSpecFromImage(images.Image{ID: "image-uuid"})

assert.Equal(t, "image-uuid", m.Properties["image_id"])
}

func Test_machineSpec_MergeExtraSpecs(t *testing.T) {
tests := []struct {
name string
Expand Down