github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/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 Remove all Routes from a Router
    60  
    61  	routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
    62  
    63  	routes := []routers.Route{}
    64  
    65  	updateOpts := routers.UpdateOpts{
    66  		Routes: routes,
    67  	}
    68  
    69  	router, err := routers.Update(networkClient, routerID, updateOpts).Extract()
    70  	if err != nil {
    71  		panic(err)
    72  	}
    73  
    74  Example to Delete a Router
    75  
    76  	routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
    77  	err := routers.Delete(networkClient, routerID).ExtractErr()
    78  	if err != nil {
    79  		panic(err)
    80  	}
    81  
    82  Example to Add an Interface to a Router
    83  
    84  	routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
    85  
    86  	intOpts := routers.AddInterfaceOpts{
    87  		SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1",
    88  	}
    89  
    90  	interface, err := routers.AddInterface(networkClient, routerID, intOpts).Extract()
    91  	if err != nil {
    92  		panic(err)
    93  	}
    94  
    95  Example to Remove an Interface from a Router
    96  
    97  	routerID := "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
    98  
    99  	intOpts := routers.RemoveInterfaceOpts{
   100  		SubnetID: "a2f1f29d-571b-4533-907f-5803ab96ead1",
   101  	}
   102  
   103  	interface, err := routers.RemoveInterface(networkClient, routerID, intOpts).Extract()
   104  	if err != nil {
   105  		panic(err)
   106  	}
   107  */
   108  package routers