blob: fe90e722cbd8e9b3d776b3475f5c5bab39dfab8a [file] [log] [blame]
Jamie Hannaforde5145412014-11-06 12:35:59 +01001package sessions
2
3import (
4 "github.com/mitchellh/mapstructure"
5
6 "github.com/rackspace/gophercloud"
7)
8
9// Type represents the type of session persistence being used.
10type Type string
11
12const (
13 // HTTPCOOKIE is a session persistence mechanism that inserts an HTTP cookie
14 // and is used to determine the destination back-end node. This is supported
15 // for HTTP load balancing only.
16 HTTPCOOKIE Type = "HTTP_COOKIE"
17
18 // SOURCEIP is a session persistence mechanism that keeps track of the source
19 // IP address that is mapped and is able to determine the destination
20 // back-end node. This is supported for HTTPS pass-through and non-HTTP load
21 // balancing only.
22 SOURCEIP Type = "SOURCE_IP"
23)
24
25// SessionPersistence indicates how a load balancer is using session persistence
26type SessionPersistence struct {
27 Type Type `mapstructure:"persistenceType"`
28}
29
30// EnableResult represents the result of an enable operation.
31type EnableResult struct {
32 gophercloud.ErrResult
33}
34
35// DisableResult represents the result of a disable operation.
36type DisableResult struct {
37 gophercloud.ErrResult
38}
39
40// GetResult represents the result of a get operation.
41type GetResult struct {
42 gophercloud.Result
43}
44
Jamie Hannaford227d9592014-11-13 10:32:07 +010045// Extract interprets a GetResult as an SP, if possible.
Jamie Hannaforde5145412014-11-06 12:35:59 +010046func (r GetResult) Extract() (*SessionPersistence, error) {
47 if r.Err != nil {
48 return nil, r.Err
49 }
50
51 var response struct {
52 SP SessionPersistence `mapstructure:"sessionPersistence"`
53 }
54
55 err := mapstructure.Decode(r.Body, &response)
56
57 return &response.SP, err
58}