Exemple #1
0
// ToMonitorUpdateMap produces a map for updating CONNECT monitors.
func (opts UpdateConnectMonitorOpts) ToMonitorUpdateMap() (map[string]interface{}, error) {
	type m map[string]interface{}

	if !gophercloud.IntWithinRange(opts.AttemptLimit, 1, 10) {
		return m{}, errAttemptLimit
	}
	if !gophercloud.IntWithinRange(opts.Delay, 1, 3600) {
		return m{}, errDelay
	}
	if !gophercloud.IntWithinRange(opts.Timeout, 1, 300) {
		return m{}, errTimeout
	}

	return m{"healthMonitor": m{
		"attemptsBeforeDeactivation": opts.AttemptLimit,
		"delay":   opts.Delay,
		"timeout": opts.Timeout,
		"type":    CONNECT,
	}}, nil
}
Exemple #2
0
// ToMonitorUpdateMap produces a map for updating HTTP(S) monitors.
func (opts UpdateHTTPMonitorOpts) ToMonitorUpdateMap() (map[string]interface{}, error) {
	type m map[string]interface{}

	if !gophercloud.IntWithinRange(opts.AttemptLimit, 1, 10) {
		return m{}, errAttemptLimit
	}
	if !gophercloud.IntWithinRange(opts.Delay, 1, 3600) {
		return m{}, errDelay
	}
	if !gophercloud.IntWithinRange(opts.Timeout, 1, 300) {
		return m{}, errTimeout
	}
	if opts.Type != HTTP && opts.Type != HTTPS {
		return m{}, errors.New("Type must either by HTTP or HTTPS")
	}
	if opts.BodyRegex == "" {
		return m{}, errors.New("BodyRegex is a required field")
	}
	if opts.Path == "" {
		return m{}, errors.New("Path is a required field")
	}
	if opts.StatusRegex == "" {
		return m{}, errors.New("StatusRegex is a required field")
	}

	json := m{
		"attemptsBeforeDeactivation": opts.AttemptLimit,
		"delay":       opts.Delay,
		"timeout":     opts.Timeout,
		"type":        opts.Type,
		"bodyRegex":   opts.BodyRegex,
		"path":        opts.Path,
		"statusRegex": opts.StatusRegex,
	}

	if opts.HostHeader != "" {
		json["hostHeader"] = opts.HostHeader
	}

	return m{"healthMonitor": json}, nil
}