blob: bbef496cab3ac298572eec1b219bef9f5f06e300 [file] [log] [blame]
Jon Perritt654fb0e2014-10-23 20:54:14 -05001package bootfromvolume
2
3import (
Jon Perritt4149d7c2014-10-23 21:23:46 -05004 "errors"
Jon Perritt654fb0e2014-10-23 20:54:14 -05005
Jon Perritt4149d7c2014-10-23 21:23:46 -05006 "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
Jon Perritt654fb0e2014-10-23 20:54:14 -05007)
8
9type CreateOptsExt struct {
10 servers.CreateOptsBuilder
Jon Perritt4149d7c2014-10-23 21:23:46 -050011 BDM BlockDeviceMapping
Jon Perritt654fb0e2014-10-23 20:54:14 -050012}
13
14// ToServerCreateMap adds the block device mapping option to the base server
15// creation options.
16func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error) {
Jon Perritt4149d7c2014-10-23 21:23:46 -050017 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 Perritt654fb0e2014-10-23 20:54:14 -050020
Jon Perritt4149d7c2014-10-23 21:23:46 -050021 if opts.BDM.UUID == "" {
22 return nil, errors.New("Required field UUID not set.")
23 }
Jon Perritt654fb0e2014-10-23 20:54:14 -050024
Jon Perritt4149d7c2014-10-23 21:23:46 -050025 base, err := opts.CreateOptsBuilder.ToServerCreateMap()
26 if err != nil {
27 return nil, err
28 }
Jon Perritt654fb0e2014-10-23 20:54:14 -050029
Jon Perritt4149d7c2014-10-23 21:23:46 -050030 serverMap := base["server"].(map[string]interface{})
31 serverMap["block_device_mapping_v2"] = opts.BDM
Jon Perritt654fb0e2014-10-23 20:54:14 -050032
Jon Perritt4149d7c2014-10-23 21:23:46 -050033 return base, nil
Jon Perritt654fb0e2014-10-23 20:54:14 -050034}