add options for system disk properties
This commit is contained in:
parent
3315812c2c
commit
c3a60ad0ce
|
@ -1,6 +1,7 @@
|
|||
package ecs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
@ -93,3 +94,61 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
|||
t.Fatal("should have error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_Devices(t *testing.T) {
|
||||
var b Builder
|
||||
config := testBuilderConfig()
|
||||
config["system_disk_mapping"] = map[string]interface{}{
|
||||
"disk_category": "cloud",
|
||||
"disk_description": "system disk",
|
||||
"disk_name": "system_disk",
|
||||
"disk_size": 60,
|
||||
}
|
||||
config["image_disk_mappings"] = []map[string]interface{}{
|
||||
{
|
||||
"disk_category": "cloud_efficiency",
|
||||
"disk_name": "data_disk1",
|
||||
"disk_size": 100,
|
||||
"disk_snapshot_id": "s-1",
|
||||
"disk_description": "data disk1",
|
||||
"disk_device": "/dev/xvdb",
|
||||
"disk_delete_with_instance": false,
|
||||
},
|
||||
{
|
||||
"disk_name": "data_disk2",
|
||||
"disk_device": "/dev/xvdc",
|
||||
},
|
||||
}
|
||||
warnings, err := b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(b.config.ECSSystemDiskMapping, AlicloudDiskDevice{
|
||||
DiskCategory: "cloud",
|
||||
Description: "system disk",
|
||||
DiskName: "system_disk",
|
||||
DiskSize: 60,
|
||||
}) {
|
||||
t.Fatalf("system disk is not set properly, actual: %#v", b.config.ECSSystemDiskMapping)
|
||||
}
|
||||
if !reflect.DeepEqual(b.config.ECSImagesDiskMappings, []AlicloudDiskDevice{
|
||||
{
|
||||
DiskCategory: "cloud_efficiency",
|
||||
DiskName: "data_disk1",
|
||||
DiskSize: 100,
|
||||
SnapshotId: "s-1",
|
||||
Description: "data disk1",
|
||||
Device: "/dev/xvdb",
|
||||
DeleteWithInstance: false,
|
||||
},
|
||||
{
|
||||
DiskName: "data_disk2",
|
||||
Device: "/dev/xvdc",
|
||||
},
|
||||
}) {
|
||||
t.Fatalf("data disks are not set properly, actual: %#v", b.config.ECSImagesDiskMappings)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ type AlicloudDiskDevice struct {
|
|||
}
|
||||
|
||||
type AlicloudDiskDevices struct {
|
||||
ECSSystemDiskMapping AlicloudDiskDevice `mapstructure:"system_disk_mapping"`
|
||||
ECSImagesDiskMappings []AlicloudDiskDevice `mapstructure:"image_disk_mappings"`
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ func (s *stepCreateAlicloudInstance) Run(_ context.Context, state multistep.Stat
|
|||
InstanceName: s.InstanceName,
|
||||
Password: password,
|
||||
ZoneId: s.ZoneId,
|
||||
SystemDisk: systemDeviceToDiskType(config.AlicloudImageConfig.ECSSystemDiskMapping),
|
||||
DataDisk: diskDeviceToDiskType(config.AlicloudImageConfig.ECSImagesDiskMappings),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -147,6 +148,15 @@ func (s *stepCreateAlicloudInstance) getUserData(state multistep.StateBag) (stri
|
|||
|
||||
}
|
||||
|
||||
func systemDeviceToDiskType(systemDisk AlicloudDiskDevice) ecs.SystemDiskType {
|
||||
return ecs.SystemDiskType{
|
||||
DiskName: systemDisk.DiskName,
|
||||
Category: ecs.DiskCategory(systemDisk.DiskCategory),
|
||||
Size: systemDisk.DiskSize,
|
||||
Description: systemDisk.Description,
|
||||
}
|
||||
}
|
||||
|
||||
func diskDeviceToDiskType(diskDevices []AlicloudDiskDevice) []ecs.DataDiskType {
|
||||
result := make([]ecs.DataDiskType, len(diskDevices))
|
||||
for _, diskDevice := range diskDevices {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"secret_key":"{{user `secret_key`}}",
|
||||
"region":"cn-beijing",
|
||||
"image_name":"packer_test",
|
||||
"source_image":"win2008r2_64_ent_sp1_zh-cn_40G_alibase_20170622.vhd",
|
||||
"source_image":"win2008r2_64_ent_sp1_zh-cn_40G_alibase_20170915.vhd",
|
||||
"instance_type":"ecs.n1.tiny",
|
||||
"io_optimized":"true",
|
||||
"internet_charge_type":"PayByTraffic",
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"secret_key":"{{user `secret_key`}}",
|
||||
"region":"cn-beijing",
|
||||
"image_name":"packer_chef2",
|
||||
"source_image":"ubuntu_14_0405_64_40G_alibase_20170625.vhd",
|
||||
"source_image":"ubuntu_14_0405_64_20G_alibase_20170824.vhd",
|
||||
"ssh_username":"root",
|
||||
"instance_type":"ecs.n1.medium",
|
||||
"io_optimized":"true",
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"secret_key":"{{user `secret_key`}}",
|
||||
"region":"cn-beijing",
|
||||
"image_name":"packer_jenkins",
|
||||
"source_image":"ubuntu_14_0405_64_40G_alibase_20170625.vhd",
|
||||
"source_image":"ubuntu_14_0405_64_20G_alibase_20170824.vhd",
|
||||
"ssh_username":"root",
|
||||
"instance_type":"ecs.n1.medium",
|
||||
"io_optimized":"true",
|
||||
|
|
|
@ -76,6 +76,27 @@ builder.
|
|||
- `image_description` (string) - The description of the image, with a length
|
||||
limit of 0 to 256 characters. Leaving it blank means null, which is the
|
||||
default value. It cannot begin with `http://` or `https://`.
|
||||
|
||||
|
||||
- `system_disk_mapping` (image disk mapping) - Image disk mapping for system disk.
|
||||
- `disk_category` (string) - Category of the data disk. Optional values are:
|
||||
- `cloud` - general cloud disk
|
||||
- `cloud_efficiency` - efficiency cloud disk
|
||||
- `cloud_ssd` - cloud SSD
|
||||
|
||||
For phased-out instance types and non-I/O optimized instances, the default value is cloud.
|
||||
Otherwise, the default value is cloud_efficiency.
|
||||
|
||||
- `disk_description` (string) - The value of disk description is blank by default. \[2, 256\] characters.
|
||||
The disk description will appear on the console. It cannot begin with `http://` or `https://`.
|
||||
|
||||
- `disk_name` (string) - The value of disk name is blank by default. \[2, 128\]
|
||||
English or Chinese characters, must begin with an uppercase/lowercase letter
|
||||
or Chinese character. Can contain numbers, `.`, `_` and `-`. The disk name
|
||||
will appear on the console. It cannot begin with `http://` or `https://`.
|
||||
|
||||
- `disk_size` (number) - Size of the system disk, measured in GiB. Value range: \[20, 500\]. The specified value
|
||||
must be equal to or greater than max{20, ImageSize}. Default value: max{40, ImageSize}.
|
||||
|
||||
- `image_disk_mappings` (array of image disk mappings) - Add one or more data
|
||||
disks to the image.
|
||||
|
@ -107,7 +128,7 @@ builder.
|
|||
`.`, `_` and `-`. The disk name will appear on the console. It cannot
|
||||
begin with `http://` or `https://`.
|
||||
|
||||
- `disk_size` (number) - Size of the system disk, in GB, values range:
|
||||
- `disk_size` (number) - Size of the data disk, in GB, values range:
|
||||
- `cloud` - 5 ~ 2000
|
||||
- `cloud_efficiency` - 20 ~ 2048
|
||||
- `cloud_ssd` - 20 ~ 2048
|
||||
|
|
Loading…
Reference in New Issue