spelling and grammar fixes
This commit is contained in:
parent
66bd707f7c
commit
e72163264b
|
@ -2,10 +2,11 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config of alicloud
|
// Config of alicloud
|
||||||
|
@ -56,8 +57,7 @@ func (c *AlicloudAccessConfig) Config() error {
|
||||||
c.AlicloudSecretKey = os.Getenv("ALICLOUD_SECRET_KEY")
|
c.AlicloudSecretKey = os.Getenv("ALICLOUD_SECRET_KEY")
|
||||||
}
|
}
|
||||||
if c.AlicloudAccessKey == "" || c.AlicloudSecretKey == "" {
|
if c.AlicloudAccessKey == "" || c.AlicloudSecretKey == "" {
|
||||||
return fmt.Errorf("ALICLOUD_ACCESS_KEY and ALICLOUD_SECRET_KEY must set in template file " +
|
return fmt.Errorf("ALICLOUD_ACCESS_KEY and ALICLOUD_SECRET_KEY must be set in template file or environment variables.")
|
||||||
"or environment variables")
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
package ecs
|
package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
"github.com/hashicorp/packer/helper/communicator"
|
"github.com/hashicorp/packer/helper/communicator"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The unique ID for this builder
|
// The unique ID for this builder
|
||||||
|
|
|
@ -13,7 +13,7 @@ func message(state multistep.StateBag, module string) {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
if cancelled || halted {
|
if cancelled || halted {
|
||||||
ui.Say(fmt.Sprintf("Delete the %s because cancelation or error...", module))
|
ui.Say(fmt.Sprintf("Delete the %s because cancellation or error...", module))
|
||||||
} else {
|
} else {
|
||||||
ui.Say(fmt.Sprintf("Clean the created %s", module))
|
ui.Say(fmt.Sprintf("Clean the created %s", module))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -19,36 +20,36 @@ func (s *setpConfigAlicloudEIP) Run(state multistep.StateBag) multistep.StepActi
|
||||||
client := state.Get("client").(*ecs.Client)
|
client := state.Get("client").(*ecs.Client)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
instance := state.Get("instance").(*ecs.InstanceAttributesType)
|
instance := state.Get("instance").(*ecs.InstanceAttributesType)
|
||||||
ui.Say("Start allocated alicloud eip")
|
ui.Say("Allocating eip")
|
||||||
ipaddress, allocateId, err := client.AllocateEipAddress(&ecs.AllocateEipAddressArgs{
|
ipaddress, allocateId, err := client.AllocateEipAddress(&ecs.AllocateEipAddressArgs{
|
||||||
RegionId: common.Region(s.RegionId), InternetChargeType: common.InternetChargeType(s.InternetChargeType),
|
RegionId: common.Region(s.RegionId), InternetChargeType: common.InternetChargeType(s.InternetChargeType),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Error allocate eip: %s", err))
|
ui.Say(fmt.Sprintf("Error allocating eip: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
s.allocatedId = allocateId
|
s.allocatedId = allocateId
|
||||||
if err = client.WaitForEip(common.Region(s.RegionId), allocateId,
|
if err = client.WaitForEip(common.Region(s.RegionId), allocateId,
|
||||||
ecs.EipStatusAvailable, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
ecs.EipStatusAvailable, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Error allocate alicloud eip: %s", err))
|
ui.Say(fmt.Sprintf("Error allocating eip: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = client.AssociateEipAddress(allocateId, instance.InstanceId); err != nil {
|
if err = client.AssociateEipAddress(allocateId, instance.InstanceId); err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Error binding alicloud eip: %s", err))
|
ui.Say(fmt.Sprintf("Error binding eip: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = client.WaitForEip(common.Region(s.RegionId), allocateId,
|
if err = client.WaitForEip(common.Region(s.RegionId), allocateId,
|
||||||
ecs.EipStatusInUse, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
ecs.EipStatusInUse, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Error associating alicloud eip: %s", err))
|
ui.Say(fmt.Sprintf("Error associating eip: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
ui.Say(fmt.Sprintf("Allocated alicloud eip %s", ipaddress))
|
ui.Say(fmt.Sprintf("Allocated eip %s", ipaddress))
|
||||||
state.Put("ipaddress", ipaddress)
|
state.Put("ipaddress", ipaddress)
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
@ -65,15 +66,14 @@ func (s *setpConfigAlicloudEIP) Cleanup(state multistep.StateBag) {
|
||||||
message(state, "EIP")
|
message(state, "EIP")
|
||||||
|
|
||||||
if err := client.UnassociateEipAddress(s.allocatedId, instance.InstanceId); err != nil {
|
if err := client.UnassociateEipAddress(s.allocatedId, instance.InstanceId); err != nil {
|
||||||
ui.Say(fmt.Sprintf("Unassociate alicloud eip failed "))
|
ui.Say(fmt.Sprintf("Unassociating eip failed."))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.WaitForEip(common.Region(s.RegionId), s.allocatedId,
|
if err := client.WaitForEip(common.Region(s.RegionId), s.allocatedId, ecs.EipStatusAvailable, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
||||||
ecs.EipStatusAvailable, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
ui.Say(fmt.Sprintf("Timeout while unassociating eip."))
|
||||||
ui.Say(fmt.Sprintf("Unassociate alicloud eip timeout "))
|
|
||||||
}
|
}
|
||||||
if err := client.ReleaseEipAddress(s.allocatedId); err != nil {
|
if err := client.ReleaseEipAddress(s.allocatedId); err != nil {
|
||||||
ui.Say(fmt.Sprintf("Release alicloud eip failed "))
|
ui.Say(fmt.Sprintf("Releasing eip failed."))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
@ -20,7 +21,7 @@ func (s *stepConfigAlicloudPublicIP) Run(state multistep.StateBag) multistep.Ste
|
||||||
ipaddress, err := client.AllocatePublicIpAddress(instance.InstanceId)
|
ipaddress, err := client.AllocatePublicIpAddress(instance.InstanceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Error allocate public ip: %s", err))
|
ui.Say(fmt.Sprintf("Error allocating public ip: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
s.publicIPAdress = ipaddress
|
s.publicIPAdress = ipaddress
|
||||||
|
|
|
@ -3,11 +3,12 @@ package ecs
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepConfigAlicloudSecurityGroup struct {
|
type stepConfigAlicloudSecurityGroup struct {
|
||||||
|
@ -40,7 +41,7 @@ func (s *stepConfigAlicloudSecurityGroup) Run(state multistep.StateBag) multiste
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Say(fmt.Sprintf("Query alicloud security grouip failed: %s", err))
|
ui.Say(fmt.Sprintf("Failed querying security group: %s", err))
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
@ -52,7 +53,7 @@ func (s *stepConfigAlicloudSecurityGroup) Run(state multistep.StateBag) multiste
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.isCreate = false
|
s.isCreate = false
|
||||||
message := fmt.Sprintf("The specific security group {%s} isn't exist.", s.SecurityGroupId)
|
message := fmt.Sprintf("The specified security group {%s} doesn't exist.", s.SecurityGroupId)
|
||||||
state.Put("error", errors.New(message))
|
state.Put("error", errors.New(message))
|
||||||
ui.Say(message)
|
ui.Say(message)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -75,7 +76,7 @@ func (s *stepConfigAlicloudSecurityGroup) Run(state multistep.StateBag) multiste
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Create security group failed %v", err))
|
ui.Say(fmt.Sprintf("Create security group failed %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
state.Put("securitygroupid", securityGroupId)
|
state.Put("securitygroupid", securityGroupId)
|
||||||
|
@ -91,7 +92,7 @@ func (s *stepConfigAlicloudSecurityGroup) Run(state multistep.StateBag) multiste
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("authorzie security group failed %v", err))
|
ui.Say(fmt.Sprintf("Failed authorizing security group: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
err = client.AuthorizeSecurityGroup(&ecs.AuthorizeSecurityGroupArgs{
|
err = client.AuthorizeSecurityGroup(&ecs.AuthorizeSecurityGroupArgs{
|
||||||
|
@ -104,7 +105,7 @@ func (s *stepConfigAlicloudSecurityGroup) Run(state multistep.StateBag) multiste
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("authorzie security group failed %v", err))
|
ui.Say(fmt.Sprintf("Failed authorizing security group: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ func (s *stepConfigAlicloudSecurityGroup) Cleanup(state multistep.StateBag) {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ui.Error(fmt.Sprintf("Error delete security group failed, may still be around: %s", err))
|
ui.Error(fmt.Sprintf("Failed to delete security group, it may still be around: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
@ -3,11 +3,12 @@ package ecs
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepConfigAlicloudVPC struct {
|
type stepConfigAlicloudVPC struct {
|
||||||
|
@ -28,7 +29,7 @@ func (s *stepConfigAlicloudVPC) Run(state multistep.StateBag) multistep.StepActi
|
||||||
RegionId: common.Region(config.AlicloudRegion),
|
RegionId: common.Region(config.AlicloudRegion),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Say(fmt.Sprintf("Query vpcs failed: %s", err))
|
ui.Say(fmt.Sprintf("Failed querying vpcs: %s", err))
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
@ -38,13 +39,13 @@ func (s *stepConfigAlicloudVPC) Run(state multistep.StateBag) multistep.StepActi
|
||||||
s.isCreate = false
|
s.isCreate = false
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
message := fmt.Sprintf("The specific vpc {%s} isn't exist.", s.VpcId)
|
message := fmt.Sprintf("The specified vpc {%s} doesn't exist.", s.VpcId)
|
||||||
state.Put("error", errors.New(message))
|
state.Put("error", errors.New(message))
|
||||||
ui.Say(message)
|
ui.Say(message)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
|
||||||
}
|
}
|
||||||
ui.Say("Start creating alicloud vpc")
|
ui.Say("Start create vpc")
|
||||||
vpc, err := client.CreateVpc(&ecs.CreateVpcArgs{
|
vpc, err := client.CreateVpc(&ecs.CreateVpcArgs{
|
||||||
RegionId: common.Region(config.AlicloudRegion),
|
RegionId: common.Region(config.AlicloudRegion),
|
||||||
CidrBlock: s.CidrBlock,
|
CidrBlock: s.CidrBlock,
|
||||||
|
@ -52,13 +53,13 @@ func (s *stepConfigAlicloudVPC) Run(state multistep.StateBag) multistep.StepActi
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Create vps failed %v", err))
|
ui.Say(fmt.Sprintf("Create vpc failed %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
err = client.WaitForVpcAvailable(common.Region(config.AlicloudRegion), vpc.VpcId, ALICLOUD_DEFAULT_SHORT_TIMEOUT)
|
err = client.WaitForVpcAvailable(common.Region(config.AlicloudRegion), vpc.VpcId, ALICLOUD_DEFAULT_SHORT_TIMEOUT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Waiting vps avabalibe failed %v", err))
|
ui.Say(fmt.Sprintf("Failed waiting for vpc to become available %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ func (s *stepConfigAlicloudVPC) Cleanup(state multistep.StateBag) {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ui.Error(fmt.Sprintf("Error delete vpc, may still be around: %s", err))
|
ui.Error(fmt.Sprintf("Error deleting vpc, it may still be around: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
@ -3,11 +3,12 @@ package ecs
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepConfigAlicloudVSwitch struct {
|
type stepConfigAlicloudVSwitch struct {
|
||||||
|
@ -31,7 +32,7 @@ func (s *stepConfigAlicloudVSwitch) Run(state multistep.StateBag) multistep.Step
|
||||||
ZoneId: s.ZoneId,
|
ZoneId: s.ZoneId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Say(fmt.Sprintf("Query vswitch failed: %s", err))
|
ui.Say(fmt.Sprintf("Failed querying vswitch: %s", err))
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
@ -42,7 +43,7 @@ func (s *stepConfigAlicloudVSwitch) Run(state multistep.StateBag) multistep.Step
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
s.isCreate = false
|
s.isCreate = false
|
||||||
message := fmt.Sprintf("The specific vswitch {%s} doesn't exist.", s.VSwitchId)
|
message := fmt.Sprintf("The specified vswitch {%s} doesn't exist.", s.VSwitchId)
|
||||||
state.Put("error", errors.New(message))
|
state.Put("error", errors.New(message))
|
||||||
ui.Say(message)
|
ui.Say(message)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -139,7 +140,7 @@ func (s *stepConfigAlicloudVSwitch) Cleanup(state multistep.StateBag) {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ui.Error(fmt.Sprintf("Error delete vswitch, may still be around: %s", err))
|
ui.Error(fmt.Sprintf("Error deleting vswitch, it may still be around: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -18,7 +19,7 @@ func (s *stepCreateAlicloudImage) Run(state multistep.StateBag) multistep.StepAc
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
// Create the alicloud image
|
// Create the alicloud image
|
||||||
ui.Say(fmt.Sprintf("Creating alicloud images: %s", config.AlicloudImageName))
|
ui.Say(fmt.Sprintf("Creating image: %s", config.AlicloudImageName))
|
||||||
var imageId string
|
var imageId string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ func (s *stepCreateAlicloudImage) Run(state multistep.StateBag) multistep.StepAc
|
||||||
Description: config.AlicloudImageDescription})
|
Description: config.AlicloudImageDescription})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error creating alicloud images: %s", err)
|
err := fmt.Errorf("Error creating image: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -39,7 +40,7 @@ func (s *stepCreateAlicloudImage) Run(state multistep.StateBag) multistep.StepAc
|
||||||
err = client.WaitForImageReady(common.Region(config.AlicloudRegion),
|
err = client.WaitForImageReady(common.Region(config.AlicloudRegion),
|
||||||
imageId, ALICLOUD_DEFAULT_LONG_TIMEOUT)
|
imageId, ALICLOUD_DEFAULT_LONG_TIMEOUT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Waiting alicloud image creating timeout: %s", err)
|
err := fmt.Errorf("Timeout waiting for image to be created: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -49,14 +50,14 @@ func (s *stepCreateAlicloudImage) Run(state multistep.StateBag) multistep.StepAc
|
||||||
RegionId: common.Region(config.AlicloudRegion),
|
RegionId: common.Region(config.AlicloudRegion),
|
||||||
ImageId: imageId})
|
ImageId: imageId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Query created alicloud image failed: %s", err)
|
err := fmt.Errorf("Error querying created image: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) == 0 {
|
if len(images) == 0 {
|
||||||
err := fmt.Errorf("Query created alicloud image failed: %s", err)
|
err := fmt.Errorf("Unable to find created image: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -85,9 +86,9 @@ func (s *stepCreateAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(Config)
|
||||||
|
|
||||||
ui.Say("Delete the alicloud image because cancelation or error...")
|
ui.Say("Deleting the image because of cancellation or error...")
|
||||||
if err := client.DeleteImage(common.Region(config.AlicloudRegion), s.image.ImageId); err != nil {
|
if err := client.DeleteImage(common.Region(config.AlicloudRegion), s.image.ImageId); err != nil {
|
||||||
ui.Error(fmt.Sprintf("Error delete alicloud image, may still be around: %s", err))
|
ui.Error(fmt.Sprintf("Error deleting image, it may still be around: %s", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,13 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepCreateAlicloudInstance struct {
|
type stepCreateAlicloudInstance struct {
|
||||||
|
@ -67,7 +68,7 @@ func (s *stepCreateAlicloudInstance) Run(state multistep.StateBag) multistep.Ste
|
||||||
DataDisk: diskDeviceToDiskType(config.AlicloudImageConfig.ECSImagesDiskMappings),
|
DataDisk: diskDeviceToDiskType(config.AlicloudImageConfig.ECSImagesDiskMappings),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error create alicloud instance: %s", err)
|
err := fmt.Errorf("Error creating instance: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -93,7 +94,7 @@ func (s *stepCreateAlicloudInstance) Run(state multistep.StateBag) multistep.Ste
|
||||||
DataDisk: diskDeviceToDiskType(config.AlicloudImageConfig.ECSImagesDiskMappings),
|
DataDisk: diskDeviceToDiskType(config.AlicloudImageConfig.ECSImagesDiskMappings),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error create instance: %s", err)
|
err := fmt.Errorf("Error creating instance: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -108,7 +109,7 @@ func (s *stepCreateAlicloudInstance) Run(state multistep.StateBag) multistep.Ste
|
||||||
}
|
}
|
||||||
instance, err := client.DescribeInstanceAttribute(instanceId)
|
instance, err := client.DescribeInstanceAttribute(instanceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Say(fmt.Sprint(err))
|
ui.Say(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
s.instance = instance
|
s.instance = instance
|
||||||
|
@ -126,7 +127,7 @@ func (s *stepCreateAlicloudInstance) Cleanup(state multistep.StateBag) {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
err := client.DeleteInstance(s.instance.InstanceId)
|
err := client.DeleteInstance(s.instance.InstanceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Say(fmt.Sprintf("Cleaning instance: %s failed ", s.instance.InstanceId))
|
ui.Say(fmt.Sprintf("Cleaning instance %s failed ", s.instance.InstanceId))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type stepDeleteAlicloudImageSnapshots struct {
|
type stepDeleteAlicloudImageSnapshots struct {
|
||||||
|
@ -36,7 +37,7 @@ func (s *stepDeleteAlicloudImageSnapshots) Run(state multistep.StateBag) multist
|
||||||
}
|
}
|
||||||
err = client.DeleteImage(common.Region(config.AlicloudRegion), image.ImageId)
|
err = client.DeleteImage(common.Region(config.AlicloudRegion), image.ImageId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Delete alicloud image failed: %s", err)
|
err := fmt.Errorf("Failed to delete image: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
@ -23,7 +24,7 @@ func (s *stepMountAlicloudDisk) Run(state multistep.StateBag) multistep.StepActi
|
||||||
disks, _, err := client.DescribeDisks(&ecs.DescribeDisksArgs{InstanceId: instance.InstanceId,
|
disks, _, err := client.DescribeDisks(&ecs.DescribeDisksArgs{InstanceId: instance.InstanceId,
|
||||||
RegionId: instance.RegionId})
|
RegionId: instance.RegionId})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error query alicloud disks failed: %s", err)
|
err := fmt.Errorf("Error querying disks: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -34,7 +35,7 @@ func (s *stepMountAlicloudDisk) Run(state multistep.StateBag) multistep.StepActi
|
||||||
InstanceId: instance.InstanceId,
|
InstanceId: instance.InstanceId,
|
||||||
Device: getDevice(&disk, alicloudDiskDevices),
|
Device: getDevice(&disk, alicloudDiskDevices),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
err := fmt.Errorf("Error mount alicloud disks failed: %s", err)
|
err := fmt.Errorf("Error mounting disks: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -43,13 +44,13 @@ func (s *stepMountAlicloudDisk) Run(state multistep.StateBag) multistep.StepActi
|
||||||
}
|
}
|
||||||
for _, disk := range disks {
|
for _, disk := range disks {
|
||||||
if err := client.WaitForDisk(instance.RegionId, disk.DiskId, ecs.DiskStatusInUse, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
if err := client.WaitForDisk(instance.RegionId, disk.DiskId, ecs.DiskStatusInUse, ALICLOUD_DEFAULT_SHORT_TIMEOUT); err != nil {
|
||||||
err := fmt.Errorf("Timeout waiting for mount of alicloud disk: %s", err)
|
err := fmt.Errorf("Timeout waiting for mount: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui.Say("Finish mounting disks")
|
ui.Say("Finished mounting disks")
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -42,7 +43,7 @@ func (s *setpRegionCopyAlicloudImage) Run(state multistep.StateBag) multistep.St
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Error copy alicloud images: %s", err))
|
ui.Say(fmt.Sprintf("Error copying images: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
alicloudImages[destinationRegion] = imageId
|
alicloudImages[destinationRegion] = imageId
|
||||||
|
@ -57,7 +58,7 @@ func (s *setpRegionCopyAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
client := state.Get("client").(*ecs.Client)
|
client := state.Get("client").(*ecs.Client)
|
||||||
alicloudImages := state.Get("alicloudimages").(map[string]string)
|
alicloudImages := state.Get("alicloudimages").(map[string]string)
|
||||||
ui.Say(fmt.Sprintf("Cancel copy image because cancelation or error..."))
|
ui.Say(fmt.Sprintf("Cancel copy image because cancellation or error..."))
|
||||||
for copyedRegionId, copyedImageId := range alicloudImages {
|
for copyedRegionId, copyedImageId := range alicloudImages {
|
||||||
if copyedRegionId == s.RegionId {
|
if copyedRegionId == s.RegionId {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
@ -17,7 +18,7 @@ func (s *stepRunAlicloudInstance) Run(state multistep.StateBag) multistep.StepAc
|
||||||
|
|
||||||
err := client.StartInstance(instance.InstanceId)
|
err := client.StartInstance(instance.InstanceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error start alicloud instance: %s", err)
|
err := fmt.Errorf("Error starting instance: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -25,7 +26,7 @@ func (s *stepRunAlicloudInstance) Run(state multistep.StateBag) multistep.StepAc
|
||||||
ui.Say("Alcoud instance starting")
|
ui.Say("Alcoud instance starting")
|
||||||
err = client.WaitForInstance(instance.InstanceId, ecs.Running, ALICLOUD_DEFAULT_TIMEOUT)
|
err = client.WaitForInstance(instance.InstanceId, ecs.Running, ALICLOUD_DEFAULT_TIMEOUT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Starting alicloud instance timeout: %s", err)
|
err := fmt.Errorf("Timeout waiting for instance to start: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -44,11 +45,11 @@ func (s *stepRunAlicloudInstance) Cleanup(state multistep.StateBag) {
|
||||||
instanceAttrubite, _ := client.DescribeInstanceAttribute(instance.InstanceId)
|
instanceAttrubite, _ := client.DescribeInstanceAttribute(instance.InstanceId)
|
||||||
if instanceAttrubite.Status == ecs.Starting || instanceAttrubite.Status == ecs.Running {
|
if instanceAttrubite.Status == ecs.Starting || instanceAttrubite.Status == ecs.Running {
|
||||||
if err := client.StopInstance(instance.InstanceId, true); err != nil {
|
if err := client.StopInstance(instance.InstanceId, true); err != nil {
|
||||||
ui.Say(fmt.Sprintf("Stop alicloud instance %s failed %v", instance.InstanceId, err))
|
ui.Say(fmt.Sprintf("Error stopping instance %s, it may still be around %s", instance.InstanceId, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := client.WaitForInstance(instance.InstanceId, ecs.Stopped, ALICLOUD_DEFAULT_TIMEOUT)
|
err := client.WaitForInstance(instance.InstanceId, ecs.Stopped, ALICLOUD_DEFAULT_TIMEOUT)
|
||||||
ui.Say(fmt.Sprintf("Stop alicloud instance %s failed %v", instance.InstanceId, err))
|
ui.Say(fmt.Sprintf("Error stopping instance %s, it may still be around %s", instance.InstanceId, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -28,7 +29,7 @@ func (s *setpShareAlicloudImage) Run(state multistep.StateBag) multistep.StepAct
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Say(fmt.Sprintf("Modify alicloud image share permission failed: %s", err))
|
ui.Say(fmt.Sprintf("Failed modifying image share permissions: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +43,7 @@ func (s *setpShareAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
client := state.Get("client").(*ecs.Client)
|
client := state.Get("client").(*ecs.Client)
|
||||||
alicloudImages := state.Get("alicloudimages").(map[string]string)
|
alicloudImages := state.Get("alicloudimages").(map[string]string)
|
||||||
ui.Say("Restore alicloud image share permission because cancelations or error...")
|
ui.Say("Restoring image share permission because cancellations or error...")
|
||||||
for copyedRegion, copyedImageId := range alicloudImages {
|
for copyedRegion, copyedImageId := range alicloudImages {
|
||||||
err := client.ModifyImageSharePermission(
|
err := client.ModifyImageSharePermission(
|
||||||
&ecs.ModifyImageSharePermissionArgs{
|
&ecs.ModifyImageSharePermissionArgs{
|
||||||
|
@ -52,7 +53,7 @@ func (s *setpShareAlicloudImage) Cleanup(state multistep.StateBag) {
|
||||||
RemoveAccount: s.AlicloudImageShareAccounts,
|
RemoveAccount: s.AlicloudImageShareAccounts,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Say(fmt.Sprintf("Restore alicloud image share permission failed: %s", err))
|
ui.Say(fmt.Sprintf("Restoring image share permission failed: %s", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue