Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 1 | package bootfromvolume |
| 2 | |
| 3 | import ( |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 4 | "errors" |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 5 | |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | type CreateOptsExt struct { |
| 10 | servers.CreateOptsBuilder |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 11 | BDM BlockDeviceMapping |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 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) { |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 17 | if opts.BDM.SourceType != "volume" && opts.BDM.SourceType != "image" && opts.BDM.SourceType != "snapshot" { |
| 18 | return nil, errors.New("SourceType must be one of: volume, image, snapshot.") |
| 19 | } |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 20 | |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 21 | if opts.BDM.UUID == "" { |
| 22 | return nil, errors.New("Required field UUID not set.") |
| 23 | } |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 24 | |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 25 | base, err := opts.CreateOptsBuilder.ToServerCreateMap() |
| 26 | if err != nil { |
| 27 | return nil, err |
| 28 | } |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 29 | |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 30 | serverMap := base["server"].(map[string]interface{}) |
| 31 | serverMap["block_device_mapping_v2"] = opts.BDM |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 32 | |
Jon Perritt | 4149d7c | 2014-10-23 21:23:46 -0500 | [diff] [blame^] | 33 | return base, nil |
Jon Perritt | 654fb0e | 2014-10-23 20:54:14 -0500 | [diff] [blame] | 34 | } |