groups

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package groups provides information and interaction with Security Groups for the OpenStack Networking service.

Example to List Security Groups

listOpts := groups.ListOpts{
	TenantID: "966b3c7d36a24facaf20b7e458bf2192",
}

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

allGroups, err := groups.ExtractGroups(allPages)
if err != nil {
	panic(err)
}

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

Example to Create a Security Group

createOpts := groups.CreateOpts{
	Name:        "group_name",
	Description: "A Security Group",
}

group, err := groups.Create(networkClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Update a Security Group

groupID := "37d94f8a-d136-465c-ae46-144f0d8ef141"

updateOpts := groups.UpdateOpts{
	Name: "new_name",
}

group, err := groups.Update(networkClient, groupID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Security Group

groupID := "37d94f8a-d136-465c-ae46-144f0d8ef141"
err := groups.Delete(networkClient, groupID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IDFromName

func IDFromName(client *gophercloud.ServiceClient, name string) (string, error)

IDFromName is a convenience function that returns a security group's ID, given its name.

func List

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

Types

type CreateOpts

type CreateOpts struct {
	// Human-readable name for the Security Group. Does not have to be unique.
	Name string `json:"name" required:"true"`

	// The UUID of the tenant who owns the Group. Only administrative users
	// can specify a tenant UUID other than their own.
	TenantID string `json:"tenant_id,omitempty"`

	// Describes the security group.
	Description string `json:"description,omitempty"`
}

CreateOpts contains all the values needed to create a new security group.

func (CreateOpts) ToSecGroupCreateMap

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

ToSecGroupCreateMap builds a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToSecGroupCreateMap() (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 it as a SecGroup.

func Create

Create is an operation which provisions a new security group with default security group rules for the IPv4 and IPv6 ether types.

func (CreateResult) Extract

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

Extract is a function that accepts a result and extracts a security group.

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 security group based on its unique ID.

type GetResult

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

GetResult represents the result of a get operation. Call its Extract method to interpret it as a SecGroup.

func Get

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

Get retrieves a particular security group based on its unique ID.

func (GetResult) Extract

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

Extract is a function that accepts a result and extracts a security group.

type ListOpts

type ListOpts struct {
	ID       string `q:"id"`
	Name     string `q:"name"`
	TenantID string `q:"tenant_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. Filtering is achieved by passing in struct field values that map to the group attributes you want to see returned. SortKey allows you to sort by a particular network attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for pagination.

type SecGroup

type SecGroup struct {
	// The UUID for the security group.
	ID string

	// Human-readable name for the security group. Might not be unique.
	// Cannot be named "default" as that is automatically created for a tenant.
	Name string

	// The security group description.
	Description string

	// A slice of security group rules that dictate the permitted behaviour for
	// traffic entering and leaving the group.
	Rules []rules.SecGroupRule `json:"security_group_rules"`

	// Owner of the security group.
	TenantID string `json:"tenant_id"`
}

SecGroup represents a container for security group rules.

func ExtractGroups

func ExtractGroups(r pagination.Page) ([]SecGroup, error)

ExtractGroups accepts a Page struct, specifically a SecGroupPage struct, and extracts the elements into a slice of SecGroup structs. In other words, a generic collection is mapped into a relevant slice.

type SecGroupPage

type SecGroupPage struct {
	pagination.LinkedPageBase
}

SecGroupPage is the page returned by a pager when traversing over a collection of security groups.

func (SecGroupPage) IsEmpty

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

IsEmpty checks whether a SecGroupPage struct is empty.

func (SecGroupPage) NextPageURL

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

NextPageURL is invoked when a paginated collection of security groups 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 UpdateOpts

type UpdateOpts struct {
	// Human-readable name for the Security Group. Does not have to be unique.
	Name string `json:"name,omitempty"`

	// Describes the security group.
	Description string `json:"description,omitempty"`
}

UpdateOpts contains all the values needed to update an existing security group.

func (UpdateOpts) ToSecGroupUpdateMap

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

ToSecGroupUpdateMap builds a request body from UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToSecGroupUpdateMap() (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 it as a SecGroup.

func Update

Update is an operation which updates an existing security group.

func (UpdateResult) Extract

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

Extract is a function that accepts a result and extracts a security group.

Directories

Path Synopsis
groups unit tests
groups unit tests

Jump to

Keyboard shortcuts

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