Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame^] | 1 | package ports |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | |
| 6 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
| 7 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
| 8 | ) |
| 9 | |
| 10 | type portResult struct { |
| 11 | gophercloud.Result |
| 12 | } |
| 13 | |
| 14 | func (r portResult) Extract() (*Port, error) { |
| 15 | var s Port |
| 16 | err := r.ExtractInto(&s) |
| 17 | return &s, err |
| 18 | } |
| 19 | |
| 20 | func (r portResult) ExtractInto(v interface{}) error { |
| 21 | return r.Result.ExtractIntoStructPtr(v, "") |
| 22 | } |
| 23 | |
| 24 | func ExtractPortsInto(r pagination.Page, v interface{}) error { |
| 25 | return r.(PortPage).Result.ExtractIntoSlicePtr(v, "ports") |
| 26 | } |
| 27 | |
| 28 | // Port represents a port in the OpenStack Bare Metal API. |
| 29 | type Port struct { |
| 30 | // UUID for the resource. |
| 31 | UUID string `json:"uuid"` |
| 32 | |
| 33 | // Physical hardware address of this network Port, |
| 34 | // typically the hardware MAC address. |
| 35 | Address string `json:"address"` |
| 36 | |
| 37 | // UUID of the Node this resource belongs to. |
| 38 | NodeUUID string `json:"node_uuid"` |
| 39 | |
| 40 | // UUID of the Portgroup this resource belongs to. |
| 41 | PortGroupUUID string `json:"portgroup_uuid"` |
| 42 | |
| 43 | // The Port binding profile. If specified, must contain switch_id (only a MAC |
| 44 | // address or an OpenFlow based datapath_id of the switch are accepted in this |
| 45 | // field) and port_id (identifier of the physical port on the switch to which |
| 46 | // node’s port is connected to) fields. switch_info is an optional string |
| 47 | // field to be used to store any vendor-specific information. |
| 48 | LocalLinkConnection map[string]interface{} `json:"local_link_connection"` |
| 49 | |
| 50 | // Indicates whether PXE is enabled or disabled on the Port. |
| 51 | PXEEnabled bool `json:"pxe_enabled"` |
| 52 | |
| 53 | // The name of the physical network to which a port is connected. |
| 54 | // May be empty. |
| 55 | PhysicalNetwork string `json:"physical_network"` |
| 56 | |
| 57 | // Internal metadata set and stored by the Port. This field is read-only. |
| 58 | InternalInfo map[string]interface{} `json:"internal_info"` |
| 59 | |
| 60 | // A set of one or more arbitrary metadata key and value pairs. |
| 61 | Extra map[string]interface{} `json:"extra"` |
| 62 | |
| 63 | // The UTC date and time when the resource was created, ISO 8601 format. |
| 64 | CreatedAt time.Time `json:"created_at"` |
| 65 | |
| 66 | // The UTC date and time when the resource was updated, ISO 8601 format. |
| 67 | // May be “null”. |
| 68 | UpdatedAt time.Time `json:"updated_at"` |
| 69 | |
| 70 | // A list of relative links. Includes the self and bookmark links. |
| 71 | Links []interface{} `json:"links"` |
| 72 | |
| 73 | // Indicates whether the Port is a Smart NIC port. |
| 74 | IsSmartNIC bool `json:"is_smartnic"` |
| 75 | } |
| 76 | |
| 77 | // PortPage abstracts the raw results of making a List() request against |
| 78 | // the API. |
| 79 | type PortPage struct { |
| 80 | pagination.LinkedPageBase |
| 81 | } |
| 82 | |
| 83 | // IsEmpty returns true if a page contains no Port results. |
| 84 | func (r PortPage) IsEmpty() (bool, error) { |
| 85 | s, err := ExtractPorts(r) |
| 86 | return len(s) == 0, err |
| 87 | } |
| 88 | |
| 89 | // NextPageURL uses the response's embedded link reference to navigate to the |
| 90 | // next page of results. |
| 91 | func (r PortPage) NextPageURL() (string, error) { |
| 92 | var s struct { |
| 93 | Links []gophercloud.Link `json:"ports_links"` |
| 94 | } |
| 95 | err := r.ExtractInto(&s) |
| 96 | if err != nil { |
| 97 | return "", err |
| 98 | } |
| 99 | return gophercloud.ExtractNextURL(s.Links) |
| 100 | } |
| 101 | |
| 102 | // ExtractPorts interprets the results of a single page from a List() call, |
| 103 | // producing a slice of Port entities. |
| 104 | func ExtractPorts(r pagination.Page) ([]Port, error) { |
| 105 | var s []Port |
| 106 | err := ExtractPortsInto(r, &s) |
| 107 | return s, err |
| 108 | } |
| 109 | |
| 110 | // GetResult is the response from a Get operation. Call its Extract |
| 111 | // method to interpret it as a Port. |
| 112 | type GetResult struct { |
| 113 | portResult |
| 114 | } |
| 115 | |
| 116 | // CreateResult is the response from a Create operation. |
| 117 | type CreateResult struct { |
| 118 | portResult |
| 119 | } |
| 120 | |
| 121 | // UpdateResult is the response from an Update operation. Call its Extract |
| 122 | // method to interpret it as a Port. |
| 123 | type UpdateResult struct { |
| 124 | portResult |
| 125 | } |
| 126 | |
| 127 | // DeleteResult is the response from a Delete operation. Call its ExtractErr |
| 128 | // method to determine if the call succeeded or failed. |
| 129 | type DeleteResult struct { |
| 130 | gophercloud.ErrResult |
| 131 | } |