policies

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package policies provides information and interaction with the policies through the OpenStack Clustering service.

Example to List Policies

listOpts := policies.ListOpts{
	Limit: 2,
}

allPages, err := policies.List(clusteringClient, listOpts).AllPages()
if err != nil {
	panic(err)
}

allPolicies, err := policies.ExtractPolicies(allPages)
if err != nil {
	panic(err)
}

for _, policy := range allPolicies {
	fmt.Printf("%+v\n", policy)
}

Example to Create a Policy

opts := policies.CreateOpts{
	Name: "new_policy",
	Spec: policies.Spec{
		Description: "new policy description",
		Properties: map[string]interface{}{
			"hooks": map[string]interface{}{
				"type": "zaqar",
				"params": map[string]interface{}{
					"queue": "my_zaqar_queue",
				},
				"timeout": 10,
			},
		},
		Type:    "senlin.policy.deletion",
		Version: "1.1",
	},
}

createdPolicy, err := policies.Create(client, opts).Extract()
if err != nil {
	panic(err)
}

Example to Get a Policy

policyName := "get_policy"
policyDetail, err := policies.Get(clusteringClient, policyName).Extract()
if err != nil {
    panic(err)
}

fmt.Printf("%+v\n", policyDetail)

Example to Update a Policy

opts := policies.UpdateOpts{
	Name: "update_policy",
}

updatePolicy, err := policies.Update(client, opts).Extract()
if err != nil {
	panic(err)
}

Example to Validate a Policy

opts := policies.ValidateOpts{
	Spec: policies.Spec{
		Description: "new policy description",
		Properties: map[string]interface{}{
			"hooks": map[string]interface{}{
				"type": "zaqar",
				"params": map[string]interface{}{
					"queue": "my_zaqar_queue",
				},
				"timeout": 10,
			},
		},
		Type:    "senlin.policy.deletion",
		Version: "1.1",
	},
}

validatePolicy, err := policies.Validate(client, opts).Extract()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

List instructs OpenStack to retrieve a list of policies.

Types

type CreateOpts

type CreateOpts struct {
	Name string `json:"name"`
	Spec Spec   `json:"spec"`
}

CreateOpts represents options used to create a policy.

func (CreateOpts) ToPolicyCreateMap

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

ToPolicyCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToPolicyCreateMap() (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 is the result of an Update operation. Call its Extract method to interpret it as a Policy.

func Create

func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create makes a request against the API to create a policy

func (CreateResult) Extract

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

Extract interpets any policyResult-base result as a Policy.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult is the result of a Delete operation. Call its Extract method to interpret it as a DeleteHeader.

func Delete

func Delete(client *gophercloud.ServiceClient, policyID string) (r DeleteResult)

Delete makes a request against the API to delete a policy.

type GetResult

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

GetResult is the result of a Get operation. Call its Extract method to interpret it as a Policy.

func Get

func Get(client *gophercloud.ServiceClient, policyTypeName string) (r GetResult)

Get makes a request against the API to get details for a policy.

func (GetResult) Extract

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

Extract interpets any policyResult-base result as a Policy.

type ListOpts

type ListOpts struct {
	// Limit limits the number of Policies to return.
	Limit int `q:"limit"`

	// Marker and Limit control paging. Marker instructs List where to start
	// listing from.
	Marker string `q:"marker"`

	// Sorts the response by one or more attribute and optional sort direction
	// combinations.
	Sort string `q:"sort"`

	// GlobalProject indicates whether to include resources for all projects or
	// resources for the current project.
	GlobalProject *bool `q:"global_project"`

	// Name to filter the response by the specified name property of the object.
	Name string `q:"name"`

	// Filter the response by the specified type property of the object.
	Type string `q:"type"`
}

ListOpts represents options used to list policies.

func (ListOpts) ToPolicyListQuery

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

ToPolicyListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type Policy

type Policy struct {
	CreatedAt time.Time              `json:"-"`
	Data      map[string]interface{} `json:"data"`
	Domain    string                 `json:"domain"`
	ID        string                 `json:"id"`
	Name      string                 `json:"name"`
	Project   string                 `json:"project"`
	Spec      Spec                   `json:"spec"`
	Type      string                 `json:"type"`
	UpdatedAt time.Time              `json:"-"`
	User      string                 `json:"user"`
}

Policy represents a clustering policy in the Openstack cloud.

func ExtractPolicies

func ExtractPolicies(r pagination.Page) ([]Policy, error)

ExtractPolicies returns a slice of Policies from the List operation.

func (*Policy) UnmarshalJSON

func (r *Policy) UnmarshalJSON(b []byte) error

type PolicyPage

type PolicyPage struct {
	pagination.MarkerPageBase
}

PolicyPage contains a list page of all policies from a List call.

func (PolicyPage) IsEmpty

func (page PolicyPage) IsEmpty() (bool, error)

IsEmpty determines if a PolicyPage contains any results.

func (PolicyPage) LastMarker

func (r PolicyPage) LastMarker() (string, error)

LastMarker returns the last policy ID in a ListResult.

type Spec

type Spec struct {
	Description string                 `json:"description"`
	Properties  map[string]interface{} `json:"properties"`
	Type        string                 `json:"type"`
	Version     string                 `json:"-"`
}

Spec represents an OpenStack clustering policy spec.

func (Spec) MarshalJSON

func (r Spec) MarshalJSON() ([]byte, error)

func (*Spec) UnmarshalJSON

func (r *Spec) UnmarshalJSON(b []byte) error

type UpdateOpts

type UpdateOpts struct {
	Name string `json:"name,omitempty"`
}

UpdateOpts represents options to update a policy.

func (UpdateOpts) ToPolicyUpdateMap

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

ToPolicyUpdateMap constructs a request body from UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToPolicyUpdateMap() (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 is the result of an Update operation. Call its Extract method to interpret it as a Policy.

func Update

func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)

Update updates a specified policy.

func (UpdateResult) Extract

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

Extract interpets any policyResult-base result as a Policy.

type ValidateOpts

type ValidateOpts struct {
	Spec Spec `json:"spec"`
}

ValidateOpts represents options used to validate a policy.

func (ValidateOpts) ToPolicyValidateMap

func (opts ValidateOpts) ToPolicyValidateMap() (map[string]interface{}, error)

ToPolicyValidateMap formats a CreateOpts into a body map.

type ValidateOptsBuilder

type ValidateOptsBuilder interface {
	ToPolicyValidateMap() (map[string]interface{}, error)
}

ValidateOptsBuilder allows extensions to add additional parameters to the Validate request.

type ValidateResult

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

ValidateResult is the result of a Validate operation. Call its Extract method to interpret it as a Policy.

func Validate

func Validate(client *gophercloud.ServiceClient, opts ValidateOptsBuilder) (r ValidateResult)

Validate policy will validate a specified policy.

func (ValidateResult) Extract

func (r ValidateResult) Extract() (*Policy, error)

Extract interpets any policyResult-base result as a Policy.

Directories

Path Synopsis
clustering_policies_v1
clustering_policies_v1

Jump to

Keyboard shortcuts

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