optimize code style
This commit is contained in:
parent
9de1c42ad4
commit
37e898e115
@ -8,18 +8,20 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OsTypeWindows = "Windows"
|
InstanceStateRunning = "Running"
|
||||||
SecurityGroupNonWeb = "recommend non web"
|
InstanceStateStopped = "Stopped"
|
||||||
InstanceStateRunning = "Running"
|
|
||||||
InstanceStateStopped = "Stopped"
|
|
||||||
BootDiskStateNormal = "Normal"
|
|
||||||
ImageStateAvailable = "Available"
|
ImageStateAvailable = "Available"
|
||||||
ImageStateUnavailable = "Unavailable"
|
ImageStateUnavailable = "Unavailable"
|
||||||
IpTypePrivate = "Private"
|
|
||||||
|
BootDiskStateNormal = "Normal"
|
||||||
|
OsTypeWindows = "Windows"
|
||||||
|
SecurityGroupNonWeb = "recommend non web"
|
||||||
|
IpTypePrivate = "Private"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultCreateImageTimeOut = 3600
|
DefaultCreateImageTimeout = 3600
|
||||||
)
|
)
|
||||||
|
|
||||||
var BootDiskTypeMap = NewStringConverter(map[string]string{
|
var BootDiskTypeMap = NewStringConverter(map[string]string{
|
||||||
|
@ -12,7 +12,7 @@ type ExpectedStateError struct {
|
|||||||
message string
|
message string
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotCompleteError struct {
|
type NotCompletedError struct {
|
||||||
message string
|
message string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ func (e *NotFoundError) Error() string {
|
|||||||
return e.message
|
return e.message
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NotCompleteError) Error() string {
|
func (e *NotCompletedError) Error() string {
|
||||||
return e.message
|
return e.message
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ func NewExpectedStateError(product, id string) error {
|
|||||||
return &ExpectedStateError{fmt.Sprintf("the %s %s not be expected state", product, id)}
|
return &ExpectedStateError{fmt.Sprintf("the %s %s not be expected state", product, id)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNotCompleteError(product string) error {
|
func NewNotCompletedError(product string) error {
|
||||||
return &NotCompleteError{fmt.Sprintf("%s is not completed", product)}
|
return &NotCompletedError{fmt.Sprintf("%s is not completed", product)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsNotFoundError(err error) bool {
|
func IsNotFoundError(err error) bool {
|
||||||
@ -55,7 +55,7 @@ func IsExpectedStateError(err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsNotCompleteError(err error) bool {
|
func IsNotCompleteError(err error) bool {
|
||||||
if _, ok := err.(*NotCompleteError); ok {
|
if _, ok := err.(*NotCompletedError); ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -45,7 +45,7 @@ func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.WaitImageReadyTimeout <= 0 {
|
if c.WaitImageReadyTimeout <= 0 {
|
||||||
c.WaitImageReadyTimeout = DefaultCreateImageTimeOut
|
c.WaitImageReadyTimeout = DefaultCreateImageTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
@ -83,7 +83,7 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(expectedImages.GetAll()) != 0 {
|
if len(expectedImages.GetAll()) != 0 {
|
||||||
return ucloudcommon.NewNotCompleteError("copying image")
|
return ucloudcommon.NewNotCompletedError("copying image")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -267,7 +267,7 @@ func (s *stepCreateInstance) buildCreateInstanceRequest(state multistep.StateBag
|
|||||||
if !s.UsePrivateIp {
|
if !s.UsePrivateIp {
|
||||||
operatorName := ucloud.String("International")
|
operatorName := ucloud.String("International")
|
||||||
if strings.HasPrefix(s.Region, "cn-") {
|
if strings.HasPrefix(s.Region, "cn-") {
|
||||||
operatorName = ucloud.String("BGP")
|
operatorName = ucloud.String("Bgp")
|
||||||
}
|
}
|
||||||
networkInterface := uhost.CreateUHostInstanceParamNetworkInterface{
|
networkInterface := uhost.CreateUHostInstanceParamNetworkInterface{
|
||||||
EIP: &uhost.CreateUHostInstanceParamNetworkInterfaceEIP{
|
EIP: &uhost.CreateUHostInstanceParamNetworkInterfaceEIP{
|
||||||
|
@ -19,11 +19,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BuilderId = "packer.post-processor.ucloud-import"
|
BuilderId = "packer.post-processor.ucloud-import"
|
||||||
RAWFileFormat = "raw"
|
|
||||||
VHDFileFormat = "vhd"
|
ImageFileFormatRAW = "raw"
|
||||||
VMDKFileFormat = "vmdk"
|
ImageFileFormatVHD = "vhd"
|
||||||
QCOW2FileFormat = "qcow2"
|
ImageFileFormatVMDK = "vmdk"
|
||||||
|
ImageFileFormatQCOW2 = "qcow2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var regionForFileMap = ucloudcommon.NewStringConverter(map[string]string{
|
var regionForFileMap = ucloudcommon.NewStringConverter(map[string]string{
|
||||||
@ -81,7 +82,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.config.WaitImageReadyTimeout <= 0 {
|
if p.config.WaitImageReadyTimeout <= 0 {
|
||||||
p.config.WaitImageReadyTimeout = ucloudcommon.DefaultCreateImageTimeOut
|
p.config.WaitImageReadyTimeout = ucloudcommon.DefaultCreateImageTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
errs := new(packer.MultiError)
|
errs := new(packer.MultiError)
|
||||||
@ -117,7 +118,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch p.config.Format {
|
switch p.config.Format {
|
||||||
case VHDFileFormat, RAWFileFormat, VMDKFileFormat, QCOW2FileFormat:
|
case ImageFileFormatVHD, ImageFileFormatRAW, ImageFileFormatVMDK, ImageFileFormatQCOW2:
|
||||||
default:
|
default:
|
||||||
errs = packer.MultiErrorAppend(
|
errs = packer.MultiErrorAppend(
|
||||||
errs, fmt.Errorf("expected %q only be one of 'raw', 'vhd', 'vmdk', or 'qcow2', got %q", "format", p.config.Format))
|
errs, fmt.Errorf("expected %q only be one of 'raw', 'vhd', 'vmdk', or 'qcow2', got %q", "format", p.config.Format))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user