diff --git a/examples/ucloud/local/http/centos-6.10/ks.cfg b/examples/ucloud/local/http/centos-6.10/ks.cfg index 31f57af6d..b6cf3436e 100644 --- a/examples/ucloud/local/http/centos-6.10/ks.cfg +++ b/examples/ucloud/local/http/centos-6.10/ks.cfg @@ -3,7 +3,7 @@ cdrom lang en_US.UTF-8 keyboard us network --bootproto=dhcp -rootpw ucloud_2019 +rootpw ucloud_packer firewall --disabled selinux --permissive timezone UTC diff --git a/examples/ucloud/local/local.json b/examples/ucloud/local/local.json index df41acb50..ae760194b 100644 --- a/examples/ucloud/local/local.json +++ b/examples/ucloud/local/local.json @@ -3,7 +3,6 @@ "ucloud_private_key": "{{env `UCLOUD_PRIVATE_KEY`}}", "ucloud_project_id": "{{env `UCLOUD_PROJECT_ID`}}", "disk_size": "4096", - "headless": "", "iso_checksum": "0da4a1206e7642906e33c0f155d2f835", "iso_checksum_type": "md5", "iso_name": "CentOS-6.10-x86_64-minimal.iso", @@ -20,14 +19,13 @@ ], "boot_wait": "10s", "disk_size": "{{user `disk_size`}}", - "headless": "{{ user `headless` }}", "http_directory": "http", "iso_checksum": "{{user `iso_checksum`}}", "iso_checksum_type": "{{user `iso_checksum_type`}}", "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", "output_directory": "packer-{{user `template`}}-qemu", - "shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p", - "ssh_password": "ucloud_2019", + "shutdown_command": "echo 'packer'|sudo -S shutdown -P now", + "ssh_password": "ucloud_packer", "ssh_port": 22, "ssh_username": "root", "ssh_timeout": "10000s", diff --git a/post-processor/ucloud-import/post-processor.go b/post-processor/ucloud-import/post-processor.go index a5a2e73cd..1223b3257 100644 --- a/post-processor/ucloud-import/post-processor.go +++ b/post-processor/ucloud-import/post-processor.go @@ -178,9 +178,9 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact BucketHost: "api.ucloud.cn", } - // query or create bucket - if err := queryOrCreateBucket(ufileconn, config); err != nil { - return nil, false, false, fmt.Errorf("Failed to query or create bucket, %s", err) + // query bucket + if err := queryBucket(ufileconn, config); err != nil { + return nil, false, false, fmt.Errorf("Failed to query bucket, %s", err) } bucketUrl := fmt.Sprintf("http://" + bucketName + "." + convertedRegion + ".ufileos.com") @@ -270,7 +270,7 @@ func (p *PostProcessor) buildImportImageRequest(conn *uhost.UHostClient, private return req } -func queryOrCreateBucket(conn *ufile.UFileClient, config *ufsdk.Config) error { +func queryBucket(conn *ufile.UFileClient, config *ufsdk.Config) error { var limit = 100 var offset int var bucketList []ufile.UFileBucketSet @@ -302,14 +302,7 @@ func queryOrCreateBucket(conn *ufile.UFileClient, config *ufsdk.Config) error { } if !ucloudcommon.IsStringIn(config.BucketName, bucketNames) { - req := conn.NewCreateBucketRequest() - req.BucketName = ucloud.String(config.BucketName) - req.Type = ucloud.String("private") - - _, err := conn.CreateBucket(req) - if err != nil { - return fmt.Errorf("error on creating bucket %s, %s", config.BucketName, err) - } + return fmt.Errorf("the bucket %s is not exit", config.BucketName) } return nil @@ -335,7 +328,7 @@ func uploadFile(conn *ufile.UFileClient, config *ufsdk.Config, keyName, source s } if resp.DataSet[0].Type == "private" { - return reqFile.GetPrivateURL(keyName, 24*60*60), nil + return reqFile.GetPrivateURL(keyName, time.Duration(24*60*60)*time.Second), nil } return reqFile.GetPublicURL(keyName), nil diff --git a/website/source/docs/post-processors/ucloud-import.html.md b/website/source/docs/post-processors/ucloud-import.html.md index 08b8c7b2c..7b75f6b53 100644 --- a/website/source/docs/post-processors/ucloud-import.html.md +++ b/website/source/docs/post-processors/ucloud-import.html.md @@ -12,6 +12,8 @@ Type: `ucloud-import` The Packer UCloud Import post-processor takes the RAW, VHD, VMDK, or qcow2 artifact from various builders and imports it to UCloud customized image list for UHost Instance. +~> **Note** Some regions don't support image import. You may refer to [ucloud console](https://console.ucloud.cn/uhost/uimage) for detail. If you want to import to such regions, please import the image in `cn-bj2` at first, and then copying the image to the target region. + ## How Does it Work? The import process operates by making a temporary copy of the RAW, VHD, VMDK, or qcow2 to an UFile bucket, and calling an import task in UHost on the RAW, VHD, VMDK, or qcow2 file. Once completed, an UCloud UHost Image is returned. The temporary RAW, VHD, VMDK, or qcow2 copy in UFile can be discarded after the import is complete. @@ -33,7 +35,7 @@ are two categories: required and optional parameters. - `image_name` - (string) The name of the user-defined image, which contains 1-63 characters and only support Chinese, English, numbers, '-_,.:[]'. -- `ufile_bucket_name` (string) - The name of the ufile bucket where the RAW, VHD, VMDK, or qcow2 file will be copied to for import. If the Bucket isn't exist, post-process will create it for you. +- `ufile_bucket_name` (string) - The name of the ufile bucket where the RAW, VHD, VMDK, or qcow2 file will be copied to for import. This bucket must exist when the post-processor is run. - `image_os_type` (string) - Type of the OS. Possible values are: `CentOS`, `Ubuntu`, `Windows`, `RedHat`, `Debian`, `Other`.