networks

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MPL-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package network contains functionality for working EdgeCloud 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 *edgecloud.ServiceClient, networkID string) (r tasks.Result)

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

func ExtractNetworkIDFromTask

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

func ExtractNetworksInto

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

func IDFromName

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

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

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

type CreateOptsBuilder

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

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

type GetInstancePortResult

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

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

ListAllInstancePort retrieves a specific list of instance ports by network_id.

func (GetInstancePortResult) Extract

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

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

func (GetInstancePortResult) ExtractInto

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 *edgecloud.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

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

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

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

ToNetworkListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToNetworkListQuery() (string, 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 edgecloud.JSONRFC3339Z  `json:"created_at"`
	UpdatedAt *edgecloud.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 *edgecloud.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 UpdateOpts.

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 *edgecloud.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