github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/l7policies/results.go (about)

     1  package l7policies
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // L7Policy is a collection of L7 rules associated with a Listener, and which
     9  // may also have an association to a back-end pool.
    10  type L7Policy struct {
    11  	// The unique ID for the L7 policy.
    12  	ID string `json:"id"`
    13  
    14  	// Name of the L7 policy.
    15  	Name string `json:"name"`
    16  
    17  	// The ID of the listener.
    18  	ListenerID string `json:"listener_id"`
    19  
    20  	// The L7 policy action. One of REDIRECT_PREFIX, REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
    21  	Action string `json:"action"`
    22  
    23  	// The position of this policy on the listener.
    24  	Position int32 `json:"position"`
    25  
    26  	// A human-readable description for the resource.
    27  	Description string `json:"description"`
    28  
    29  	// ProjectID is the UUID of the project who owns the L7 policy in octavia.
    30  	// Only administrative users can specify a project UUID other than their own.
    31  	ProjectID string `json:"project_id"`
    32  
    33  	// Requests matching this policy will be redirected to the pool with this ID.
    34  	// Only valid if action is REDIRECT_TO_POOL.
    35  	RedirectPoolID string `json:"redirect_pool_id"`
    36  
    37  	// Requests matching this policy will be redirected to this Prefix URL.
    38  	// Only valid if action is REDIRECT_PREFIX.
    39  	RedirectPrefix string `json:"redirect_prefix"`
    40  
    41  	// Requests matching this policy will be redirected to this URL.
    42  	// Only valid if action is REDIRECT_TO_URL.
    43  	RedirectURL string `json:"redirect_url"`
    44  
    45  	// Requests matching this policy will be redirected to the specified URL or Prefix URL
    46  	// with the HTTP response code. Valid if action is REDIRECT_TO_URL or REDIRECT_PREFIX.
    47  	RedirectHttpCode int32 `json:"redirect_http_code"`
    48  
    49  	// The administrative state of the L7 policy, which is up (true) or down (false).
    50  	AdminStateUp bool `json:"admin_state_up"`
    51  
    52  	// The provisioning status of the L7 policy.
    53  	// This value is ACTIVE, PENDING_* or ERROR.
    54  	ProvisioningStatus string `json:"provisioning_status"`
    55  
    56  	// The operating status of the L7 policy.
    57  	OperatingStatus string `json:"operating_status"`
    58  
    59  	// Rules are List of associated L7 rule IDs.
    60  	Rules []Rule `json:"rules"`
    61  }
    62  
    63  // Rule represents layer 7 load balancing rule.
    64  type Rule struct {
    65  	// The unique ID for the L7 rule.
    66  	ID string `json:"id"`
    67  
    68  	// The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH.
    69  	RuleType string `json:"type"`
    70  
    71  	// The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH.
    72  	CompareType string `json:"compare_type"`
    73  
    74  	// The value to use for the comparison. For example, the file type to compare.
    75  	Value string `json:"value"`
    76  
    77  	// ProjectID is the UUID of the project who owns the rule in octavia.
    78  	// Only administrative users can specify a project UUID other than their own.
    79  	ProjectID string `json:"project_id"`
    80  
    81  	// The key to use for the comparison. For example, the name of the cookie to evaluate.
    82  	Key string `json:"key"`
    83  
    84  	// When true the logic of the rule is inverted. For example, with invert true,
    85  	// equal to would become not equal to. Default is false.
    86  	Invert bool `json:"invert"`
    87  
    88  	// The administrative state of the L7 rule, which is up (true) or down (false).
    89  	AdminStateUp bool `json:"admin_state_up"`
    90  
    91  	// The provisioning status of the L7 rule.
    92  	// This value is ACTIVE, PENDING_* or ERROR.
    93  	ProvisioningStatus string `json:"provisioning_status"`
    94  
    95  	// The operating status of the L7 policy.
    96  	OperatingStatus string `json:"operating_status"`
    97  }
    98  
    99  type commonResult struct {
   100  	gophercloud.Result
   101  }
   102  
   103  // Extract is a function that accepts a result and extracts a l7policy.
   104  func (r commonResult) Extract() (*L7Policy, error) {
   105  	var s struct {
   106  		L7Policy *L7Policy `json:"l7policy"`
   107  	}
   108  	err := r.ExtractInto(&s)
   109  	return s.L7Policy, err
   110  }
   111  
   112  // CreateResult represents the result of a Create operation. Call its Extract
   113  // method to interpret the result as a L7Policy.
   114  type CreateResult struct {
   115  	commonResult
   116  }
   117  
   118  // L7PolicyPage is the page returned by a pager when traversing over a
   119  // collection of l7policies.
   120  type L7PolicyPage struct {
   121  	pagination.LinkedPageBase
   122  }
   123  
   124  // NextPageURL is invoked when a paginated collection of l7policies has reached
   125  // the end of a page and the pager seeks to traverse over a new one. In order
   126  // to do this, it needs to construct the next page's URL.
   127  func (r L7PolicyPage) NextPageURL() (string, error) {
   128  	var s struct {
   129  		Links []gophercloud.Link `json:"l7policies_links"`
   130  	}
   131  	err := r.ExtractInto(&s)
   132  	if err != nil {
   133  		return "", err
   134  	}
   135  	return gophercloud.ExtractNextURL(s.Links)
   136  }
   137  
   138  // IsEmpty checks whether a L7PolicyPage struct is empty.
   139  func (r L7PolicyPage) IsEmpty() (bool, error) {
   140  	if r.StatusCode == 204 {
   141  		return true, nil
   142  	}
   143  
   144  	is, err := ExtractL7Policies(r)
   145  	return len(is) == 0, err
   146  }
   147  
   148  // ExtractL7Policies accepts a Page struct, specifically a L7PolicyPage struct,
   149  // and extracts the elements into a slice of L7Policy structs. In other words,
   150  // a generic collection is mapped into a relevant slice.
   151  func ExtractL7Policies(r pagination.Page) ([]L7Policy, error) {
   152  	var s struct {
   153  		L7Policies []L7Policy `json:"l7policies"`
   154  	}
   155  	err := (r.(L7PolicyPage)).ExtractInto(&s)
   156  	return s.L7Policies, err
   157  }
   158  
   159  // GetResult represents the result of a Get operation. Call its Extract
   160  // method to interpret the result as a L7Policy.
   161  type GetResult struct {
   162  	commonResult
   163  }
   164  
   165  // DeleteResult represents the result of a Delete operation. Call its
   166  // ExtractErr method to determine if the request succeeded or failed.
   167  type DeleteResult struct {
   168  	gophercloud.ErrResult
   169  }
   170  
   171  // UpdateResult represents the result of an Update operation. Call its Extract
   172  // method to interpret the result as a L7Policy.
   173  type UpdateResult struct {
   174  	commonResult
   175  }
   176  
   177  type commonRuleResult struct {
   178  	gophercloud.Result
   179  }
   180  
   181  // Extract is a function that accepts a result and extracts a rule.
   182  func (r commonRuleResult) Extract() (*Rule, error) {
   183  	var s struct {
   184  		Rule *Rule `json:"rule"`
   185  	}
   186  	err := r.ExtractInto(&s)
   187  	return s.Rule, err
   188  }
   189  
   190  // CreateRuleResult represents the result of a CreateRule operation.
   191  // Call its Extract method to interpret it as a Rule.
   192  type CreateRuleResult struct {
   193  	commonRuleResult
   194  }
   195  
   196  // RulePage is the page returned by a pager when traversing over a
   197  // collection of Rules in a L7Policy.
   198  type RulePage struct {
   199  	pagination.LinkedPageBase
   200  }
   201  
   202  // NextPageURL is invoked when a paginated collection of rules has reached
   203  // the end of a page and the pager seeks to traverse over a new one. In order
   204  // to do this, it needs to construct the next page's URL.
   205  func (r RulePage) NextPageURL() (string, error) {
   206  	var s struct {
   207  		Links []gophercloud.Link `json:"rules_links"`
   208  	}
   209  	err := r.ExtractInto(&s)
   210  	if err != nil {
   211  		return "", err
   212  	}
   213  	return gophercloud.ExtractNextURL(s.Links)
   214  }
   215  
   216  // IsEmpty checks whether a RulePage struct is empty.
   217  func (r RulePage) IsEmpty() (bool, error) {
   218  	if r.StatusCode == 204 {
   219  		return true, nil
   220  	}
   221  
   222  	is, err := ExtractRules(r)
   223  	return len(is) == 0, err
   224  }
   225  
   226  // ExtractRules accepts a Page struct, specifically a RulePage struct,
   227  // and extracts the elements into a slice of Rules structs. In other words,
   228  // a generic collection is mapped into a relevant slice.
   229  func ExtractRules(r pagination.Page) ([]Rule, error) {
   230  	var s struct {
   231  		Rules []Rule `json:"rules"`
   232  	}
   233  	err := (r.(RulePage)).ExtractInto(&s)
   234  	return s.Rules, err
   235  }
   236  
   237  // GetRuleResult represents the result of a GetRule operation.
   238  // Call its Extract method to interpret it as a Rule.
   239  type GetRuleResult struct {
   240  	commonRuleResult
   241  }
   242  
   243  // DeleteRuleResult represents the result of a DeleteRule operation.
   244  // Call its ExtractErr method to determine if the request succeeded or failed.
   245  type DeleteRuleResult struct {
   246  	gophercloud.ErrResult
   247  }
   248  
   249  // UpdateRuleResult represents the result of an UpdateRule operation.
   250  // Call its Extract method to interpret it as a Rule.
   251  type UpdateRuleResult struct {
   252  	commonRuleResult
   253  }