File: doc.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (138 lines) | stat: -rw-r--r-- 3,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
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"},
		ServiceTypes: []string{"network:floatingip"},
	}

	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"}
	serviceTypes := []string{"network:floatingip", "network:routed"}
	name := "new_name"

	updateOpts := subnets.UpdateOpts{
		Name:           &name,
		DNSNameservers: &dnsNameservers,
		ServiceTypes:   &serviceTypes,
	}

	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)
	}
*/
package subnets