Merge pull request #7914 from shawnmssu/fix_ucloud_builder
UCloud Builder: update api about stop instance
This commit is contained in:
commit
a99c0802be
|
@ -30,7 +30,7 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag)
|
|||
srcImageId := state.Get("image_id").(string)
|
||||
artifactImages := state.Get("ucloud_images").(*imageInfoSet)
|
||||
expectedImages := newImageInfoSet(nil)
|
||||
ui.Say(fmt.Sprintf("Copying image with %q...", srcImageId))
|
||||
ui.Say(fmt.Sprintf("Copying images from %q...", srcImageId))
|
||||
for _, v := range s.ImageDestinations {
|
||||
if v.ProjectId == s.ProjectId && v.Region == s.RegionId {
|
||||
continue
|
||||
|
@ -59,6 +59,7 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag)
|
|||
ui.Message(fmt.Sprintf("Copying image from %s:%s:%s to %s:%s:%s)",
|
||||
s.ProjectId, s.RegionId, srcImageId, v.ProjectId, v.Region, resp.TargetImageId))
|
||||
}
|
||||
ui.Message("Waiting for the copied images to become available...")
|
||||
|
||||
err := retry.Config{
|
||||
Tries: 200,
|
||||
|
|
|
@ -23,7 +23,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
|
|||
ui := state.Get("ui").(packer.Ui)
|
||||
config := state.Get("config").(*Config)
|
||||
|
||||
ui.Say(fmt.Sprintf("Creating image %s", config.ImageName))
|
||||
ui.Say(fmt.Sprintf("Creating image %s...", config.ImageName))
|
||||
|
||||
req := conn.NewCreateCustomImageRequest()
|
||||
req.ImageName = ucloud.String(config.ImageName)
|
||||
|
@ -34,6 +34,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
|
|||
if err != nil {
|
||||
return halt(state, err, "Error on creating image")
|
||||
}
|
||||
ui.Message(fmt.Sprintf("Waiting for the created image %q to become available...", resp.ImageId))
|
||||
|
||||
err = retry.Config{
|
||||
Tries: 200,
|
||||
|
|
|
@ -141,9 +141,9 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) {
|
|||
}
|
||||
|
||||
if instance.State != instanceStateStopped {
|
||||
stopReq := conn.NewPoweroffUHostInstanceRequest()
|
||||
stopReq := conn.NewStopUHostInstanceRequest()
|
||||
stopReq.UHostId = ucloud.String(s.instanceId)
|
||||
if _, err = conn.PoweroffUHostInstance(stopReq); err != nil {
|
||||
if _, err = conn.StopUHostInstance(stopReq); err != nil {
|
||||
ui.Error(fmt.Sprintf("Error on stopping instance when deleting %q, %s",
|
||||
s.instanceId, err.Error()))
|
||||
return
|
||||
|
|
|
@ -27,7 +27,7 @@ func (s *stepStopInstance) Run(ctx context.Context, state multistep.StateBag) mu
|
|||
}
|
||||
|
||||
if instance.State != instanceStateStopped {
|
||||
stopReq := conn.NewPoweroffUHostInstanceRequest()
|
||||
stopReq := conn.NewStopUHostInstanceRequest()
|
||||
stopReq.UHostId = ucloud.String(instance.UHostId)
|
||||
ui.Say(fmt.Sprintf("Stopping instance %q", instance.UHostId))
|
||||
err = retry.Config{
|
||||
|
@ -37,7 +37,7 @@ func (s *stepStopInstance) Run(ctx context.Context, state multistep.StateBag) mu
|
|||
},
|
||||
RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 6 * time.Second, Multiplier: 2}).Linear,
|
||||
}.Run(ctx, func(ctx context.Context) error {
|
||||
if _, err = conn.PoweroffUHostInstance(stopReq); err != nil {
|
||||
if _, err = conn.StopUHostInstance(stopReq); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -26,7 +26,7 @@ In addition to the options listed here, a
|
|||
[communicator](../templates/communicator.html) can be configured for this
|
||||
builder.
|
||||
|
||||
\~> **Note:** The bulider doesn't support Windows images for now and only supports CentoOS and ubuntu images via SSH anthentication with `ssh_username` (Required) and `ssh_password` (Optional). The `ssh_username` must be `root` for CentOS images and `ubuntu` for Ubuntu images. The `ssh_password` may contain 8-30 characters, and must be consisted with at least 2 items out of the capital letters, lower case letters, numbers and special characters. The special characters include <code>`()~!@#$%^&*-+=_|{}\[]:;'<>,.?/</code>.
|
||||
\~> **Note:** The bulider doesn't support Windows images for now and only supports CentOS and Ubuntu images via SSH anthentication with `ssh_username` (Required) and `ssh_password` (Optional). The `ssh_username` must be `root` for CentOS images and `ubuntu` for Ubuntu images. The `ssh_password` may contain 8-30 characters, and must consist of at least 2 items out of the capital letters, lower case letters, numbers and special characters. The special characters include <code>`()~!@#$%^&*-+=_|{}\[]:;'<>,.?/</code>.
|
||||
|
||||
### Required:
|
||||
|
||||
|
@ -84,9 +84,9 @@ builder.
|
|||
|
||||
- `description` (number) - The copied image description.
|
||||
|
||||
## Basic Example
|
||||
## Examples
|
||||
|
||||
Here is a basic example for build UCloud image.
|
||||
Here is a basic example for build UCloud CentOS image:
|
||||
|
||||
``` json
|
||||
{
|
||||
|
@ -95,6 +95,7 @@ Here is a basic example for build UCloud image.
|
|||
"ucloud_private_key": "{{env `UCLOUD_PRIVATE_KEY`}}",
|
||||
"ucloud_project_id": "{{env `UCLOUD_PROJECT_ID`}}"
|
||||
},
|
||||
|
||||
"builders": [{
|
||||
"type":"ucloud-uhost",
|
||||
"public_key":"{{user `ucloud_public_key`}}",
|
||||
|
@ -110,6 +111,43 @@ Here is a basic example for build UCloud image.
|
|||
}
|
||||
```
|
||||
|
||||
Here is a example for build UCloud Ubuntu image:
|
||||
|
||||
``` json
|
||||
{
|
||||
"variables": {
|
||||
"ucloud_public_key": "{{env `UCLOUD_PUBLIC_KEY`}}",
|
||||
"ucloud_private_key": "{{env `UCLOUD_PRIVATE_KEY`}}",
|
||||
"ucloud_project_id": "{{env `UCLOUD_PROJECT_ID`}}",
|
||||
"password": "ucloud_2019"
|
||||
},
|
||||
|
||||
"builders": [{
|
||||
"type": "ucloud-uhost",
|
||||
"public_key": "{{user `ucloud_public_key`}}",
|
||||
"private_key": "{{user `ucloud_private_key`}}",
|
||||
"project_id": "{{user `ucloud_project_id`}}",
|
||||
"region": "cn-bj2",
|
||||
"availability_zone": "cn-bj2-02",
|
||||
"instance_type": "n-basic-2",
|
||||
"source_image_id": "uimage-irofn4",
|
||||
"ssh_password": "{{user `password`}}",
|
||||
"ssh_username": "ubuntu",
|
||||
"image_name": "packer-test-ubuntu-bj"
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "shell",
|
||||
"execute_command": "echo '{{user `password`}}' | sudo -S '{{.Path}}'",
|
||||
"inline": [
|
||||
"sleep 30",
|
||||
"sudo apt update",
|
||||
"sudo apt install nginx -y"
|
||||
]
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
-> **Note:** Packer can also read the public key and private key from
|
||||
environmental variables. See the configuration reference in the section above
|
||||
for more information on what environmental variables Packer will look for.
|
||||
|
|
Loading…
Reference in New Issue