update bucket about no create

This commit is contained in:
mingsheng.su 2019-10-23 10:41:38 +08:00 committed by Megan Marsh
parent 083d7896f4
commit 1099777978
4 changed files with 12 additions and 19 deletions

View File

@ -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

View File

@ -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",

View File

@ -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

View File

@ -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`.