update string to const
This commit is contained in:
parent
156d31f933
commit
9798c86a0d
|
@ -7,6 +7,16 @@ const (
|
|||
defaultPasswordSpe = "-_"
|
||||
)
|
||||
|
||||
const (
|
||||
osTypeWindows = "Windows"
|
||||
securityGroupNonWeb = "recommend non web"
|
||||
instanceStateRunning = "Running"
|
||||
instanceStateStopped = "Stopped"
|
||||
bootDiskStateInitializing = "Initializing"
|
||||
bootDiskStateNormal = "Normal"
|
||||
imageStateAvailable = "Available"
|
||||
)
|
||||
|
||||
var bootDiskTypeMap = map[string]string{
|
||||
"cloud_ssd": "CLOUD_SSD",
|
||||
"local_normal": "LOCAL_NORMAL",
|
||||
|
|
|
@ -24,8 +24,8 @@ func (s *stepCheckSourceImageId) Run(ctx context.Context, state multistep.StateB
|
|||
return halt(state, err, "Error on querying source_image_id")
|
||||
}
|
||||
|
||||
if imageSet.OsType == "Windows" {
|
||||
return halt(state, err, "The builder of ucloud-uhost not support make Windows image yet")
|
||||
if imageSet.OsType == osTypeWindows {
|
||||
return halt(state, err, "The builder of ucloud-uhost not support build Windows image yet")
|
||||
}
|
||||
|
||||
state.Put("source_image", imageSet)
|
||||
|
|
|
@ -52,7 +52,7 @@ func (s *stepConfigSecurityGroup) Run(ctx context.Context, state multistep.State
|
|||
}
|
||||
|
||||
for _, item := range resp.DataSet {
|
||||
if item.Type == "recommend non web" {
|
||||
if item.Type == securityGroupNonWeb {
|
||||
securityGroupId = item.FWId
|
||||
break
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag)
|
|||
return err
|
||||
}
|
||||
|
||||
if imageSet.State == "Available" {
|
||||
if imageSet.State == imageStateAvailable {
|
||||
expectedImages.Remove(v.Id())
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if inst == nil || inst.State != "Available" {
|
||||
if inst == nil || inst.State != imageStateAvailable {
|
||||
return newExpectedStateError("image", resp.ImageId)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if inst == nil || inst.State != "Running" {
|
||||
if inst == nil || inst.State != instanceStateRunning {
|
||||
return newExpectedStateError("instance", instanceId)
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag)
|
|||
s.instanceId = instanceId
|
||||
state.Put("instance", instance)
|
||||
|
||||
if instance.BootDiskState == "Initializing" {
|
||||
if instance.BootDiskState == bootDiskStateInitializing {
|
||||
ui.Say(fmt.Sprintf("Waiting for boot disk of instance initialized when boot_disk_type is %q", s.BootDiskType))
|
||||
|
||||
err = retry.Config{
|
||||
|
@ -87,7 +87,7 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if inst.BootDiskState != "Normal" {
|
||||
if inst.BootDiskState != bootDiskStateNormal {
|
||||
return newExpectedStateError("boot_disk of instance", instanceId)
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) {
|
|||
return
|
||||
}
|
||||
|
||||
if instance.State != "Stopped" {
|
||||
if instance.State != instanceStateStopped {
|
||||
err = retry.Config{
|
||||
Tries: 5,
|
||||
ShouldRetry: func(err error) bool {
|
||||
|
@ -168,7 +168,7 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) {
|
|||
return err
|
||||
}
|
||||
|
||||
if instance.State != "Stopped" {
|
||||
if instance.State != instanceStateStopped {
|
||||
return newExpectedStateError("instance", s.instanceId)
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ func (s *stepStopInstance) Run(ctx context.Context, state multistep.StateBag) mu
|
|||
return halt(state, err, fmt.Sprintf("Error on reading instance when stop %q", instance.UHostId))
|
||||
}
|
||||
|
||||
if instance.State != "Stopped" {
|
||||
if instance.State != instanceStateStopped {
|
||||
stopReq := conn.NewPoweroffUHostInstanceRequest()
|
||||
stopReq.UHostId = ucloud.String(instance.UHostId)
|
||||
ui.Say(fmt.Sprintf("Stopping instance %q", instance.UHostId))
|
||||
|
@ -59,7 +59,7 @@ func (s *stepStopInstance) Run(ctx context.Context, state multistep.StateBag) mu
|
|||
return err
|
||||
}
|
||||
|
||||
if instance.State != "Stopped" {
|
||||
if instance.State != instanceStateStopped {
|
||||
return newExpectedStateError("instance", instance.UHostId)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,28 +8,28 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func checkStringIn(val string, availables []string) error {
|
||||
for _, choice := range availables {
|
||||
func checkStringIn(val string, available []string) error {
|
||||
for _, choice := range available {
|
||||
if val == choice {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("should be one of %q, got %q", strings.Join(availables, ","), val)
|
||||
return fmt.Errorf("should be one of %q, got %q", strings.Join(available, ","), val)
|
||||
}
|
||||
|
||||
func checkIntIn(val int, availables []int) error {
|
||||
for _, choice := range availables {
|
||||
func checkIntIn(val int, available []int) error {
|
||||
for _, choice := range available {
|
||||
if val == choice {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("should be one of %v, got %d", availables, val)
|
||||
return fmt.Errorf("should be one of %v, got %d", available, val)
|
||||
}
|
||||
|
||||
func isStringIn(val string, availables []string) bool {
|
||||
for _, choice := range availables {
|
||||
func isStringIn(val string, available []string) bool {
|
||||
for _, choice := range available {
|
||||
if val == choice {
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue