github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/er/v3/attachments/results.go (about) 1 package attachments 2 3 import ( 4 "github.com/chnsz/golangsdk/openstack/common/tags" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // listResp is the structure that represents the ER attachment list, page detail and the request information. 9 type listResp struct { 10 // The list of the ER attachment. 11 Attachments []Attachment `json:"attachments"` 12 // The request ID. 13 RequestId string `json:"request_id"` 14 // The page information. 15 PageInfo PageInfo `json:"page_info"` 16 } 17 18 // Attachment is the structure that represents the ER attachment (type of VPC, VPN, VGW and PEERING) details. 19 type Attachment struct { 20 // The attachment ID. 21 ID string `json:"id"` 22 // The attachment name. 23 Name string `json:"name"` 24 // The attachment description. 25 Description string `json:"description"` 26 // The current status of the attachment. 27 // + pending 28 // + available 29 // + modifying 30 // + deleting 31 // + failed 32 // + pending_acceptance 33 // + rejected 34 // + initiating_request 35 // + freezed 36 Status string `json:"state"` 37 // The creation time of the attachment. 38 CreatedAt string `json:"created_at"` 39 // The latest update time of the attachment. 40 UpdatedAt string `json:"updated_at"` 41 // The tag list associated with the attachment. 42 Tags []tags.ResourceTag `json:"tags"` 43 // The project ID where the attachment is located. 44 ProjectId string `json:"project_id"` 45 // The ER instance ID to which the attachment is belongs. 46 InstanceId string `json:"er_id"` 47 // The resource ID associated with the internal connection. 48 ResourceId string `json:"resource_id"` 49 // The resource type. 50 // + vpc: virtual private cloud. 51 // + vpn: vpn gateway. 52 // + vgw: virtual gateway of cloud private line. 53 // + peering: Peering connection, through the cloud connection (CC) to load enterprise routers in different regions 54 // to create a peering connection. 55 ResourceType string `q:"resource_type"` 56 // The project ID to which the attachment is belongs. 57 ResourceProjectId string `json:"resource_project_id"` 58 // Whether this attachment is associated. 59 Associated bool `json:"associated"` 60 // The associated route table ID. 61 RouteTableId string `json:"route_table_id"` 62 } 63 64 // PageInfo is the structure that represents the page information. 65 type PageInfo struct { 66 // The next marker (next page index) information. 67 NextMarker string `json:"next_marker"` 68 // The number of the ER attahcment in current page. 69 CurrentCount int `json:"current_count"` 70 } 71 72 // AttachmentPage represents the response pages of the List method. 73 type AttachmentPage struct { 74 pagination.MarkerPageBase 75 } 76 77 // IsEmpty returns true if current page no ER attachment. 78 func (r AttachmentPage) IsEmpty() (bool, error) { 79 resp, err := extractAttachments(r) 80 return len(resp) == 0, err 81 } 82 83 // LastMarker returns the last marker index during current page. 84 func (r AttachmentPage) LastMarker() (string, error) { 85 resp, err := extractPageInfo(r) 86 if err != nil { 87 return "", err 88 } 89 return resp.NextMarker, nil 90 } 91 92 // NextPageURL generates the URL for the page of results after this one. 93 func (r AttachmentPage) NextPageURL() (string, error) { 94 currentURL := r.URL 95 96 mark, err := r.Owner.LastMarker() 97 if err != nil { 98 return "", err 99 } 100 if mark == "" { 101 return "", nil 102 } 103 104 q := currentURL.Query() 105 q.Set("marker", mark) 106 currentURL.RawQuery = q.Encode() 107 108 return currentURL.String(), nil 109 } 110 111 // extractPageInfo is a method which to extract the response of the page information. 112 func extractPageInfo(r pagination.Page) (*PageInfo, error) { 113 var s listResp 114 err := r.(AttachmentPage).Result.ExtractInto(&s) 115 return &s.PageInfo, err 116 } 117 118 // extractAttachments is a method which to extract the response to an attachment list. 119 func extractAttachments(r pagination.Page) ([]Attachment, error) { 120 var s listResp 121 err := r.(AttachmentPage).Result.ExtractInto(&s) 122 return s.Attachments, err 123 }