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