Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame^] | 1 | /* |
| 2 | Package ports contains the functionality to Listing, Searching, Creating, Updating, |
| 3 | and Deleting of bare metal Port resources |
| 4 | |
| 5 | API reference: https://developer.openstack.org/api-ref/baremetal/#ports-ports |
| 6 | |
| 7 | |
| 8 | Example to List Ports with Detail |
| 9 | |
| 10 | ports.ListDetail(client, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 11 | portList, err := ports.ExtractPorts(page) |
| 12 | if err != nil { |
| 13 | return false, err |
| 14 | } |
| 15 | |
| 16 | for _, n := range portList { |
| 17 | // Do something |
| 18 | } |
| 19 | |
| 20 | return true, nil |
| 21 | }) |
| 22 | |
| 23 | Example to List Ports |
| 24 | |
| 25 | listOpts := ports.ListOpts{ |
| 26 | Limit: 10, |
| 27 | } |
| 28 | |
| 29 | ports.List(client, listOpts).EachPage(func(page pagination.Page) (bool, error) { |
| 30 | portList, err := ports.ExtractPorts(page) |
| 31 | if err != nil { |
| 32 | return false, err |
| 33 | } |
| 34 | |
| 35 | for _, n := range portList { |
| 36 | // Do something |
| 37 | } |
| 38 | |
| 39 | return true, nil |
| 40 | }) |
| 41 | |
| 42 | Example to Create a Port |
| 43 | |
| 44 | createOpts := ports.CreateOpts{ |
| 45 | NodeUUID: "e8920409-e07e-41bb-8cc1-72acb103e2dd", |
| 46 | Address: "00:1B:63:84:45:E6", |
| 47 | PhysicalNetwork: "my-network", |
| 48 | } |
| 49 | |
| 50 | createPort, err := ports.Create(client, createOpts).Extract() |
| 51 | if err != nil { |
| 52 | panic(err) |
| 53 | } |
| 54 | |
| 55 | Example to Get a Port |
| 56 | |
| 57 | showPort, err := ports.Get(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").Extract() |
| 58 | if err != nil { |
| 59 | panic(err) |
| 60 | } |
| 61 | |
| 62 | Example to Update a Port |
| 63 | |
| 64 | updateOpts := ports.UpdateOpts{ |
| 65 | ports.UpdateOperation{ |
| 66 | Op: ReplaceOp, |
| 67 | Path: "/address", |
| 68 | Value: "22:22:22:22:22:22", |
| 69 | }, |
| 70 | } |
| 71 | |
| 72 | updatePort, err := ports.Update(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474", updateOpts).Extract() |
| 73 | if err != nil { |
| 74 | panic(err) |
| 75 | } |
| 76 | |
| 77 | Example to Delete a Port |
| 78 | |
| 79 | err = ports.Delete(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").ExtractErr() |
| 80 | if err != nil { |
| 81 | panic(err) |
| 82 | } |
| 83 | |
| 84 | */ |
| 85 | package ports |