Skip to content

Commit

Permalink
Refactor to aupport OCI flexible shapes and latest bersion of the OCI…
Browse files Browse the repository at this point in the history
… SDK API
  • Loading branch information
mattia rossi committed Sep 2, 2021
1 parent adee72f commit 48d31f1
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 87 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ require (
github.com/hashicorp/hcl/v2 v2.8.0
github.com/hashicorp/packer v1.6.7-0.20210217093213-201869d627bf
github.com/hashicorp/packer-plugin-sdk v0.0.14
github.com/oracle/oci-go-sdk v19.0.0+incompatible
github.com/oracle/oci-go-sdk/v36 v36.2.0
github.com/zclconf/go-cty v1.7.0
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,12 @@ github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/olekukonko/tablewriter v0.0.0-20180105111133-96aac992fc8b/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/oracle/oci-go-sdk v18.0.0+incompatible h1:FLV4KixsVfF3rwyVTMI6Ryp/Q+OSb9sR5TawbfjFLN4=
github.com/oracle/oci-go-sdk v18.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-go-sdk v19.0.0+incompatible h1:UQnOTZBLEtrqNnJ7jQJiaadScBQ7+CF61+OIvWktkoc=
github.com/oracle/oci-go-sdk v19.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-go-sdk/v36 v36.2.0 h1:oBaN/FnBDy3ohMyVZ/rKfekYxnyksG2KK0YAhT5HSnk=
github.com/oracle/oci-go-sdk/v36 v36.2.0/go.mod h1:t8Y/M3Lh8X4BOJhtThJKe1skRTg7qom7oWyHiNjo4RM=
github.com/outscale/osc-sdk-go/osc v0.0.0-20200722135656-d654809d0699/go.mod h1:5AqqNH1X8zCHescKVlpSHRzrat1KCKDXqZoQPe8fY3A=
github.com/packer-community/winrmcp v0.0.0-20180921204643-0fd363d6159a h1:A3QMuteviunoaY/8ex+RKFqwhcZJ/Cf3fCW3IwL2wx4=
github.com/packer-community/winrmcp v0.0.0-20180921204643-0fd363d6159a/go.mod h1:f6Izs6JvFTdnRbziASagjZ2vmf55NSIkC/weStxCHqk=
Expand Down
2 changes: 1 addition & 1 deletion pkg/ocisurrogate/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/oracle/oci-go-sdk/core"
"github.com/oracle/oci-go-sdk/v36/core"
)

// Artifact is an artifact implementation that contains a built Custom Image.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ocisurrogate/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
commonsteps "github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
"github.com/hashicorp/packer-plugin-sdk/packer"
ocommon "github.com/hashicorp/packer/builder/oracle/common"
"github.com/oracle/oci-go-sdk/core"
"github.com/oracle/oci-go-sdk/v36/core"
)

// BuilderId uniquely identifies the builder
Expand Down
29 changes: 24 additions & 5 deletions pkg/ocisurrogate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ import (
"github.com/hashicorp/packer-plugin-sdk/pathing"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
ocicommon "github.com/oracle/oci-go-sdk/common"
ociauth "github.com/oracle/oci-go-sdk/common/auth"
ocicommon "github.com/oracle/oci-go-sdk/v36/common"
ociauth "github.com/oracle/oci-go-sdk/v36/common/auth"
)

type FlexShapeConfig struct {
Ocpus *float32 `mapstructure:"ocpus" required:"false"`
MemoryInGBs *float32 `mapstructure:"memory_in_gbs" required:"false"`
}

type Config struct {
common.PackerConfig `mapstructure:",squash"`
Comm communicator.Config `mapstructure:",squash"`
Expand Down Expand Up @@ -59,11 +64,13 @@ type Config struct {
// Image
BaseImageID string `mapstructure:"base_image_ocid"`
BaseImageName string `mapstructure:"base_image_name"`
Shape string `mapstructure:"shape"`
ImageName string `mapstructure:"image_name"`
BootVolumeSizeInGBs int64 `mapstructure:"bootvolumesize"`

// Instance
InstanceName string `mapstructure:"instance_name"`
Shape string `mapstructure:"shape"`
ShapeConfig FlexShapeConfig `mapstructure:"shape_config"`
BootVolumeSizeInGBs int64 `mapstructure:"bootvolumesize"`

// Metadata optionally contains custom metadata key/value pairs provided in the
// configuration. While this can be used to set metadata["user_data"] the explicit
Expand Down Expand Up @@ -194,7 +201,7 @@ func (c *Config) Prepare(raws ...interface{}) error {
}

providers := []ocicommon.ConfigurationProvider{
NewRawConfigurationProvider(c.TenancyID, c.UserID, c.Region, c.Fingerprint, string(keyContent), &c.PassPhrase),
ocicommon.NewRawConfigurationProvider(c.TenancyID, c.UserID, c.Region, c.Fingerprint, string(keyContent), &c.PassPhrase),
}

if fileProvider != nil {
Expand Down Expand Up @@ -245,6 +252,18 @@ func (c *Config) Prepare(raws ...interface{}) error {
errs, errors.New("'shape' must be specified"))
}

if strings.HasSuffix(c.Shape, "Flex") {
if c.ShapeConfig.Ocpus == nil {
errs = packer.MultiErrorAppend(
errs, errors.New("'Ocpus' must be specified when using flexible shapes"))
}
}

if c.ShapeConfig.MemoryInGBs != nil && c.ShapeConfig.Ocpus == nil {
errs = packer.MultiErrorAppend(
errs, errors.New("'Ocpus' must be specified if memory_in_gbs is specified"))
}

if c.SubnetID == "" {
errs = packer.MultiErrorAppend(
errs, errors.New("'subnet_ocid' must be specified"))
Expand Down
28 changes: 28 additions & 0 deletions pkg/ocisurrogate/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 0 additions & 76 deletions pkg/ocisurrogate/config_provider.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/ocisurrogate/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ocisurrogate
import (
"context"

"github.com/oracle/oci-go-sdk/core"
"github.com/oracle/oci-go-sdk/v36/core"
)

// Driver interfaces between the builder steps and the OCI SDK.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ocisurrogate/driver_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ocisurrogate
import (
"context"

"github.com/oracle/oci-go-sdk/core"
"github.com/oracle/oci-go-sdk/v36/core"
)

// driverMock implements the Driver interface and communicates with Oracle
Expand Down
10 changes: 9 additions & 1 deletion pkg/ocisurrogate/driver_oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"
"time"

core "github.com/oracle/oci-go-sdk/core"
core "github.com/oracle/oci-go-sdk/v36/core"
)

// driverOCI implements the Driver interface and communicates with Oracle
Expand Down Expand Up @@ -94,6 +94,14 @@ func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string, surrog
instanceDetails.DisplayName = &d.cfg.InstanceName
}

if d.cfg.ShapeConfig.Ocpus != nil {
LaunchInstanceShapeConfigDetails := core.LaunchInstanceShapeConfigDetails{
Ocpus: d.cfg.ShapeConfig.Ocpus,
MemoryInGBs: d.cfg.ShapeConfig.MemoryInGBs,
}
instanceDetails.ShapeConfig = &LaunchInstanceShapeConfigDetails
}

instance, err := d.computeClient.LaunchInstance(context.TODO(), core.LaunchInstanceRequest{LaunchInstanceDetails: instanceDetails})

if err != nil {
Expand Down

0 comments on commit 48d31f1

Please sign in to comment.