:chore: added OSC Connection in builder file
This commit is contained in:
parent
1bfb2d9170
commit
1fbe715c13
|
@ -99,10 +99,13 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
|
||||
oapiconn := oapi.NewClient(clientConfig, skipClient)
|
||||
|
||||
oscConn := b.config.NewOSCClient()
|
||||
|
||||
// Setup the state bag and initial state for the steps
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", &b.config)
|
||||
state.Put("oapi", oapiconn)
|
||||
state.Put("osc", oscConn)
|
||||
state.Put("clientConfig", clientConfig)
|
||||
state.Put("hook", hook)
|
||||
state.Put("ui", ui)
|
||||
|
|
|
@ -27,6 +27,7 @@ type FlatConfig struct {
|
|||
SkipValidation *bool `mapstructure:"skip_region_validation" cty:"skip_region_validation" hcl:"skip_region_validation"`
|
||||
SkipMetadataApiCheck *bool `mapstructure:"skip_metadata_api_check" cty:"skip_metadata_api_check" hcl:"skip_metadata_api_check"`
|
||||
Token *string `mapstructure:"token" cty:"token" hcl:"token"`
|
||||
API *string `mapstructure:"api" cty:"api" hcl:"api"`
|
||||
OMIName *string `mapstructure:"omi_name" cty:"omi_name" hcl:"omi_name"`
|
||||
OMIDescription *string `mapstructure:"omi_description" cty:"omi_description" hcl:"omi_description"`
|
||||
OMIVirtType *string `mapstructure:"omi_virtualization_type" cty:"omi_virtualization_type" hcl:"omi_virtualization_type"`
|
||||
|
@ -148,6 +149,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"skip_region_validation": &hcldec.AttrSpec{Name: "skip_region_validation", Type: cty.Bool, Required: false},
|
||||
"skip_metadata_api_check": &hcldec.AttrSpec{Name: "skip_metadata_api_check", Type: cty.Bool, Required: false},
|
||||
"token": &hcldec.AttrSpec{Name: "token", Type: cty.String, Required: false},
|
||||
"api": &hcldec.AttrSpec{Name: "api", Type: cty.String, Required: false},
|
||||
"omi_name": &hcldec.AttrSpec{Name: "omi_name", Type: cty.String, Required: false},
|
||||
"omi_description": &hcldec.AttrSpec{Name: "omi_description", Type: cty.String, Required: false},
|
||||
"omi_virtualization_type": &hcldec.AttrSpec{Name: "omi_virtualization_type", Type: cty.String, Required: false},
|
||||
|
|
|
@ -27,6 +27,7 @@ type FlatConfig struct {
|
|||
SkipValidation *bool `mapstructure:"skip_region_validation" cty:"skip_region_validation" hcl:"skip_region_validation"`
|
||||
SkipMetadataApiCheck *bool `mapstructure:"skip_metadata_api_check" cty:"skip_metadata_api_check" hcl:"skip_metadata_api_check"`
|
||||
Token *string `mapstructure:"token" cty:"token" hcl:"token"`
|
||||
API *string `mapstructure:"api" cty:"api" hcl:"api"`
|
||||
AssociatePublicIpAddress *bool `mapstructure:"associate_public_ip_address" cty:"associate_public_ip_address" hcl:"associate_public_ip_address"`
|
||||
Subregion *string `mapstructure:"subregion_name" cty:"subregion_name" hcl:"subregion_name"`
|
||||
BlockDurationMinutes *int64 `mapstructure:"block_duration_minutes" cty:"block_duration_minutes" hcl:"block_duration_minutes"`
|
||||
|
@ -149,6 +150,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"skip_region_validation": &hcldec.AttrSpec{Name: "skip_region_validation", Type: cty.Bool, Required: false},
|
||||
"skip_metadata_api_check": &hcldec.AttrSpec{Name: "skip_metadata_api_check", Type: cty.Bool, Required: false},
|
||||
"token": &hcldec.AttrSpec{Name: "token", Type: cty.String, Required: false},
|
||||
"api": &hcldec.AttrSpec{Name: "api", Type: cty.String, Required: false},
|
||||
"associate_public_ip_address": &hcldec.AttrSpec{Name: "associate_public_ip_address", Type: cty.Bool, Required: false},
|
||||
"subregion_name": &hcldec.AttrSpec{Name: "subregion_name", Type: cty.String, Required: false},
|
||||
"block_duration_minutes": &hcldec.AttrSpec{Name: "block_duration_minutes", Type: cty.Number, Required: false},
|
||||
|
|
|
@ -66,6 +66,7 @@ type FlatConfig struct {
|
|||
SkipValidation *bool `mapstructure:"skip_region_validation" cty:"skip_region_validation" hcl:"skip_region_validation"`
|
||||
SkipMetadataApiCheck *bool `mapstructure:"skip_metadata_api_check" cty:"skip_metadata_api_check" hcl:"skip_metadata_api_check"`
|
||||
Token *string `mapstructure:"token" cty:"token" hcl:"token"`
|
||||
API *string `mapstructure:"api" cty:"api" hcl:"api"`
|
||||
AssociatePublicIpAddress *bool `mapstructure:"associate_public_ip_address" cty:"associate_public_ip_address" hcl:"associate_public_ip_address"`
|
||||
Subregion *string `mapstructure:"subregion_name" cty:"subregion_name" hcl:"subregion_name"`
|
||||
BlockDurationMinutes *int64 `mapstructure:"block_duration_minutes" cty:"block_duration_minutes" hcl:"block_duration_minutes"`
|
||||
|
@ -172,6 +173,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"skip_region_validation": &hcldec.AttrSpec{Name: "skip_region_validation", Type: cty.Bool, Required: false},
|
||||
"skip_metadata_api_check": &hcldec.AttrSpec{Name: "skip_metadata_api_check", Type: cty.Bool, Required: false},
|
||||
"token": &hcldec.AttrSpec{Name: "token", Type: cty.String, Required: false},
|
||||
"api": &hcldec.AttrSpec{Name: "api", Type: cty.String, Required: false},
|
||||
"associate_public_ip_address": &hcldec.AttrSpec{Name: "associate_public_ip_address", Type: cty.Bool, Required: false},
|
||||
"subregion_name": &hcldec.AttrSpec{Name: "subregion_name", Type: cty.String, Required: false},
|
||||
"block_duration_minutes": &hcldec.AttrSpec{Name: "block_duration_minutes", Type: cty.Number, Required: false},
|
||||
|
|
|
@ -41,6 +41,7 @@ type FlatConfig struct {
|
|||
SecretKey *string `mapstructure:"secret_key" cty:"secret_key" hcl:"secret_key"`
|
||||
SkipMetadataApiCheck *bool `mapstructure:"skip_metadata_api_check" cty:"skip_metadata_api_check" hcl:"skip_metadata_api_check"`
|
||||
Token *string `mapstructure:"token" cty:"token" hcl:"token"`
|
||||
API *string `mapstructure:"api" cty:"api" hcl:"api"`
|
||||
ChrootMounts [][]string `mapstructure:"chroot_mounts" cty:"chroot_mounts" hcl:"chroot_mounts"`
|
||||
CommandWrapper *string `mapstructure:"command_wrapper" cty:"command_wrapper" hcl:"command_wrapper"`
|
||||
CopyFiles []string `mapstructure:"copy_files" cty:"copy_files" hcl:"copy_files"`
|
||||
|
@ -103,6 +104,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"secret_key": &hcldec.AttrSpec{Name: "secret_key", Type: cty.String, Required: false},
|
||||
"skip_metadata_api_check": &hcldec.AttrSpec{Name: "skip_metadata_api_check", Type: cty.Bool, Required: false},
|
||||
"token": &hcldec.AttrSpec{Name: "token", Type: cty.String, Required: false},
|
||||
"api": &hcldec.AttrSpec{Name: "api", Type: cty.String, Required: false},
|
||||
"chroot_mounts": &hcldec.AttrSpec{Name: "chroot_mounts", Type: cty.List(cty.List(cty.String)), Required: false},
|
||||
"command_wrapper": &hcldec.AttrSpec{Name: "command_wrapper", Type: cty.String, Required: false},
|
||||
"copy_files": &hcldec.AttrSpec{Name: "copy_files", Type: cty.List(cty.String), Required: false},
|
||||
|
|
|
@ -4,9 +4,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/antihax/optional"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/outscale/osc-go/oapi"
|
||||
"github.com/outscale/osc-sdk-go/osc"
|
||||
)
|
||||
|
||||
// StepPreValidate provides an opportunity to pre-validate any configuration for
|
||||
|
@ -24,11 +25,19 @@ func (s *StepPreValidate) Run(_ context.Context, state multistep.StateBag) multi
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
oapiconn := state.Get("oapi").(*oapi.Client)
|
||||
var (
|
||||
conn = state.Get("osc").(*osc.APIClient)
|
||||
images []interface{}
|
||||
)
|
||||
|
||||
ui.Say(fmt.Sprintf("Prevalidating OMI Name: %s", s.DestOmiName))
|
||||
resp, err := oapiconn.POST_ReadImages(oapi.ReadImagesRequest{
|
||||
Filters: oapi.FiltersImage{ImageNames: []string{s.DestOmiName}},
|
||||
|
||||
resp, _, err := conn.ImageApi.ReadImages(context.Background(), &osc.ReadImagesOpts{
|
||||
ReadImagesRequest: optional.NewInterface(osc.ReadImagesRequest{
|
||||
Filters: osc.FiltersImage{
|
||||
ImageNames: []string{s.DestOmiName},
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -38,18 +47,14 @@ func (s *StepPreValidate) Run(_ context.Context, state multistep.StateBag) multi
|
|||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
//FIXME: Remove when the oAPI filters works
|
||||
images := make([]oapi.Image, 0)
|
||||
|
||||
for _, omi := range resp.OK.Images {
|
||||
for _, omi := range resp.Images {
|
||||
if omi.ImageName == s.DestOmiName {
|
||||
images = append(images, omi)
|
||||
}
|
||||
}
|
||||
|
||||
//if len(resp.OK.Images) > 0 {
|
||||
if len(images) > 0 {
|
||||
err := fmt.Errorf("Error: name conflicts with an existing OMI: %s", resp.OK.Images[0].ImageId)
|
||||
err := fmt.Errorf("Error: name conflicts with an existing OMI: %s", s.DestOmiName)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
|
|
Loading…
Reference in New Issue