networks

package
v0.5.37 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package network contains functionality for working GCLoud networks API resources

Example to List Network

listOpts := networks.ListOpts{
}

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

allNetworks, err := networks.ExtractNetworks(allPages)
if err != nil {
	panic(err)
}

for _, network := range allNetworks {
	fmt.Printf("%+v", network)
}

Example to Create a Network

createOpts := networks.CreateOpts{
	Name:  "network_1"
}

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

Example to Delete a Network

networkID := "484cda0e-106f-4f4b-bb3f-d413710bbe78"
err := networks.Delete(networkClient, networkID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

Create accepts a CreateOpts struct and creates a new network using the values provided.

func Delete

func Delete(c *gcorecloud.ServiceClient, networkID string) (r tasks.Result)

Delete accepts a unique ID and deletes the network associated with it.

func ExtractMetadataInto added in v0.5.21

func ExtractMetadataInto(r pagination.Page, v interface{}) error

func ExtractNetworkIDFromTask

func ExtractNetworkIDFromTask(task *tasks.Task) (string, error)

func ExtractNetworksInto

func ExtractNetworksInto(r pagination.Page, v interface{}) error

func IDFromName

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

IDFromName is a convenience function that returns a network ID, given its name.

func MetadataList added in v0.5.21

func MetadataList(client *gcorecloud.ServiceClient, id string) pagination.Pager

Types

type CreateOpts

type CreateOpts struct {
	Name         string            `json:"name" required:"true" validate:"required"`
	CreateRouter bool              `json:"create_router"`
	Type         string            `json:"type,omitempty" validate:"omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty"`
}

CreateOpts represents options used to create a network.

func (CreateOpts) ToNetworkCreateMap

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

ToNetworkCreateMap builds a request body from CreateOpts.

func (CreateOpts) Validate

func (opts CreateOpts) Validate() error

Validate

type CreateOptsBuilder

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

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

type GetInstancePortResult added in v0.4.27

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

GetInstancePortResult represents the result of a get operation. Call its Extract method to interpret it as an array of instance port.

func ListAllInstancePort added in v0.4.27

func ListAllInstancePort(c *gcorecloud.ServiceClient, networkID string) (r GetInstancePortResult)

ListAllInstancePort retrieves a specific list of instance ports by network_id.

func (GetInstancePortResult) Extract added in v0.4.27

func (r GetInstancePortResult) Extract() ([]InstancePort, error)

Extract is a function that accepts a result and extracts a network resource.

func (GetInstancePortResult) ExtractInto added in v0.4.27

func (r GetInstancePortResult) ExtractInto(v interface{}) error

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 Network.

func Get

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

Get retrieves a specific network based on its unique ID.

func (GetResult) Extract

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

Extract is a function that accepts a result and extracts a network resource.

func (GetResult) ExtractInto

func (r GetResult) ExtractInto(v interface{}) error

type InstancePort added in v0.4.27

type InstancePort struct {
	ID           string `json:"id"`
	InstanceID   string `json:"instance_id"`
	InstanceName string `json:"instance_name"`
}

InstancePort represents a instance port structure.

type ListOpts added in v0.5.12

type ListOpts struct {
	MetadataK  string            `q:"metadata_k" validate:"omitempty"`
	MetadataKV map[string]string `q:"metadata_kv" validate:"omitempty"`
}

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

func (ListOpts) ToNetworkListQuery added in v0.5.12

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

ToNetworkListQuery formats a ListOpts into a query string.

type ListOptsBuilder added in v0.5.12

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

type Metadata added in v0.5.21

type Metadata struct {
	Key      string `json:"key"`
	Value    string `json:"value"`
	ReadOnly bool   `json:"read_only"`
}

func ExtractMetadata added in v0.5.21

func ExtractMetadata(r pagination.Page) ([]Metadata, error)

ExtractMetadata accepts a Page struct, specifically a MetadataPage struct, and extracts the elements into a slice of securitygroups metadata structs. In other words, a generic collection is mapped into a relevant slice.

func MetadataListAll added in v0.5.21

func MetadataListAll(client *gcorecloud.ServiceClient, id string) ([]Metadata, error)

type MetadataActionResult added in v0.5.21

type MetadataActionResult struct {
	gcorecloud.ErrResult
}

MetadataActionResult represents the result of a create, delete or update operation(no content)

func MetadataCreateOrUpdate added in v0.5.21

func MetadataCreateOrUpdate(client *gcorecloud.ServiceClient, id string, opts map[string]interface{}) (r MetadataActionResult)

MetadataCreateOrUpdate creates or update a metadata for an security group.

func MetadataDelete added in v0.5.21

func MetadataDelete(client *gcorecloud.ServiceClient, id string, key string) (r MetadataActionResult)

MetadataDelete deletes defined metadata key for a security group.

func MetadataReplace added in v0.5.21

func MetadataReplace(client *gcorecloud.ServiceClient, id string, opts map[string]interface{}) (r MetadataActionResult)

MetadataReplace replace a metadata for an security group.

type MetadataPage added in v0.5.21

type MetadataPage struct {
	pagination.LinkedPageBase
}

MetadataPage is the page returned by a pager when traversing over a collection of instance metadata objects.

type MetadataResult added in v0.5.21

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

MetadataResult represents the result of a get operation

func MetadataGet added in v0.5.21

func MetadataGet(client *gcorecloud.ServiceClient, id string, key string) (r MetadataResult)

MetadataGet gets defined metadata key for a security group.

func (MetadataResult) Extract added in v0.5.21

func (r MetadataResult) Extract() (*Network, error)

Extract is a function that accepts a result and extracts a network resource.

func (MetadataResult) ExtractInto added in v0.5.21

func (r MetadataResult) ExtractInto(v interface{}) error

type Network

type Network struct {
	Name      string                   `json:"name"`
	ID        string                   `json:"id"`
	Subnets   []string                 `json:"subnets"`
	MTU       int                      `json:"mtu"`
	Type      string                   `json:"type"`
	CreatedAt gcorecloud.JSONRFC3339Z  `json:"created_at"`
	UpdatedAt *gcorecloud.JSONRFC3339Z `json:"updated_at"`
	External  bool                     `json:"external"`
	Default   bool                     `json:"default"`
	Shared    bool                     `json:"shared"`
	TaskID    *string                  `json:"task_id"`
	ProjectID int                      `json:"project_id"`
	RegionID  int                      `json:"region_id"`
	Region    string                   `json:"region"`
	Metadata  []metadata.Metadata      `json:"metadata"`
}

Network represents a network structure.

func ExtractNetworks

func ExtractNetworks(r pagination.Page) ([]Network, error)

ExtractNetwork accepts a Page struct, specifically a NetworkPage struct, and extracts the elements into a slice of Network structs. In other words, a generic collection is mapped into a relevant slice.

func ListAll

func ListAll(client *gcorecloud.ServiceClient, opts ListOptsBuilder) ([]Network, error)

ListAll is a convenience function that returns all networks.

type NetworkPage

type NetworkPage struct {
	pagination.LinkedPageBase
}

NetworkPage is the page returned by a pager when traversing over a collection of networks.

func (NetworkPage) IsEmpty

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

IsEmpty checks whether a NetworkPage struct is empty.

func (NetworkPage) NextPageURL

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

NextPageURL is invoked when a paginated collection of networks 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 NetworkTaskResult

type NetworkTaskResult struct {
	Networks []string `json:"networks"`
	Routers  []string `json:"routers"`
}

type UpdateOpts

type UpdateOpts struct {
	Name string `json:"name" required:"true" validate:"required"`
}

UpdateOpts represents options used to update a network.

func (UpdateOpts) ToNetworkUpdateMap

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

ToNetworkUpdateMap builds a request body from UpdateOpts.

func (UpdateOpts) Validate

func (opts UpdateOpts) Validate() error

Validate

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToNetworkUpdateMap() (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 Network.

func Update

func Update(c *gcorecloud.ServiceClient, networkID string, opts UpdateOptsBuilder) (r UpdateResult)

Update accepts a UpdateOpts struct and updates an existing network using the values provided. For more information, see the Create function.

func (UpdateResult) Extract

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

Extract is a function that accepts a result and extracts a network resource.

func (UpdateResult) ExtractInto

func (r UpdateResult) ExtractInto(v interface{}) error

Directories

Path Synopsis
networks unit tests
networks unit tests

Jump to

Keyboard shortcuts

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