Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/hpc support #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 27 additions & 2 deletions builder/gridscale/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package gridscale
import (
"context"
"fmt"
"github.com/gridscale/gsclient-go/v3"
"log"

"github.com/gridscale/gsclient-go/v3"
registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
)

type Artifact struct {
Expand All @@ -14,8 +16,18 @@ type Artifact struct {
// The UUID of the template
TemplateUUID string

// Location name.
LocationName string

// Location UUID.
LocationUUID string

// The client for making API calls
Client gsclient.TemplateOperator

// StateData should store data such as GeneratedData
// to be shared with post-processors
StateData map[string]interface{}
}

func (*Artifact) BuilderId() string {
Expand All @@ -36,7 +48,20 @@ func (a *Artifact) String() string {
}

func (a *Artifact) State(name string) interface{} {
return nil
if name == registryimage.ArtifactStateURI {
img, err := registryimage.FromArtifact(a,
registryimage.WithID(a.TemplateName),
registryimage.WithProvider("gridscale"),
registryimage.WithSourceID(a.TemplateUUID),
registryimage.WithRegion(a.LocationName),
)
if err != nil {
log.Printf("[DEBUG] error encountered when creating a registry image %v", err)
return nil
}
return img
}
return a.StateData[name]
}

func (a *Artifact) Destroy() error {
Expand Down
2 changes: 2 additions & 0 deletions builder/gridscale/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
artifact := &Artifact{
TemplateName: b.config.TemplateName,
TemplateUUID: state.Get("template_uuid").(string),
LocationName: state.Get("location_name").(string),
LocationUUID: state.Get("location_uuid").(string),
Client: client,
}

Expand Down
18 changes: 15 additions & 3 deletions builder/gridscale/step_create_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *stepCreateTemplate) Run(ctx context.Context, state multistep.StateBag)
return multistep.ActionHalt
}
ui.Say(fmt.Sprintf("Creating template: %v", c.TemplateName))
template, err := client.CreateTemplate(
templateRes, err := client.CreateTemplate(
context.Background(),
gsclient.TemplateCreateRequest{
Name: c.TemplateName,
Expand All @@ -50,8 +50,20 @@ func (s *stepCreateTemplate) Run(ctx context.Context, state multistep.StateBag)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put("template_uuid", template.ObjectUUID)
ui.Say(fmt.Sprintf("Created template %v with uuid: %v", c.TemplateName, template.ObjectUUID))
template, err := client.GetTemplate(
context.Background(),
templateRes.ObjectUUID,
)
if err != nil {
err := fmt.Errorf("Error getting template: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put("template_uuid", template.Properties.ObjectUUID)
state.Put("location_name", template.Properties.LocationName)
state.Put("location_uuid", template.Properties.LocationUUID)
ui.Say(fmt.Sprintf("Created template %v with uuid: %v", c.TemplateName, template.Properties.ObjectUUID))
return multistep.ActionContinue
}

Expand Down
2 changes: 1 addition & 1 deletion docs/builders/gridscale.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ packer {
required_plugins {
gridscale = {
version = ">= 0.0.1"
source = "github.com/hashicorp/gridscale"
source = "github.com/gridscale/gridscale"
}
}
}
Expand Down