Documentation ¶
Overview ¶
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.
Example to List Subnets
listOpts := subnets.ListOpts{ IPVersion: 4, } allPages, err := subnets.List(networkClient, listOpts).AllPages() if err != nil { panic(err) } allSubnets, err := subnets.ExtractSubnets(allPages) if err != nil { panic(err) } for _, subnet := range allSubnets { fmt.Printf("%+v\n", subnet) }
Example to Create a Subnet With Specified Gateway
var gatewayIP = "192.168.199.1" createOpts := subnets.CreateOpts{ NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", IPVersion: 4, CIDR: "192.168.199.0/24", GatewayIP: &gatewayIP, AllocationPools: []subnets.AllocationPool{ { Start: "192.168.199.2", End: "192.168.199.254", }, }, DNSNameservers: []string{"foo"}, } subnet, err := subnets.Create(networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Create a Subnet With No Gateway
var noGateway = "" createOpts := subnets.CreateOpts{ NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", IPVersion: 4, CIDR: "192.168.1.0/24", GatewayIP: &noGateway, AllocationPools: []subnets.AllocationPool{ { Start: "192.168.1.2", End: "192.168.1.254", }, }, DNSNameservers: []string{}, } subnet, err := subnets.Create(networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Create a Subnet With a Default Gateway
createOpts := subnets.CreateOpts{ NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", IPVersion: 4, CIDR: "192.168.1.0/24", AllocationPools: []subnets.AllocationPool{ { Start: "192.168.1.2", End: "192.168.1.254", }, }, DNSNameservers: []string{}, } subnet, err := subnets.Create(networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Update a Subnet
subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" dnsNameservers := []string{"8.8.8.8"} name := "new_name" updateOpts := subnets.UpdateOpts{ Name: &name, DNSNameservers: &dnsNameservers, } subnet, err := subnets.Update(networkClient, subnetID, updateOpts).Extract() if err != nil { panic(err) }
Example to Remove a Gateway From a Subnet
var noGateway = "" subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" updateOpts := subnets.UpdateOpts{ GatewayIP: &noGateway, } subnet, err := subnets.Update(networkClient, subnetID, updateOpts).Extract() if err != nil { panic(err) }
Example to Delete a Subnet
subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" err := subnets.Delete(networkClient, subnetID).ExtractErr() if err != nil { panic(err) }
Index ¶
- func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type AllocationPool
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type CreateSubnetResponse
- type DeleteResult
- type DetailInfo
- type GetResult
- type HostRoute
- type ListOpts
- type ListOptsBuilder
- type OsNetwork
- type Subnet
- type SubnetPage
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
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.
Types ¶
type AllocationPool ¶
AllocationPool represents a sub-range of cidr available for dynamic allocation to ports, e.g. {Start: "10.0.0.2", End: "10.0.0.254"}
type CreateOpts ¶
type CreateOpts struct { // Name is a human-readable name of the subnet. Name string `json:"name" required:"true"` Zone string `json:"zone" required:"true"` // Added Type string `json:"type" required:"true"` // Added. Network Creation type. 기본값으로 "tier"만 사용 가능 UserCustom string `json:"usercustom" required:"true"` // Added. Detail DetailInfo `json:"detail,omitempty"` // Added. Tier 상세 설정 }
CreateOpts represents the attributes used when creating a new subnet.
func (CreateOpts) ToSubnetCreateMap ¶
func (opts CreateOpts) ToSubnetCreateMap() (map[string]interface{}, error)
ToSubnetCreateMap builds a request body from CreateOpts.
type CreateOptsBuilder ¶
CreateOptsBuilder allows extensions to add additional parameters to the List 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 Subnet.
func Create ¶
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r 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 ¶
Extract is a function that accepts a result and extracts a subnet resource.
func (CreateResult) ExtractCreateInfo ¶
func (r CreateResult) ExtractCreateInfo() (*CreateSubnetResponse, error)
type CreateSubnetResponse ¶
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 accepts a unique ID and deletes the subnet associated with it.
type DetailInfo ¶
type DetailInfo struct { Cclass string `json:"cclass,omitempty"` // Added CIDR string `json:"cidr,omitempty"` // Added StartIP string `json:"startip,omitempty"` // Added. Server가 사용 가능한 첫번째 ip EndIP string `json:"endip,omitempty"` // Added. Server가 사용 가능한 마지막 ip LBStartIP string `json:"lbstartip,omitempty"` // Added. LoadBalancer가 사용 가능한 첫번째 ip LBEndIP string `json:"lbendip,omitempty"` // Added. LoadBalancer가 사용 가능한 마지막 ip BMStartIP string `json:"bmstartip,omitempty"` // Added. Bare Metal 또는 기타 목적으로 사용 가능한 첫번째 ip BMEndIP string `json:"bmendip,omitempty"` // Added. 또는 기타 목적으로 사용 가능한 마지막 ip Gateway string `json:"gateway,omitempty"` // Added }
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 Subnet.
func (GetResult) Extract ¶
Extract is a function that accepts a result and extracts a subnet resource.
func (GetResult) ExtractCreateInfo ¶
func (r GetResult) ExtractCreateInfo() (*CreateSubnetResponse, error)
type HostRoute ¶
type HostRoute struct { DestinationCIDR string `json:"destination"` NextHop string `json:"nexthop"` }
HostRoute represents a route that should be used by devices with IPs from a subnet (not including local subnet route).
type ListOpts ¶
type ListOpts struct { Name string `q:"name"` Description string `q:"description"` EnableDHCP *bool `q:"enable_dhcp"` NetworkID string `q:"network_id"` TenantID string `q:"tenant_id"` ProjectID string `q:"project_id"` IPVersion int `q:"ip_version"` GatewayIP string `q:"gateway_ip"` CIDR string `q:"cidr"` IPv6AddressMode string `q:"ipv6_address_mode"` IPv6RAMode string `q:"ipv6_ra_mode"` ID string `q:"id"` SubnetPoolID string `q:"subnetpool_id"` Limit int `q:"limit"` Marker string `q:"marker"` SortKey string `q:"sort_key"` SortDir string `q:"sort_dir"` Tags string `q:"tags"` TagsAny string `q:"tags-any"` NotTags string `q:"not-tags"` NotTagsAny string `q:"not-tags-any"` }
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 ¶
ToSubnetListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type Subnet ¶
type Subnet struct { EndIP string `json:"endip"` // Added StartIP string `json:"startip"` // Added Type string `json:"type"` // Added VLan string `json:"vlan"` // Added Netmask string `json:"netmask"` // Added // UUID of the parent network. VpcID string `json:"vpcid"` // Modified // Human-readable name for the subnet. Might not be unique. Name string `json:"name"` ZoneID string `json:"zoneid"` // Added DataLakeYN string `json:"datalakeyn"` // Added // CIDR representing IP range for this subnet, based on IP version. CIDR string `json:"cidr"` // UUID representing the subnet. ID string `json:"id"` // ProjectID is the project owner of the subnet. ProjectID string `json:"projectid"` // Modified // Default gateway used by devices in this subnet. Gateway string `json:"gateway"` // Modified Account string `json:"account"` // Added OsName string `json:"osname"` // Added OsNetworkID string `json:"osnetworkid"` // Added Status string `json:"status"` // Added }
Subnet represents a subnet. See package documentation for a top-level description of what this is. KT Cloud D1 API guide : https://cloud.kt.com/docs/open-api-guide/d/computing/tier
func ExtractSubnets ¶
func ExtractSubnets(r 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.
type SubnetPage ¶
type SubnetPage struct {
pagination.LinkedPageBase
}
SubnetPage is the page returned by a pager when traversing over a collection of subnets.
func (SubnetPage) IsEmpty ¶
func (r SubnetPage) IsEmpty() (bool, error)
IsEmpty checks whether a SubnetPage struct is empty.
func (SubnetPage) NextPageURL ¶
func (r 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 ¶
type UpdateOpts struct { // Name is a human-readable name of the subnet. Name *string `json:"name,omitempty"` // Description of the subnet. Description *string `json:"description,omitempty"` // AllocationPools are IP Address pools that will be available for DHCP. AllocationPools []AllocationPool `json:"allocation_pools,omitempty"` // GatewayIP sets gateway information for the subnet. Setting to nil will // cause a default gateway to automatically be created. Setting to an empty // string will cause the subnet to be created with no gateway. Setting to // an explicit address will set that address as the gateway. GatewayIP *string `json:"gateway_ip,omitempty"` // DNSNameservers are the nameservers to be set via DHCP. DNSNameservers *[]string `json:"dns_nameservers,omitempty"` // HostRoutes are any static host routes to be set via DHCP. HostRoutes *[]HostRoute `json:"host_routes,omitempty"` // EnableDHCP will either enable to disable the DHCP service. EnableDHCP *bool `json:"enable_dhcp,omitempty"` // RevisionNumber implements extension:standard-attr-revisions. If != "" it // will set revision_number=%s. If the revision number does not match, the // update will fail. RevisionNumber *int `json:"-" h:"If-Match"` }
UpdateOpts represents the attributes used when updating an existing subnet.
func (UpdateOpts) ToSubnetUpdateMap ¶
func (opts UpdateOpts) ToSubnetUpdateMap() (map[string]interface{}, error)
ToSubnetUpdateMap 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 Subnet.
func Update ¶
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)
Update accepts a UpdateOpts struct and updates an existing subnet using the values provided.
func (UpdateResult) Extract ¶
Extract is a function that accepts a result and extracts a subnet resource.
func (UpdateResult) ExtractCreateInfo ¶
func (r UpdateResult) ExtractCreateInfo() (*CreateSubnetResponse, error)