blob: b0cf61edb1b136dcc84112bbe8e549b208971a37 [file] [log] [blame]
Jon Perritt654fb0e2014-10-23 20:54:14 -05001package bootfromvolume
2
3import (
4 "errors"
5
6 "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
7)
8
9type 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.
16func (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}