github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/diskconfig/requests.go (about) 1 package diskconfig 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/openstack/compute/v2/servers" 6 ) 7 8 // DiskConfig represents one of the two possible settings for the DiskConfig 9 // option when creating, rebuilding, or resizing servers: Auto or Manual. 10 type DiskConfig string 11 12 const ( 13 // Auto builds a server with a single partition the size of the target flavor 14 // disk and automatically adjusts the filesystem to fit the entire partition. 15 // Auto may only be used with images and servers that use a single EXT3 16 // partition. 17 Auto DiskConfig = "AUTO" 18 19 // Manual builds a server using whatever partition scheme and filesystem are 20 // present in the source image. If the target flavor disk is larger, the 21 // remaining space is left unpartitioned. This enables images to have non-EXT3 22 // filesystems, multiple partitions, and so on, and enables you to manage the 23 // disk configuration. It also results in slightly shorter boot times. 24 Manual DiskConfig = "MANUAL" 25 ) 26 27 // CreateOptsExt adds a DiskConfig option to the base CreateOpts. 28 type CreateOptsExt struct { 29 servers.CreateOptsBuilder 30 31 // DiskConfig [optional] controls how the created server's disk is partitioned. 32 DiskConfig DiskConfig `json:"OS-DCF:diskConfig,omitempty"` 33 } 34 35 // ToServerCreateMap adds the diskconfig option to the base server creation options. 36 func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error) { 37 base, err := opts.CreateOptsBuilder.ToServerCreateMap() 38 if err != nil { 39 return nil, err 40 } 41 42 if string(opts.DiskConfig) == "" { 43 return base, nil 44 } 45 46 serverMap := base["server"].(map[string]interface{}) 47 serverMap["OS-DCF:diskConfig"] = string(opts.DiskConfig) 48 49 return base, nil 50 } 51 52 // RebuildOptsExt adds a DiskConfig option to the base RebuildOpts. 53 type RebuildOptsExt struct { 54 servers.RebuildOptsBuilder 55 56 // DiskConfig controls how the rebuilt server's disk is partitioned. 57 DiskConfig DiskConfig `json:"OS-DCF:diskConfig,omitempty"` 58 } 59 60 // ToServerRebuildMap adds the diskconfig option to the base server rebuild options. 61 func (opts RebuildOptsExt) ToServerRebuildMap() (map[string]interface{}, error) { 62 if opts.DiskConfig != Auto && opts.DiskConfig != Manual { 63 err := golangsdk.ErrInvalidInput{} 64 err.Argument = "diskconfig.RebuildOptsExt.DiskConfig" 65 err.Info = "Must be either diskconfig.Auto or diskconfig.Manual" 66 return nil, err 67 } 68 69 base, err := opts.RebuildOptsBuilder.ToServerRebuildMap() 70 if err != nil { 71 return nil, err 72 } 73 74 serverMap := base["rebuild"].(map[string]interface{}) 75 serverMap["OS-DCF:diskConfig"] = string(opts.DiskConfig) 76 77 return base, nil 78 } 79 80 // ResizeOptsExt adds a DiskConfig option to the base server resize options. 81 type ResizeOptsExt struct { 82 servers.ResizeOptsBuilder 83 84 // DiskConfig [optional] controls how the resized server's disk is partitioned. 85 DiskConfig DiskConfig 86 } 87 88 // ToServerResizeMap adds the diskconfig option to the base server creation options. 89 func (opts ResizeOptsExt) ToServerResizeMap() (map[string]interface{}, error) { 90 if opts.DiskConfig != Auto && opts.DiskConfig != Manual { 91 err := golangsdk.ErrInvalidInput{} 92 err.Argument = "diskconfig.ResizeOptsExt.DiskConfig" 93 err.Info = "Must be either diskconfig.Auto or diskconfig.Manual" 94 return nil, err 95 } 96 97 base, err := opts.ResizeOptsBuilder.ToServerResizeMap() 98 if err != nil { 99 return nil, err 100 } 101 102 serverMap := base["resize"].(map[string]interface{}) 103 serverMap["OS-DCF:diskConfig"] = string(opts.DiskConfig) 104 105 return base, nil 106 }