File: requests.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.0~git20180917.45f1c769-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,768 kB
  • sloc: sh: 98; makefile: 14
file content (106 lines) | stat: -rw-r--r-- 3,507 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package diskconfig

import (
	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
)

// DiskConfig represents one of the two possible settings for the DiskConfig
// option when creating, rebuilding, or resizing servers: Auto or Manual.
type DiskConfig string

const (
	// Auto builds a server with a single partition the size of the target flavor
	// disk and automatically adjusts the filesystem to fit the entire partition.
	// Auto may only be used with images and servers that use a single EXT3
	// partition.
	Auto DiskConfig = "AUTO"

	// Manual builds a server using whatever partition scheme and filesystem are
	// present in the source image. If the target flavor disk is larger, the
	// remaining space is left unpartitioned. This enables images to have non-EXT3
	// filesystems, multiple partitions, and so on, and enables you to manage the
	// disk configuration. It also results in slightly shorter boot times.
	Manual DiskConfig = "MANUAL"
)

// CreateOptsExt adds a DiskConfig option to the base CreateOpts.
type CreateOptsExt struct {
	servers.CreateOptsBuilder

	// DiskConfig [optional] controls how the created server's disk is partitioned.
	DiskConfig DiskConfig `json:"OS-DCF:diskConfig,omitempty"`
}

// ToServerCreateMap adds the diskconfig option to the base server creation options.
func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error) {
	base, err := opts.CreateOptsBuilder.ToServerCreateMap()
	if err != nil {
		return nil, err
	}

	if string(opts.DiskConfig) == "" {
		return base, nil
	}

	serverMap := base["server"].(map[string]interface{})
	serverMap["OS-DCF:diskConfig"] = string(opts.DiskConfig)

	return base, nil
}

// RebuildOptsExt adds a DiskConfig option to the base RebuildOpts.
type RebuildOptsExt struct {
	servers.RebuildOptsBuilder

	// DiskConfig controls how the rebuilt server's disk is partitioned.
	DiskConfig DiskConfig `json:"OS-DCF:diskConfig,omitempty"`
}

// ToServerRebuildMap adds the diskconfig option to the base server rebuild options.
func (opts RebuildOptsExt) ToServerRebuildMap() (map[string]interface{}, error) {
	if opts.DiskConfig != Auto && opts.DiskConfig != Manual {
		err := gophercloud.ErrInvalidInput{}
		err.Argument = "diskconfig.RebuildOptsExt.DiskConfig"
		err.Info = "Must be either diskconfig.Auto or diskconfig.Manual"
		return nil, err
	}

	base, err := opts.RebuildOptsBuilder.ToServerRebuildMap()
	if err != nil {
		return nil, err
	}

	serverMap := base["rebuild"].(map[string]interface{})
	serverMap["OS-DCF:diskConfig"] = string(opts.DiskConfig)

	return base, nil
}

// ResizeOptsExt adds a DiskConfig option to the base server resize options.
type ResizeOptsExt struct {
	servers.ResizeOptsBuilder

	// DiskConfig [optional] controls how the resized server's disk is partitioned.
	DiskConfig DiskConfig
}

// ToServerResizeMap adds the diskconfig option to the base server creation options.
func (opts ResizeOptsExt) ToServerResizeMap() (map[string]interface{}, error) {
	if opts.DiskConfig != Auto && opts.DiskConfig != Manual {
		err := gophercloud.ErrInvalidInput{}
		err.Argument = "diskconfig.ResizeOptsExt.DiskConfig"
		err.Info = "Must be either diskconfig.Auto or diskconfig.Manual"
		return nil, err
	}

	base, err := opts.ResizeOptsBuilder.ToServerResizeMap()
	if err != nil {
		return nil, err
	}

	serverMap := base["resize"].(map[string]interface{})
	serverMap["OS-DCF:diskConfig"] = string(opts.DiskConfig)

	return base, nil
}