Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame^] | 1 | package bootfromvolume |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
| 7 | ) |
| 8 | |
| 9 | type CreateOptsExt struct { |
| 10 | servers.CreateOptsBuilder |
| 11 | BlockDeviceMapping BlockDeviceMapping |
| 12 | } |
| 13 | |
| 14 | // ToServerCreateMap adds the block device mapping option to the base server |
| 15 | // creation options. |
| 16 | func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error) { |
| 17 | if opts.SourceType != "volume" && opts.SourceType != "image" && opts.SourceType != "snapshot" { |
| 18 | return nil, errors.New("SourceType must be one of: volume, image, snapshot.") |
| 19 | } |
| 20 | |
| 21 | if opts.UUID == "" { |
| 22 | return nil, errors.New("Required field UUID not set.") |
| 23 | } |
| 24 | |
| 25 | base := opts.CreateOptsBuilder.ToServerCreateMap() |
| 26 | |
| 27 | serverMap := base["server"].(map[string]interface{}) |
| 28 | serverMap["block_device_mapping_v2"] = opts.BlockDeviceMapping |
| 29 | |
| 30 | return base |
| 31 | } |