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", MTU: 1500, } 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 ¶
- func Create(c *gcorecloud.ServiceClient, opts CreateOptsBuilder) (r tasks.Result)
- func Delete(c *gcorecloud.ServiceClient, networkID string) (r tasks.Result)
- func ExtractNetworkIDFromTask(task *tasks.Task) (string, error)
- func ExtractNetworksInto(r pagination.Page, v interface{}) error
- func IDFromName(client *gcorecloud.ServiceClient, name string) (string, error)
- func List(c *gcorecloud.ServiceClient) pagination.Pager
- type CreateOpts
- type CreateOptsBuilder
- type GetResult
- type Network
- type NetworkPage
- type NetworkTaskResult
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
func Create(c *gcorecloud.ServiceClient, opts CreateOptsBuilder) (r tasks.Result)
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 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 List ¶
func List(c *gcorecloud.ServiceClient) pagination.Pager
Types ¶
type CreateOpts ¶
type CreateOpts struct { Name string `json:"name" required:"true" validate:"required"` Mtu int `json:"mtu,omitempty" validate:"omitempty,lte=1500"` CreateRouter bool `json:"create_router,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.
type CreateOptsBuilder ¶
CreateOptsBuilder allows extensions to add additional parameters to the Create request.
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 ¶
Extract is a function that accepts a result and extracts a network resource.
func (GetResult) ExtractInto ¶
func (r GetResult) 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"` CreatedAt gcorecloud.JSONRFC3339Z `json:"created_at"` UpdatedAt *gcorecloud.JSONRFC3339Z `json:"updated_at"` External bool `json:"external"` Default bool `json:"default"` TaskID *string `json:"task_id"` ProjectID int `json:"project_id"` RegionID int `json:"region_id"` Region string `json:"region"` }
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) ([]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 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.
type UpdateOptsBuilder ¶
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 ¶
Extract is a function that accepts a result and extracts a network resource.
func (UpdateResult) ExtractInto ¶
func (r UpdateResult) ExtractInto(v interface{}) error