gophercloud: Index | Files

package subnets

import ""

Package subnets contains functionality for working with Neutron subnet resources. A subnet represents an IP address block that can be used to assign IP addresses to virtual instances. Each subnet must have a CIDR and must be associated with a network. IPs can either be selected from the whole subnet CIDR or from allocation pools specified by the user.

A subnet can also have a gateway, a list of DNS name servers, and host routes. This information is pushed to instances whose interfaces are associated with the subnet.


Package Files

doc.go errors.go requests.go results.go urls.go


const (
    IPv4 = 4
    IPv6 = 6

Valid IP types

func ExtractSubnets Uses

func ExtractSubnets(page pagination.Page) ([]Subnet, error)

ExtractSubnets accepts a Page struct, specifically a SubnetPage struct, and extracts the elements into a slice of Subnet structs. In other words, a generic collection is mapped into a relevant slice.

func IDFromName Uses

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

IDFromName is a convenience function that returns a subnet's ID given its name.

func List Uses

func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager

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

Default policy settings return only those subnets that are owned by the tenant who submits the request, unless the request is submitted by a user with administrative rights.

type AdminState Uses

type AdminState *bool

AdminState gives users a solid type to work with for create and update operations. It is recommended that users use the `Up` and `Down` enums.

var (
    Up   AdminState = &iTrue
    Down AdminState = &iFalse

Convenience vars for AdminStateUp values.

type AllocationPool Uses

type AllocationPool struct {
    Start string `json:"start"`
    End   string `json:"end"`

AllocationPool represents a sub-range of cidr available for dynamic allocation to ports, e.g. {Start: "", End: ""}

type CreateOpts Uses

type CreateOpts struct {
    // Required
    NetworkID string
    CIDR      string
    // Optional
    Name            string
    TenantID        string
    AllocationPools []AllocationPool
    GatewayIP       string
    NoGateway       bool
    IPVersion       int
    EnableDHCP      *bool
    DNSNameservers  []string
    HostRoutes      []HostRoute

CreateOpts represents the attributes used when creating a new subnet.

func (CreateOpts) ToSubnetCreateMap Uses

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

ToSubnetCreateMap casts a CreateOpts struct to a map.

type CreateOptsBuilder Uses

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

CreateOptsBuilder is the interface options structs have to satisfy in order to be used in the main Create operation in this package. Since many extensions decorate or modify the common logic, it is useful for them to satisfy a basic interface in order for them to be used.

type CreateResult Uses

type CreateResult struct {
    // contains filtered or unexported fields

CreateResult represents the result of a create operation.

func Create Uses

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

Create accepts a CreateOpts struct and creates a new subnet using the values provided. You must remember to provide a valid NetworkID, CIDR and IP version.

func (CreateResult) Extract Uses

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

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

type DeleteResult Uses

type DeleteResult struct {

DeleteResult represents the result of a delete operation.

func Delete Uses

func Delete(c *gophercloud.ServiceClient, id string) DeleteResult

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

type GetResult Uses

type GetResult struct {
    // contains filtered or unexported fields

GetResult represents the result of a get operation.

func Get Uses

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

Get retrieves a specific subnet based on its unique ID.

func (GetResult) Extract Uses

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

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

type HostRoute Uses

type HostRoute struct {
    DestinationCIDR string `mapstructure:"destination" json:"destination"`
    NextHop         string `mapstructure:"nexthop" json:"nexthop"`

HostRoute represents a route that should be used by devices with IPs from a subnet (not including local subnet route).

type ListOpts Uses

type ListOpts struct {
    Name       string `q:"name"`
    EnableDHCP *bool  `q:"enable_dhcp"`
    NetworkID  string `q:"network_id"`
    TenantID   string `q:"tenant_id"`
    IPVersion  int    `q:"ip_version"`
    GatewayIP  string `q:"gateway_ip"`
    CIDR       string `q:"cidr"`
    ID         string `q:"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 subnet attributes you want to see returned. SortKey allows you to sort by a particular subnet attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for pagination.

func (ListOpts) ToSubnetListQuery Uses

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

ToSubnetListQuery formats a ListOpts into a query string.

type ListOptsBuilder Uses

type ListOptsBuilder interface {
    ToSubnetListQuery() (string, error)

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

type Subnet Uses

type Subnet struct {
    // UUID representing the subnet
    ID  string `mapstructure:"id" json:"id"`
    // UUID of the parent network
    NetworkID string `mapstructure:"network_id" json:"network_id"`
    // Human-readable name for the subnet. Might not be unique.
    Name string `mapstructure:"name" json:"name"`
    // IP version, either `4' or `6'
    IPVersion int `mapstructure:"ip_version" json:"ip_version"`
    // CIDR representing IP range for this subnet, based on IP version
    CIDR string `mapstructure:"cidr" json:"cidr"`
    // Default gateway used by devices in this subnet
    GatewayIP string `mapstructure:"gateway_ip" json:"gateway_ip"`
    // DNS name servers used by hosts in this subnet.
    DNSNameservers []string `mapstructure:"dns_nameservers" json:"dns_nameservers"`
    // Sub-ranges of CIDR available for dynamic allocation to ports. See AllocationPool.
    AllocationPools []AllocationPool `mapstructure:"allocation_pools" json:"allocation_pools"`
    // Routes that should be used by devices with IPs from this subnet (not including local subnet route).
    HostRoutes []HostRoute `mapstructure:"host_routes" json:"host_routes"`
    // Specifies whether DHCP is enabled for this subnet or not.
    EnableDHCP bool `mapstructure:"enable_dhcp" json:"enable_dhcp"`
    // Owner of network. Only admin users can specify a tenant_id other than its own.
    TenantID string `mapstructure:"tenant_id" json:"tenant_id"`

Subnet represents a subnet. See package documentation for a top-level description of what this is.

type SubnetPage Uses

type SubnetPage struct {

SubnetPage is the page returned by a pager when traversing over a collection of subnets.

func (SubnetPage) IsEmpty Uses

func (p SubnetPage) IsEmpty() (bool, error)

IsEmpty checks whether a SubnetPage struct is empty.

func (SubnetPage) NextPageURL Uses

func (p SubnetPage) NextPageURL() (string, error)

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

type UpdateOpts struct {
    Name           string
    GatewayIP      string
    NoGateway      bool
    DNSNameservers []string
    HostRoutes     []HostRoute
    EnableDHCP     *bool

UpdateOpts represents the attributes used when updating an existing subnet.

func (UpdateOpts) ToSubnetUpdateMap Uses

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

ToSubnetUpdateMap casts an UpdateOpts struct to a map.

type UpdateOptsBuilder Uses

type UpdateOptsBuilder interface {
    ToSubnetUpdateMap() (map[string]interface{}, error)

UpdateOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateResult Uses

type UpdateResult struct {
    // contains filtered or unexported fields

UpdateResult represents the result of an update operation.

func Update Uses

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

Update accepts a UpdateOpts struct and updates an existing subnet using the values provided.

func (UpdateResult) Extract Uses

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

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

Package subnets imports 4 packages (graph) and is imported by 75 packages. Updated 2016-07-23. Refresh now. Tools for package owners.