Skip to content

Commit 25b9827

Browse files
Merge pull request #12 from gridscale/feature/hpc-support
Feature/hpc support
2 parents 2a14105 + 51149f6 commit 25b9827

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

builder/gridscale/artifact.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package gridscale
33
import (
44
"context"
55
"fmt"
6-
"github.com/gridscale/gsclient-go/v3"
76
"log"
7+
8+
"github.com/gridscale/gsclient-go/v3"
9+
registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
810
)
911

1012
type Artifact struct {
@@ -14,8 +16,18 @@ type Artifact struct {
1416
// The UUID of the template
1517
TemplateUUID string
1618

19+
// Location name.
20+
LocationName string
21+
22+
// Location UUID.
23+
LocationUUID string
24+
1725
// The client for making API calls
1826
Client gsclient.TemplateOperator
27+
28+
// StateData should store data such as GeneratedData
29+
// to be shared with post-processors
30+
StateData map[string]interface{}
1931
}
2032

2133
func (*Artifact) BuilderId() string {
@@ -36,7 +48,20 @@ func (a *Artifact) String() string {
3648
}
3749

3850
func (a *Artifact) State(name string) interface{} {
39-
return nil
51+
if name == registryimage.ArtifactStateURI {
52+
img, err := registryimage.FromArtifact(a,
53+
registryimage.WithID(a.TemplateName),
54+
registryimage.WithProvider("gridscale"),
55+
registryimage.WithSourceID(a.TemplateUUID),
56+
registryimage.WithRegion(a.LocationName),
57+
)
58+
if err != nil {
59+
log.Printf("[DEBUG] error encountered when creating a registry image %v", err)
60+
return nil
61+
}
62+
return img
63+
}
64+
return a.StateData[name]
4065
}
4166

4267
func (a *Artifact) Destroy() error {

builder/gridscale/builder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
189189
artifact := &Artifact{
190190
TemplateName: b.config.TemplateName,
191191
TemplateUUID: state.Get("template_uuid").(string),
192+
LocationName: state.Get("location_name").(string),
193+
LocationUUID: state.Get("location_uuid").(string),
192194
Client: client,
193195
}
194196

builder/gridscale/step_create_template.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *stepCreateTemplate) Run(ctx context.Context, state multistep.StateBag)
3737
return multistep.ActionHalt
3838
}
3939
ui.Say(fmt.Sprintf("Creating template: %v", c.TemplateName))
40-
template, err := client.CreateTemplate(
40+
templateRes, err := client.CreateTemplate(
4141
context.Background(),
4242
gsclient.TemplateCreateRequest{
4343
Name: c.TemplateName,
@@ -50,8 +50,20 @@ func (s *stepCreateTemplate) Run(ctx context.Context, state multistep.StateBag)
5050
ui.Error(err.Error())
5151
return multistep.ActionHalt
5252
}
53-
state.Put("template_uuid", template.ObjectUUID)
54-
ui.Say(fmt.Sprintf("Created template %v with uuid: %v", c.TemplateName, template.ObjectUUID))
53+
template, err := client.GetTemplate(
54+
context.Background(),
55+
templateRes.ObjectUUID,
56+
)
57+
if err != nil {
58+
err := fmt.Errorf("Error getting template: %s", err)
59+
state.Put("error", err)
60+
ui.Error(err.Error())
61+
return multistep.ActionHalt
62+
}
63+
state.Put("template_uuid", template.Properties.ObjectUUID)
64+
state.Put("location_name", template.Properties.LocationName)
65+
state.Put("location_uuid", template.Properties.LocationUUID)
66+
ui.Say(fmt.Sprintf("Created template %v with uuid: %v", c.TemplateName, template.Properties.ObjectUUID))
5567
return multistep.ActionContinue
5668
}
5769

docs/builders/gridscale.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The `gridscale` Packer builder is used to create new (os) templates for use with
1414
The builder does _not_ manage templates. Once it creates a template, it is up to you
1515
to use it or delete it.
1616

17+
1718
## Configuration Reference
1819

1920
There are many configuration options available for the builder. They are

0 commit comments

Comments
 (0)