github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/layer3/routers/doc.go (about) 1 /* 2 Package routers enables management and retrieval of Routers from the OpenStack 3 Networking service. 4 5 Example to List Routers 6 7 listOpts := routers.ListOpts{} 8 allPages, err := routers.List(networkClient, listOpts).AllPages() 9 if err != nil { 10 panic(err) 11 } 12 13 allRouters, err := routers.ExtractRouters(allPages) 14 if err != nil { 15 panic(err) 16 } 17 18 for _, router := range allRoutes { 19 fmt.Printf("%+v\n", router) 20 } 21 22 Example to Create a Router 23 24 iTrue := true 25 gwi := routers.GatewayInfo{ 26 NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b", 27 } 28 29 createOpts := routers.CreateOpts{ 30 Name: "router_1", 31 AdminStateUp: &iTrue, 32 GatewayInfo: &gwi, 33 } 34 35 router, err := routers.Create(networkClient, createOpts).Extract() 36 if err != nil { 37 panic(err) 38 } 39 40 Example to Update a Router 41 42 routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 43 44 routes := []routers.Route{{ 45 DestinationCIDR: "40.0.1.0/24", 46 NextHop: "10.1.0.10", 47 }} 48 49 updateOpts := routers.UpdateOpts{ 50 Name: "new_name", 51 Routes: &routes, 52 } 53 54 router, err := routers.Update(networkClient, routerID, updateOpts).Extract() 55 if err != nil { 56 panic(err) 57 } 58 59 Example to Update just the Router name, keeping everything else as-is 60 61 routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 62 63 updateOpts := routers.UpdateOpts{ 64 Name: "new_name", 65 } 66 67 router, err := routers.Update(networkClient, routerID, updateOpts).Extract() 68 if err != nil { 69 panic(err) 70 } 71 72 Example to Remove all Routes from a Router 73 74 routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 75 76 routes := []routers.Route{} 77 78 updateOpts := routers.UpdateOpts{ 79 Routes: &routes, 80 } 81 82 router, err := routers.Update(networkClient, routerID, updateOpts).Extract() 83 if err != nil { 84 panic(err) 85 } 86 87 Example to Delete a Router 88 89 routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 90 err := routers.Delete(networkClient, routerID).ExtractErr() 91 if err != nil { 92 panic(err) 93 } 94 95 Example to Add an Interface to a Router 96 97 routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 98 99 intOpts := routers.AddInterfaceOpts{ 100 SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1", 101 } 102 103 interface, err := routers.AddInterface(networkClient, routerID, intOpts).Extract() 104 if err != nil { 105 panic(err) 106 } 107 108 Example to Remove an Interface from a Router 109 110 routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 111 112 intOpts := routers.RemoveInterfaceOpts{ 113 SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1", 114 } 115 116 interface, err := routers.RemoveInterface(networkClient, routerID, intOpts).Extract() 117 if err != nil { 118 panic(err) 119 } 120 121 Example to List an L3 agents for a Router 122 123 routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c" 124 125 allPages, err := routers.ListL3Agents(networkClient, routerID).AllPages() 126 if err != nil { 127 panic(err) 128 } 129 130 allL3Agents, err := routers.ExtractL3Agents(allPages) 131 if err != nil { 132 panic(err) 133 } 134 135 for _, agent := range allL3Agents { 136 fmt.Printf("%+v\n", agent) 137 } 138 */ 139 package routers