- Remove plugin version
- remove `os_type`. use `communicator` instead of this.
This commit is contained in:
parent
32e9ff84c5
commit
da78ebbf83
|
@ -8,8 +8,6 @@ import (
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "1.0.0"
|
|
||||||
|
|
||||||
// Builder assume this implements packer.Builder
|
// Builder assume this implements packer.Builder
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
config *Config
|
config *Config
|
||||||
|
@ -30,8 +28,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||||
ui.Say("Running builder for Naver Cloud Platform (version: " + version + ") ...")
|
|
||||||
|
|
||||||
ui.Message("Creating Naver Cloud Platform Connection ...")
|
ui.Message("Creating Naver Cloud Platform Connection ...")
|
||||||
conn := ncloud.NewConnection(b.config.AccessKey, b.config.SecretKey)
|
conn := ncloud.NewConnection(b.config.AccessKey, b.config.SecretKey)
|
||||||
|
|
||||||
|
@ -42,7 +38,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
|
|
||||||
steps = []multistep.Step{}
|
steps = []multistep.Step{}
|
||||||
|
|
||||||
if b.config.OSType == "Linux" {
|
if b.config.Comm.Type == "ssh" {
|
||||||
steps = []multistep.Step{
|
steps = []multistep.Step{
|
||||||
NewStepValidateTemplate(conn, ui, b.config),
|
NewStepValidateTemplate(conn, ui, b.config),
|
||||||
NewStepCreateLoginKey(conn, ui),
|
NewStepCreateLoginKey(conn, ui),
|
||||||
|
@ -63,7 +59,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
NewStepDeleteLoginKey(conn, ui),
|
NewStepDeleteLoginKey(conn, ui),
|
||||||
NewStepDeletePublicIPInstance(conn, ui),
|
NewStepDeletePublicIPInstance(conn, ui),
|
||||||
}
|
}
|
||||||
} else if b.config.OSType == "Windows" {
|
} else if b.config.Comm.Type == "Windows" {
|
||||||
steps = []multistep.Step{
|
steps = []multistep.Step{
|
||||||
NewStepValidateTemplate(conn, ui, b.config),
|
NewStepValidateTemplate(conn, ui, b.config),
|
||||||
NewStepCreateLoginKey(conn, ui),
|
NewStepCreateLoginKey(conn, ui),
|
||||||
|
@ -94,7 +90,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run!
|
// Run!
|
||||||
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
|
b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, b.stateBag)
|
||||||
b.runner.Run(b.stateBag)
|
b.runner.Run(b.stateBag)
|
||||||
|
|
||||||
// If there was an error, return that
|
// If there was an error, return that
|
||||||
|
|
|
@ -16,13 +16,13 @@ type Config struct {
|
||||||
|
|
||||||
AccessKey string `mapstructure:"access_key"`
|
AccessKey string `mapstructure:"access_key"`
|
||||||
SecretKey string `mapstructure:"secret_key"`
|
SecretKey string `mapstructure:"secret_key"`
|
||||||
OSType string `mapstructure:"os_type"`
|
|
||||||
ServerImageProductCode string `mapstructure:"server_image_product_code"`
|
ServerImageProductCode string `mapstructure:"server_image_product_code"`
|
||||||
ServerProductCode string `mapstructure:"server_product_code"`
|
ServerProductCode string `mapstructure:"server_product_code"`
|
||||||
MemberServerImageNo string `mapstructure:"member_server_image_no"`
|
MemberServerImageNo string `mapstructure:"member_server_image_no"`
|
||||||
ServerImageName string `mapstructure:"server_image_name"`
|
ServerImageName string `mapstructure:"server_image_name"`
|
||||||
ServerImageDescription string `mapstructure:"server_image_description"`
|
ServerImageDescription string `mapstructure:"server_image_description"`
|
||||||
UserData string `mapstructure:"user_data"`
|
UserData string `mapstructure:"user_data"`
|
||||||
|
UserDataFile string `mapstructure:"user_data_file"`
|
||||||
BlockStorageSize int `mapstructure:"block_storage_size"`
|
BlockStorageSize int `mapstructure:"block_storage_size"`
|
||||||
Region string `mapstructure:"region"`
|
Region string `mapstructure:"region"`
|
||||||
AccessControlGroupConfigurationNo string `mapstructure:"access_control_group_configuration_no"`
|
AccessControlGroupConfigurationNo string `mapstructure:"access_control_group_configuration_no"`
|
||||||
|
@ -60,10 +60,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
errs = packer.MultiErrorAppend(errs, errors.New("secret_key is required"))
|
errs = packer.MultiErrorAppend(errs, errors.New("secret_key is required"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.OSType != "Linux" && c.OSType != "Windows" {
|
|
||||||
errs = packer.MultiErrorAppend(errs, errors.New("os_type is required. ('Linux' or 'Windows')"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.MemberServerImageNo == "" && c.ServerImageProductCode == "" {
|
if c.MemberServerImageNo == "" && c.ServerImageProductCode == "" {
|
||||||
errs = packer.MultiErrorAppend(errs, errors.New("server_image_product_code or member_server_image_no is required"))
|
errs = packer.MultiErrorAppend(errs, errors.New("server_image_product_code or member_server_image_no is required"))
|
||||||
}
|
}
|
||||||
|
@ -100,8 +96,8 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
errs = packer.MultiErrorAppend(errs, errors.New("If user_data field is set, length of UserData should be max 21847"))
|
errs = packer.MultiErrorAppend(errs, errors.New("If user_data field is set, length of UserData should be max 21847"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.OSType == "Windows" && c.AccessControlGroupConfigurationNo == "" {
|
if c.Comm.Type == "wrinrm" && c.AccessControlGroupConfigurationNo == "" {
|
||||||
errs = packer.MultiErrorAppend(errs, errors.New("If os_type is Windows, access_control_group_configuration_no is required"))
|
errs = packer.MultiErrorAppend(errs, errors.New("If Communicator is winrm, access_control_group_configuration_no is required"))
|
||||||
}
|
}
|
||||||
|
|
||||||
c.FeeSystemTypeCode = "MTRAT"
|
c.FeeSystemTypeCode = "MTRAT"
|
||||||
|
|
|
@ -9,7 +9,6 @@ func testConfig() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"access_key": "access_key",
|
"access_key": "access_key",
|
||||||
"secret_key": "secret_key",
|
"secret_key": "secret_key",
|
||||||
"os_type": "Windows",
|
|
||||||
"server_image_product_code": "SPSW0WINNT000016",
|
"server_image_product_code": "SPSW0WINNT000016",
|
||||||
"server_product_code": "SPSVRSSD00000011",
|
"server_product_code": "SPSVRSSD00000011",
|
||||||
"server_image_name": "packer-test {{timestamp}}",
|
"server_image_name": "packer-test {{timestamp}}",
|
||||||
|
@ -27,7 +26,6 @@ func testConfigForMemberServerImage() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"access_key": "access_key",
|
"access_key": "access_key",
|
||||||
"secret_key": "secret_key",
|
"secret_key": "secret_key",
|
||||||
"os_type": "Windows",
|
|
||||||
"server_product_code": "SPSVRSSD00000011",
|
"server_product_code": "SPSVRSSD00000011",
|
||||||
"member_server_image_no": "2440",
|
"member_server_image_no": "2440",
|
||||||
"server_image_name": "packer-test {{timestamp}}",
|
"server_image_name": "packer-test {{timestamp}}",
|
||||||
|
@ -135,7 +133,6 @@ func TestExistsBothServerImageProductCodeAndMemberServerImageNoConfig(t *testing
|
||||||
raw := map[string]interface{}{
|
raw := map[string]interface{}{
|
||||||
"access_key": "access_key",
|
"access_key": "access_key",
|
||||||
"secret_key": "secret_key",
|
"secret_key": "secret_key",
|
||||||
"os_type": "Windows",
|
|
||||||
"server_image_product_code": "SPSW0WINNT000016",
|
"server_image_product_code": "SPSW0WINNT000016",
|
||||||
"server_product_code": "SPSVRSSD00000011",
|
"server_product_code": "SPSVRSSD00000011",
|
||||||
"member_server_image_no": "2440",
|
"member_server_image_no": "2440",
|
||||||
|
|
|
@ -91,10 +91,10 @@ func (s *StepCreatePublicIPInstance) Run(state multistep.StateBag) multistep.Ste
|
||||||
|
|
||||||
publicIPInstance, err := s.CreatePublicIPInstance(serverInstanceNo)
|
publicIPInstance, err := s.CreatePublicIPInstance(serverInstanceNo)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
switch s.Config.OSType {
|
switch s.Config.Comm.Type {
|
||||||
case "Linux":
|
case "ssh":
|
||||||
state.Put("SSHHost", publicIPInstance.PublicIP)
|
state.Put("SSHHost", publicIPInstance.PublicIP)
|
||||||
case "Windows":
|
case "winrm":
|
||||||
state.Put("WinRMHost", publicIPInstance.PublicIP)
|
state.Put("WinRMHost", publicIPInstance.PublicIP)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,17 @@ func TestStepCreatePublicIPInstanceShouldFailIfOperationCreatePublicIPInstanceFa
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStepCreatePublicIPInstanceShouldPassIfOperationCreatePublicIPInstancePasses(t *testing.T) {
|
func TestStepCreatePublicIPInstanceShouldPassIfOperationCreatePublicIPInstancePasses(t *testing.T) {
|
||||||
|
c := new(Config)
|
||||||
|
c.Comm.Prepare(nil)
|
||||||
|
c.Comm.Type = "ssh"
|
||||||
|
|
||||||
var testSubject = &StepCreatePublicIPInstance{
|
var testSubject = &StepCreatePublicIPInstance{
|
||||||
CreatePublicIPInstance: func(serverInstanceNo string) (*ncloud.PublicIPInstance, error) {
|
CreatePublicIPInstance: func(serverInstanceNo string) (*ncloud.PublicIPInstance, error) {
|
||||||
return &ncloud.PublicIPInstance{PublicIPInstanceNo: "a", PublicIP: "b"}, nil
|
return &ncloud.PublicIPInstance{PublicIPInstanceNo: "a", PublicIP: "b"}, nil
|
||||||
},
|
},
|
||||||
Say: func(message string) {},
|
Say: func(message string) {},
|
||||||
Error: func(e error) {},
|
Error: func(e error) {},
|
||||||
Config: &Config{OSType: "Windows"},
|
Config: c,
|
||||||
}
|
}
|
||||||
|
|
||||||
stateBag := createTestStateBagStepCreatePublicIPInstance()
|
stateBag := createTestStateBagStepCreatePublicIPInstance()
|
||||||
|
|
Loading…
Reference in New Issue