Esempio n. 1
0
// ToServerCreateMap adds the block device mapping 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 len(opts.BlockDevice) == 0 {
		err := gophercloud.ErrMissingInput{}
		err.Argument = "bootfromvolume.CreateOptsExt.BlockDevice"
		return nil, err
	}

	serverMap := base["server"].(map[string]interface{})

	blockDevice := make([]map[string]interface{}, len(opts.BlockDevice))

	for i, bd := range opts.BlockDevice {
		b, err := gophercloud.BuildRequestBody(bd, "")
		if err != nil {
			return nil, err
		}
		blockDevice[i] = b
	}
	serverMap["block_device_mapping_v2"] = blockDevice

	return base, nil
}
Esempio n. 2
0
// ToUserCreateMap assembles a request body based on the contents of a CreateOpts.
func (opts CreateOpts) ToUserCreateMap() (map[string]interface{}, error) {
	if opts.Name == "" && opts.Username == "" {
		err := gophercloud.ErrMissingInput{}
		err.Argument = "users.CreateOpts.Name/users.CreateOpts.Username"
		err.Info = "Either a Name or Username must be provided"
		return nil, err
	}
	return gophercloud.BuildRequestBody(opts, "user")
}
Esempio n. 3
0
// ToLBMonitorCreateMap allows CreateOpts to satisfy the CreateOptsBuilder
// interface
func (opts CreateOpts) ToLBMonitorCreateMap() (map[string]interface{}, error) {
	if opts.Type == TypeHTTP || opts.Type == TypeHTTPS {
		if opts.URLPath == "" {
			err := gophercloud.ErrMissingInput{}
			err.Argument = "monitors.CreateOpts.URLPath"
			return nil, err
		}
		if opts.ExpectedCodes == "" {
			err := gophercloud.ErrMissingInput{}
			err.Argument = "monitors.CreateOpts.ExpectedCodes"
			return nil, err
		}
	}
	if opts.Delay < opts.Timeout {
		err := gophercloud.ErrInvalidInput{}
		err.Argument = "monitors.CreateOpts.Delay/monitors.CreateOpts.Timeout"
		err.Info = "Delay must be greater than or equal to timeout"
		return nil, err
	}
	return gophercloud.BuildRequestBody(opts, "health_monitor")
}