github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/subnets/doc.go (about) 1 /* 2 Package subnets contains functionality for working with Neutron subnet 3 resources. A subnet represents an IP address block that can be used to 4 assign IP addresses to virtual instances. Each subnet must have a CIDR and 5 must be associated with a network. IPs can either be selected from the whole 6 subnet CIDR or from allocation pools specified by the user. 7 8 A subnet can also have a gateway, a list of DNS name servers, and host routes. 9 This information is pushed to instances whose interfaces are associated with 10 the subnet. 11 12 Example to List Subnets 13 14 listOpts := subnets.ListOpts{ 15 IPVersion: 4, 16 } 17 18 allPages, err := subnets.List(networkClient, listOpts).AllPages() 19 if err != nil { 20 panic(err) 21 } 22 23 allSubnets, err := subnets.ExtractSubnets(allPages) 24 if err != nil { 25 panic(err) 26 } 27 28 for _, subnet := range allSubnets { 29 fmt.Printf("%+v\n", subnet) 30 } 31 32 Example to Create a Subnet With Specified Gateway 33 34 var gatewayIP = "192.168.199.1" 35 createOpts := subnets.CreateOpts{ 36 NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a22", 37 IPVersion: 4, 38 CIDR: "192.168.199.0/24", 39 GatewayIP: &gatewayIP, 40 AllocationPools: []subnets.AllocationPool{ 41 { 42 Start: "192.168.199.2", 43 End: "192.168.199.254", 44 }, 45 }, 46 DNSNameservers: []string{"foo"}, 47 } 48 49 subnet, err := subnets.Create(networkClient, createOpts).Extract() 50 if err != nil { 51 panic(err) 52 } 53 54 Example to Create a Subnet With No Gateway 55 56 var noGateway = "" 57 58 createOpts := subnets.CreateOpts{ 59 NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", 60 IPVersion: 4, 61 CIDR: "192.168.1.0/24", 62 GatewayIP: &noGateway, 63 AllocationPools: []subnets.AllocationPool{ 64 { 65 Start: "192.168.1.2", 66 End: "192.168.1.254", 67 }, 68 }, 69 DNSNameservers: []string{}, 70 } 71 72 subnet, err := subnets.Create(networkClient, createOpts).Extract() 73 if err != nil { 74 panic(err) 75 } 76 77 Example to Create a Subnet With a Default Gateway 78 79 createOpts := subnets.CreateOpts{ 80 NetworkID: "d32019d3-bc6e-4319-9c1d-6722fc136a23", 81 IPVersion: 4, 82 CIDR: "192.168.1.0/24", 83 AllocationPools: []subnets.AllocationPool{ 84 { 85 Start: "192.168.1.2", 86 End: "192.168.1.254", 87 }, 88 }, 89 DNSNameservers: []string{}, 90 } 91 92 subnet, err := subnets.Create(networkClient, createOpts).Extract() 93 if err != nil { 94 panic(err) 95 } 96 97 Example to Update a Subnet 98 99 subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" 100 101 updateOpts := subnets.UpdateOpts{ 102 Name: "new_name", 103 DNSNameservers: []string{"8.8.8.8}, 104 } 105 106 subnet, err := subnets.Update(networkClient, subnetID, updateOpts).Extract() 107 if err != nil { 108 panic(err) 109 } 110 111 Example to Remove a Gateway From a Subnet 112 113 var noGateway = "" 114 subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" 115 116 updateOpts := subnets.UpdateOpts{ 117 GatewayIP: &noGateway, 118 } 119 120 subnet, err := subnets.Update(networkClient, subnetID, updateOpts).Extract() 121 if err != nil { 122 panic(err) 123 } 124 125 Example to Delete a Subnet 126 127 subnetID := "db77d064-e34f-4d06-b060-f21e28a61c23" 128 err := subnets.Delete(networkClient, subnetID).ExtractErr() 129 if err != nil { 130 panic(err) 131 } 132 */ 133 package subnets