l7policies

package
v0.0.0-...-e621b23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package l7policies provides information and interaction with L7Policies and Rules of the LBaaS v2 extension for the OpenStack Networking service.

Example to Create a L7Policy

createOpts := l7policies.CreateOpts{
	Name:        "redirect-example.com",
	ListenerID:  "023f2e34-7806-443b-bfae-16c324569a3d",
	Action:      l7policies.ActionRedirectToURL,
	RedirectURL: "http://www.example.com",
}
l7policy, err := l7policies.Create(lbClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to List L7Policies

listOpts := l7policies.ListOpts{
	ListenerID: "c79a4468-d788-410c-bf79-9a8ef6354852",
}
allPages, err := l7policies.List(lbClient, listOpts).AllPages()
if err != nil {
	panic(err)
}
allL7Policies, err := l7policies.ExtractL7Policies(allPages)
if err != nil {
	panic(err)
}
for _, l7policy := range allL7Policies {
	fmt.Printf("%+v\n", l7policy)
}

Example to Get a L7Policy

l7policy, err := l7policies.Get(lbClient, "023f2e34-7806-443b-bfae-16c324569a3d").Extract()
if err != nil {
	panic(err)
}

Example to Delete a L7Policy

l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64"
err := l7policies.Delete(lbClient, l7policyID).ExtractErr()
if err != nil {
	panic(err)
}

Example to Update a L7Policy

l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64"
name := "new-name"
updateOpts := l7policies.UpdateOpts{
	Name: &name,
}
l7policy, err := l7policies.Update(lbClient, l7policyID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Create a Rule

l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64"
createOpts := l7policies.CreateRuleOpts{
	RuleType:    l7policies.TypePath,
	CompareType: l7policies.CompareTypeRegex,
	Value:       "/images*",
}
rule, err := l7policies.CreateRule(lbClient, l7policyID, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to List L7 Rules

l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64"
listOpts := l7policies.ListRulesOpts{
	RuleType: l7policies.TypePath,
}
allPages, err := l7policies.ListRules(lbClient, l7policyID, listOpts).AllPages()
if err != nil {
	panic(err)
}
allRules, err := l7policies.ExtractRules(allPages)
if err != nil {
	panic(err)
}
for _, rule := allRules {
	fmt.Printf("%+v\n", rule)
}

Example to Get a l7 rule

l7rule, err := l7policies.GetRule(lbClient, "023f2e34-7806-443b-bfae-16c324569a3d", "53ad8ab8-40fa-11e8-a508-00224d6b7bc1").Extract()
if err != nil {
	panic(err)
}

Example to Delete a l7 rule

l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64"
ruleID := "64dba99f-8af8-4200-8882-e32a0660f23e"
err := l7policies.DeleteRule(lbClient, l7policyID, ruleID).ExtractErr()
if err != nil {
	panic(err)
}

Example to Update a Rule

l7policyID := "d67d56a6-4a86-4688-a282-f46444705c64"
ruleID := "64dba99f-8af8-4200-8882-e32a0660f23e"
updateOpts := l7policies.UpdateRuleOpts{
	RuleType:    l7policies.TypePath,
	CompareType: l7policies.CompareTypeRegex,
	Value:       "/images/special*",
}
rule, err := l7policies.UpdateRule(lbClient, l7policyID, ruleID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Index

Constants

View Source
const (
	ActionRedirectToPool Action = "REDIRECT_TO_POOL"
	ActionRedirectToURL  Action = "REDIRECT_TO_URL"
	ActionReject         Action = "REJECT"

	TypeCookie   RuleType = "COOKIE"
	TypeFileType RuleType = "FILE_TYPE"
	TypeHeader   RuleType = "HEADER"
	TypeHostName RuleType = "HOST_NAME"
	TypePath     RuleType = "PATH"

	CompareTypeContains  CompareType = "CONTAINS"
	CompareTypeEndWith   CompareType = "ENDS_WITH"
	CompareTypeEqual     CompareType = "EQUAL_TO"
	CompareTypeRegex     CompareType = "REGEX"
	CompareTypeStartWith CompareType = "STARTS_WITH"
)

Variables

This section is empty.

Functions

func List

List returns a Pager which allows you to iterate over a collection of l7policies. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.

Default policy settings return only those l7policies that are owned by the project who submits the request, unless an admin user submits the request.

func ListRules

ListRules returns a Pager which allows you to iterate over a collection of rules. It accepts a ListRulesOptsBuilder, which allows you to filter and sort the returned collection for greater efficiency.

Default policy settings return only those rules that are owned by the project who submits the request, unless an admin user submits the request.

Types

type Action

type Action string

type CompareType

type CompareType string

type CreateOpts

type CreateOpts struct {
	// Name of the L7 policy.
	Name string `json:"name,omitempty"`

	// The ID of the listener.
	ListenerID string `json:"listener_id" required:"true"`

	// The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
	Action Action `json:"action" required:"true"`

	// The position of this policy on the listener.
	Position int32 `json:"position,omitempty"`

	// A human-readable description for the resource.
	Description string `json:"description,omitempty"`

	// ProjectID is the UUID of the project who owns the L7 policy in octavia.
	// Only administrative users can specify a project UUID other than their own.
	ProjectID string `json:"project_id,omitempty"`

	// Requests matching this policy will be redirected to the pool with this ID.
	// Only valid if action is REDIRECT_TO_POOL.
	RedirectPoolID string `json:"redirect_pool_id,omitempty"`

	// Requests matching this policy will be redirected to this URL.
	// Only valid if action is REDIRECT_TO_URL.
	RedirectURL string `json:"redirect_url,omitempty"`

	// The administrative state of the Loadbalancer. A valid value is true (UP)
	// or false (DOWN).
	AdminStateUp *bool `json:"admin_state_up,omitempty"`
}

CreateOpts is the common options struct used in this package's Create operation.

func (CreateOpts) ToL7PolicyCreateMap

func (opts CreateOpts) ToL7PolicyCreateMap() (map[string]interface{}, error)

ToL7PolicyCreateMap builds a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToL7PolicyCreateMap() (map[string]interface{}, error)
}

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateResult

type CreateResult struct {
	// contains filtered or unexported fields
}

CreateResult represents the result of a Create operation. Call its Extract method to interpret the result as a L7Policy.

func Create

Create accepts a CreateOpts struct and uses the values to create a new l7policy.

func (CreateResult) Extract

func (r CreateResult) Extract() (*L7Policy, error)

Extract is a function that accepts a result and extracts a l7policy.

type CreateRuleOpts

type CreateRuleOpts struct {
	// The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH.
	RuleType RuleType `json:"type" required:"true"`

	// The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH.
	CompareType CompareType `json:"compare_type" required:"true"`

	// The value to use for the comparison. For example, the file type to compare.
	Value string `json:"value" required:"true"`

	// ProjectID is the UUID of the project who owns the rule in octavia.
	// Only administrative users can specify a project UUID other than their own.
	ProjectID string `json:"project_id,omitempty"`

	// The key to use for the comparison. For example, the name of the cookie to evaluate.
	Key string `json:"key,omitempty"`

	// When true the logic of the rule is inverted. For example, with invert true,
	// equal to would become not equal to. Default is false.
	Invert bool `json:"invert,omitempty"`

	// The administrative state of the Loadbalancer. A valid value is true (UP)
	// or false (DOWN).
	AdminStateUp *bool `json:"admin_state_up,omitempty"`
}

CreateRuleOpts is the common options struct used in this package's CreateRule operation.

func (CreateRuleOpts) ToRuleCreateMap

func (opts CreateRuleOpts) ToRuleCreateMap() (map[string]interface{}, error)

ToRuleCreateMap builds a request body from CreateRuleOpts.

type CreateRuleResult

type CreateRuleResult struct {
	// contains filtered or unexported fields
}

CreateRuleResult represents the result of a CreateRule operation. Call its Extract method to interpret it as a Rule.

func CreateRule

func CreateRule(c *gophercloud.ServiceClient, policyID string, opts CreateRuleOpts) (r CreateRuleResult)

CreateRule will create and associate a Rule with a particular L7Policy.

func (CreateRuleResult) Extract

func (r CreateRuleResult) Extract() (*Rule, error)

Extract is a function that accepts a result and extracts a rule.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult represents the result of a Delete operation. Call its ExtractErr method to determine if the request succeeded or failed.

func Delete

func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult)

Delete will permanently delete a particular l7policy based on its unique ID.

type DeleteRuleResult

type DeleteRuleResult struct {
	gophercloud.ErrResult
}

DeleteRuleResult represents the result of a DeleteRule operation. Call its ExtractErr method to determine if the request succeeded or failed.

func DeleteRule

func DeleteRule(c *gophercloud.ServiceClient, policyID string, ruleID string) (r DeleteRuleResult)

DeleteRule will remove a Rule from a particular L7Policy.

type GetResult

type GetResult struct {
	// contains filtered or unexported fields
}

GetResult represents the result of a Get operation. Call its Extract method to interpret the result as a L7Policy.

func Get

func Get(c *gophercloud.ServiceClient, id string) (r GetResult)

Get retrieves a particular l7policy based on its unique ID.

func (GetResult) Extract

func (r GetResult) Extract() (*L7Policy, error)

Extract is a function that accepts a result and extracts a l7policy.

type GetRuleResult

type GetRuleResult struct {
	// contains filtered or unexported fields
}

GetRuleResult represents the result of a GetRule operation. Call its Extract method to interpret it as a Rule.

func GetRule

func GetRule(c *gophercloud.ServiceClient, policyID string, ruleID string) (r GetRuleResult)

GetRule retrieves a particular L7Policy Rule based on its unique ID.

func (GetRuleResult) Extract

func (r GetRuleResult) Extract() (*Rule, error)

Extract is a function that accepts a result and extracts a rule.

type L7Policy

type L7Policy struct {
	// The unique ID for the L7 policy.
	ID string `json:"id"`

	// Name of the L7 policy.
	Name string `json:"name"`

	// The ID of the listener.
	ListenerID string `json:"listener_id"`

	// The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
	Action string `json:"action"`

	// The position of this policy on the listener.
	Position int32 `json:"position"`

	// A human-readable description for the resource.
	Description string `json:"description"`

	// ProjectID is the UUID of the project who owns the L7 policy in octavia.
	// Only administrative users can specify a project UUID other than their own.
	ProjectID string `json:"project_id"`

	// Requests matching this policy will be redirected to the pool with this ID.
	// Only valid if action is REDIRECT_TO_POOL.
	RedirectPoolID string `json:"redirect_pool_id"`

	// Requests matching this policy will be redirected to this URL.
	// Only valid if action is REDIRECT_TO_URL.
	RedirectURL string `json:"redirect_url"`

	// The administrative state of the L7 policy, which is up (true) or down (false).
	AdminStateUp bool `json:"admin_state_up"`

	// The provisioning status of the L7 policy.
	// This value is ACTIVE, PENDING_* or ERROR.
	ProvisioningStatus string `json:"provisioning_status"`

	// The operating status of the L7 policy.
	OperatingStatus string `json:"operating_status"`

	// Rules are List of associated L7 rule IDs.
	Rules []Rule `json:"rules"`
}

L7Policy is a collection of L7 rules associated with a Listener, and which may also have an association to a back-end pool.

func ExtractL7Policies

func ExtractL7Policies(r pagination.Page) ([]L7Policy, error)

ExtractL7Policies accepts a Page struct, specifically a L7PolicyPage struct, and extracts the elements into a slice of L7Policy structs. In other words, a generic collection is mapped into a relevant slice.

type L7PolicyPage

type L7PolicyPage struct {
	pagination.LinkedPageBase
}

L7PolicyPage is the page returned by a pager when traversing over a collection of l7policies.

func (L7PolicyPage) IsEmpty

func (r L7PolicyPage) IsEmpty() (bool, error)

IsEmpty checks whether a L7PolicyPage struct is empty.

func (L7PolicyPage) NextPageURL

func (r L7PolicyPage) NextPageURL() (string, error)

NextPageURL is invoked when a paginated collection of l7policies has reached the end of a page and the pager seeks to traverse over a new one. In order to do this, it needs to construct the next page's URL.

type ListOpts

type ListOpts struct {
	Name           string `q:"name"`
	Description    string `q:"description"`
	ListenerID     string `q:"listener_id"`
	Action         string `q:"action"`
	ProjectID      string `q:"project_id"`
	RedirectPoolID string `q:"redirect_pool_id"`
	RedirectURL    string `q:"redirect_url"`
	Position       int32  `q:"position"`
	AdminStateUp   bool   `q:"admin_state_up"`
	ID             string `q:"id"`
	Limit          int    `q:"limit"`
	Marker         string `q:"marker"`
	SortKey        string `q:"sort_key"`
	SortDir        string `q:"sort_dir"`
}

ListOpts allows the filtering and sorting of paginated collections through the API.

func (ListOpts) ToL7PolicyListQuery

func (opts ListOpts) ToL7PolicyListQuery() (string, error)

ToL7PolicyListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToL7PolicyListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request.

type ListRulesOpts

type ListRulesOpts struct {
	RuleType     RuleType    `q:"type"`
	ProjectID    string      `q:"project_id"`
	CompareType  CompareType `q:"compare_type"`
	Value        string      `q:"value"`
	Key          string      `q:"key"`
	Invert       bool        `q:"invert"`
	AdminStateUp bool        `q:"admin_state_up"`
	ID           string      `q:"id"`
	Limit        int         `q:"limit"`
	Marker       string      `q:"marker"`
	SortKey      string      `q:"sort_key"`
	SortDir      string      `q:"sort_dir"`
}

ListRulesOpts allows the filtering and sorting of paginated collections through the API.

func (ListRulesOpts) ToRulesListQuery

func (opts ListRulesOpts) ToRulesListQuery() (string, error)

ToRulesListQuery formats a ListOpts into a query string.

type ListRulesOptsBuilder

type ListRulesOptsBuilder interface {
	ToRulesListQuery() (string, error)
}

ListRulesOptsBuilder allows extensions to add additional parameters to the ListRules request.

type Rule

type Rule struct {
	// The unique ID for the L7 rule.
	ID string `json:"id"`

	// The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH.
	RuleType string `json:"type"`

	// The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH.
	CompareType string `json:"compare_type"`

	// The value to use for the comparison. For example, the file type to compare.
	Value string `json:"value"`

	// ProjectID is the UUID of the project who owns the rule in octavia.
	// Only administrative users can specify a project UUID other than their own.
	ProjectID string `json:"project_id"`

	// The key to use for the comparison. For example, the name of the cookie to evaluate.
	Key string `json:"key"`

	// When true the logic of the rule is inverted. For example, with invert true,
	// equal to would become not equal to. Default is false.
	Invert bool `json:"invert"`

	// The administrative state of the L7 rule, which is up (true) or down (false).
	AdminStateUp bool `json:"admin_state_up"`

	// The provisioning status of the L7 rule.
	// This value is ACTIVE, PENDING_* or ERROR.
	ProvisioningStatus string `json:"provisioning_status"`

	// The operating status of the L7 policy.
	OperatingStatus string `json:"operating_status"`
}

Rule represents layer 7 load balancing rule.

func ExtractRules

func ExtractRules(r pagination.Page) ([]Rule, error)

ExtractRules accepts a Page struct, specifically a RulePage struct, and extracts the elements into a slice of Rules structs. In other words, a generic collection is mapped into a relevant slice.

type RulePage

type RulePage struct {
	pagination.LinkedPageBase
}

RulePage is the page returned by a pager when traversing over a collection of Rules in a L7Policy.

func (RulePage) IsEmpty

func (r RulePage) IsEmpty() (bool, error)

IsEmpty checks whether a RulePage struct is empty.

func (RulePage) NextPageURL

func (r RulePage) NextPageURL() (string, error)

NextPageURL is invoked when a paginated collection of rules has reached the end of a page and the pager seeks to traverse over a new one. In order to do this, it needs to construct the next page's URL.

type RuleType

type RuleType string

type UpdateOpts

type UpdateOpts struct {
	// Name of the L7 policy, empty string is allowed.
	Name *string `json:"name,omitempty"`

	// The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
	Action Action `json:"action,omitempty"`

	// The position of this policy on the listener.
	Position int32 `json:"position,omitempty"`

	// A human-readable description for the resource, empty string is allowed.
	Description *string `json:"description,omitempty"`

	// Requests matching this policy will be redirected to the pool with this ID.
	// Only valid if action is REDIRECT_TO_POOL.
	RedirectPoolID *string `json:"redirect_pool_id,omitempty"`

	// Requests matching this policy will be redirected to this URL.
	// Only valid if action is REDIRECT_TO_URL.
	RedirectURL *string `json:"redirect_url,omitempty"`

	// The administrative state of the Loadbalancer. A valid value is true (UP)
	// or false (DOWN).
	AdminStateUp *bool `json:"admin_state_up,omitempty"`
}

UpdateOpts is the common options struct used in this package's Update operation.

func (UpdateOpts) ToL7PolicyUpdateMap

func (opts UpdateOpts) ToL7PolicyUpdateMap() (map[string]interface{}, error)

ToL7PolicyUpdateMap builds a request body from UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToL7PolicyUpdateMap() (map[string]interface{}, error)
}

UpdateOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateResult

type UpdateResult struct {
	// contains filtered or unexported fields
}

UpdateResult represents the result of an Update operation. Call its Extract method to interpret the result as a L7Policy.

func Update

Update allows l7policy to be updated.

func (UpdateResult) Extract

func (r UpdateResult) Extract() (*L7Policy, error)

Extract is a function that accepts a result and extracts a l7policy.

type UpdateRuleOpts

type UpdateRuleOpts struct {
	// The L7 rule type. One of COOKIE, FILE_TYPE, HEADER, HOST_NAME, or PATH.
	RuleType RuleType `json:"type,omitempty"`

	// The comparison type for the L7 rule. One of CONTAINS, ENDS_WITH, EQUAL_TO, REGEX, or STARTS_WITH.
	CompareType CompareType `json:"compare_type,omitempty"`

	// The value to use for the comparison. For example, the file type to compare.
	Value string `json:"value,omitempty"`

	// The key to use for the comparison. For example, the name of the cookie to evaluate.
	Key *string `json:"key,omitempty"`

	// When true the logic of the rule is inverted. For example, with invert true,
	// equal to would become not equal to. Default is false.
	Invert *bool `json:"invert,omitempty"`

	// The administrative state of the Loadbalancer. A valid value is true (UP)
	// or false (DOWN).
	AdminStateUp *bool `json:"admin_state_up,omitempty"`
}

UpdateRuleOpts is the common options struct used in this package's Update operation.

func (UpdateRuleOpts) ToRuleUpdateMap

func (opts UpdateRuleOpts) ToRuleUpdateMap() (map[string]interface{}, error)

ToRuleUpdateMap builds a request body from UpdateRuleOpts.

type UpdateRuleOptsBuilder

type UpdateRuleOptsBuilder interface {
	ToRuleUpdateMap() (map[string]interface{}, error)
}

UpdateRuleOptsBuilder allows to add additional parameters to the PUT request.

type UpdateRuleResult

type UpdateRuleResult struct {
	// contains filtered or unexported fields
}

UpdateRuleResult represents the result of an UpdateRule operation. Call its Extract method to interpret it as a Rule.

func UpdateRule

func UpdateRule(c *gophercloud.ServiceClient, policyID string, ruleID string, opts UpdateRuleOptsBuilder) (r UpdateRuleResult)

UpdateRule allows Rule to be updated.

func (UpdateRuleResult) Extract

func (r UpdateRuleResult) Extract() (*Rule, error)

Extract is a function that accepts a result and extracts a rule.

Directories

Path Synopsis
l7policies unit tests
l7policies unit tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL