github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/trunks/results.go (about) 1 package trunks 2 3 import ( 4 "time" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 type Subport struct { 11 SegmentationID int `json:"segmentation_id" required:"true"` 12 SegmentationType string `json:"segmentation_type" required:"true"` 13 PortID string `json:"port_id" required:"true"` 14 } 15 16 type commonResult struct { 17 gophercloud.Result 18 } 19 20 // CreateResult is the response from a Create operation. Call its Extract method 21 // to interpret it as a Trunk. 22 type CreateResult struct { 23 commonResult 24 } 25 26 // DeleteResult is the response from a Delete operation. Call its ExtractErr to 27 // determine if the request succeeded or failed. 28 type DeleteResult struct { 29 gophercloud.ErrResult 30 } 31 32 // GetResult is the response from a Get operation. Call its Extract method 33 // to interpret it as a Trunk. 34 type GetResult struct { 35 commonResult 36 } 37 38 // UpdateResult is the result of an Update request. Call its Extract method to 39 // interpret it as a Trunk. 40 type UpdateResult struct { 41 commonResult 42 } 43 44 // GetSubportsResult is the result of a Get request on the trunks subports 45 // resource. Call its Extract method to interpret it as a slice of Subport. 46 type GetSubportsResult struct { 47 commonResult 48 } 49 50 // UpdateSubportsResult is the result of either an AddSubports or a RemoveSubports 51 // request. Call its Extract method to interpret it as a Trunk. 52 type UpdateSubportsResult struct { 53 commonResult 54 } 55 56 type Trunk struct { 57 // Indicates whether the trunk is currently operational. Possible values include 58 // `ACTIVE', `DOWN', `BUILD', 'DEGRADED' or `ERROR'. 59 Status string `json:"status"` 60 61 // A list of ports associated with the trunk 62 Subports []Subport `json:"sub_ports"` 63 64 // Human-readable name for the trunk. Might not be unique. 65 Name string `json:"name,omitempty"` 66 67 // The administrative state of the trunk. If false (down), the trunk does not 68 // forward packets. 69 AdminStateUp bool `json:"admin_state_up,omitempty"` 70 71 // ProjectID is the project owner of the trunk. 72 ProjectID string `json:"project_id"` 73 74 // TenantID is the project owner of the trunk. 75 TenantID string `json:"tenant_id"` 76 77 // The date and time when the resource was created. 78 CreatedAt time.Time `json:"created_at"` 79 80 // The date and time when the resource was updated, 81 // if the resource has not been updated, this field will show as null. 82 UpdatedAt time.Time `json:"updated_at"` 83 84 RevisionNumber int `json:"revision_number"` 85 86 // UUID of the trunk's parent port 87 PortID string `json:"port_id"` 88 89 // UUID for the trunk resource 90 ID string `json:"id"` 91 92 // Display description. 93 Description string `json:"description"` 94 95 // A list of tags associated with the trunk 96 Tags []string `json:"tags,omitempty"` 97 } 98 99 func (r commonResult) Extract() (*Trunk, error) { 100 var s struct { 101 Trunk *Trunk `json:"trunk"` 102 } 103 err := r.ExtractInto(&s) 104 return s.Trunk, err 105 } 106 107 // TrunkPage is the page returned by a pager when traversing a collection of 108 // trunk resources. 109 type TrunkPage struct { 110 pagination.LinkedPageBase 111 } 112 113 func (page TrunkPage) IsEmpty() (bool, error) { 114 if page.StatusCode == 204 { 115 return true, nil 116 } 117 118 trunks, err := ExtractTrunks(page) 119 return len(trunks) == 0, err 120 } 121 122 func ExtractTrunks(page pagination.Page) ([]Trunk, error) { 123 var a struct { 124 Trunks []Trunk `json:"trunks"` 125 } 126 err := (page.(TrunkPage)).ExtractInto(&a) 127 return a.Trunks, err 128 } 129 130 func (r GetSubportsResult) Extract() ([]Subport, error) { 131 var s struct { 132 Subports []Subport `json:"sub_ports"` 133 } 134 err := r.ExtractInto(&s) 135 return s.Subports, err 136 } 137 138 func (r UpdateSubportsResult) Extract() (t *Trunk, err error) { 139 err = r.ExtractInto(&t) 140 return 141 }