use state storage to save `feeSystemTypeCode`

This commit is contained in:
유성덕 2018-01-29 18:35:43 +09:00
parent 2152ad7609
commit 3820f97a0b
4 changed files with 29 additions and 20 deletions

View File

@ -2,6 +2,8 @@ package ncloud
import (
"errors"
"fmt"
"os"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
@ -26,7 +28,6 @@ type Config struct {
BlockStorageSize int `mapstructure:"block_storage_size"`
Region string `mapstructure:"region"`
AccessControlGroupConfigurationNo string `mapstructure:"access_control_group_configuration_no"`
FeeSystemTypeCode string `mapstructure:"-"`
Comm communicator.Config `mapstructure:",squash"`
ctx *interpolate.Context
@ -93,10 +94,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
}
if c.UserData != "" && c.UserDataFile != "" {
errs = append(errs, fmt.Errorf("Only one of user_data or user_data_file can be specified."))
errs = packer.MultiErrorAppend(errs, errors.New("Only one of user_data or user_data_file can be specified."))
} else if c.UserDataFile != "" {
if _, err := os.Stat(c.UserDataFile); err != nil {
errs = append(errs, fmt.Errorf("user_data_file not found: %s", c.UserDataFile))
errs = packer.MultiErrorAppend(errs, fmt.Errorf("user_data_file not found: %s", c.UserDataFile))
}
}
@ -108,8 +109,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs = packer.MultiErrorAppend(errs, errors.New("If Communicator is winrm, access_control_group_configuration_no is required"))
}
c.FeeSystemTypeCode = "MTRAT"
if errs != nil && len(errs.Errors) > 0 {
return nil, warnings, errs
}

View File

@ -14,7 +14,7 @@ import (
type StepCreateServerInstance struct {
Conn *ncloud.Conn
CreateServerInstance func(loginKeyName string, zoneNo string) (string, error)
CreateServerInstance func(loginKeyName string, zoneNo string, feeSystemTypeCode string) (string, error)
CheckServerInstanceStatusIsRunning func(serverInstanceNo string) error
Say func(message string)
Error func(e error)
@ -35,7 +35,7 @@ func NewStepCreateServerInstance(conn *ncloud.Conn, ui packer.Ui, config *Config
return step
}
func (s *StepCreateServerInstance) createServerInstance(loginKeyName string, zoneNo string) (string, error) {
func (s *StepCreateServerInstance) createServerInstance(loginKeyName string, zoneNo string, feeSystemTypeCode string) (string, error) {
reqParams := new(ncloud.RequestCreateServerInstance)
reqParams.ServerProductCode = s.Config.ServerProductCode
reqParams.MemberServerImageNo = s.Config.MemberServerImageNo
@ -44,7 +44,7 @@ func (s *StepCreateServerInstance) createServerInstance(loginKeyName string, zon
}
reqParams.LoginKeyName = loginKeyName
reqParams.ZoneNo = zoneNo
reqParams.FeeSystemTypeCode = s.Config.FeeSystemTypeCode
reqParams.FeeSystemTypeCode = feeSystemTypeCode
if s.Config.UserData != "" {
reqParams.UserData = s.Config.UserData
@ -87,7 +87,12 @@ func (s *StepCreateServerInstance) Run(state multistep.StateBag) multistep.StepA
var loginKey = state.Get("LoginKey").(*LoginKey)
var zoneNo = state.Get("ZoneNo").(string)
serverInstanceNo, err := s.CreateServerInstance(loginKey.KeyName, zoneNo)
feeSystemTypeCode := "MTRAT"
if _, ok := state.GetOk("FeeSystemTypeCode"); ok {
feeSystemTypeCode = state.Get("FeeSystemTypeCode").(string)
}
serverInstanceNo, err := s.CreateServerInstance(loginKey.KeyName, zoneNo, feeSystemTypeCode)
if err == nil {
state.Put("InstanceNo", serverInstanceNo)
}

View File

@ -8,7 +8,7 @@ import (
func TestStepCreateServerInstanceShouldFailIfOperationCreateFails(t *testing.T) {
var testSubject = &StepCreateServerInstance{
CreateServerInstance: func(loginKeyName string, zoneNo string) (string, error) {
CreateServerInstance: func(loginKeyName string, zoneNo string, feeSystemTypeCode string) (string, error) {
return "", fmt.Errorf("!! Unit Test FAIL !!")
},
Say: func(message string) {},
@ -30,7 +30,7 @@ func TestStepCreateServerInstanceShouldFailIfOperationCreateFails(t *testing.T)
func TestStepCreateServerInstanceShouldPassIfOperationCreatePasses(t *testing.T) {
var testSubject = &StepCreateServerInstance{
CreateServerInstance: func(loginKeyName string, zoneNo string) (string, error) { return "", nil },
CreateServerInstance: func(loginKeyName string, zoneNo string, feeSystemTypeCode string) (string, error) { return "", nil },
Say: func(message string) {},
Error: func(e error) {},
}

View File

@ -14,13 +14,14 @@ import (
//StepValidateTemplate : struct for Validation a tempalte
type StepValidateTemplate struct {
Conn *ncloud.Conn
Validate func() error
Say func(message string)
Error func(e error)
Config *Config
zoneNo string
regionNo string
Conn *ncloud.Conn
Validate func() error
Say func(message string)
Error func(e error)
Config *Config
zoneNo string
regionNo string
FeeSystemTypeCode string
}
// NewStepValidateTemplate : funciton for Validation a tempalte
@ -168,7 +169,7 @@ func (s *StepValidateTemplate) validateServerImageProduct() error {
}
if strings.Contains(productName, "mssql") {
s.Config.FeeSystemTypeCode = "FXSUM"
s.FeeSystemTypeCode = "FXSUM"
}
return nil
@ -193,7 +194,7 @@ func (s *StepValidateTemplate) validateServerProductCode() error {
if product.ProductCode == productCode {
isExistProductCode = true
if strings.Contains(product.ProductName, "mssql") {
s.Config.FeeSystemTypeCode = "FXSUM"
s.FeeSystemTypeCode = "FXSUM"
}
if product.ProductType.Code == "VDS" {
@ -255,6 +256,10 @@ func (s *StepValidateTemplate) Run(state multistep.StateBag) multistep.StepActio
state.Put("ZoneNo", s.zoneNo)
if s.FeeSystemTypeCode != "" {
state.Put("FeeSystemTypeCode", s.FeeSystemTypeCode)
}
return processStepResult(err, s.Error, state)
}