github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/er/v3/instances/results.go (about) 1 package instances 2 3 import ( 4 "github.com/chnsz/golangsdk/openstack/common/tags" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // Instance is the structure that represents the details of the ER instance. 9 type Instance struct { 10 // The ID of the instance. 11 ID string `json:"id"` 12 // The name of the instance. 13 Name string `json:"name"` 14 // The destination of the instance. 15 Description string `json:"description"` 16 // The current status of the instance. 17 Status string `json:"state"` 18 // The key/value pairs to associate with the instance. 19 Tags []tags.ResourceTag `json:"tags"` 20 // The creation time of the instance. 21 CreatedAt string `json:"created_at"` 22 // The last update time of the instance. 23 UpdatedAt string `json:"updated_at"` 24 // The ID of enterprise project to which the instance belongs. 25 EnterpriseProjectId string `json:"enterprise_project_id"` 26 // The project ID. 27 ProjectId string `json:"project_id"` 28 // The BGP AS number of the ER instance. 29 ASN int `json:"asn"` 30 // Whether to enable the propagation of the default route table. 31 EnableDefaultPropagation bool `json:"enable_default_propagation"` 32 // Whether to enable the association of the default route table. 33 EnableDefaultAssociation bool `json:"enable_default_association"` 34 // Whether to automatically accept the creation of shared attachment. 35 AutoAcceptSharedAttachments bool `json:"auto_accept_shared_attachments"` 36 // The ID of the default propagation route table. 37 DefaultPropagationRouteTableId string `json:"default_propagation_route_table_id"` 38 // The ID of the default association route table. 39 DefaultAssociationRouteTableId string `json:"default_association_route_table_id"` 40 // The availability zone list where the ER instance is located. 41 AvailabilityZoneIds []string `json:"availability_zone_ids"` 42 } 43 44 // listResp is the structure that represents the API response of the 'List' method, which contains instance list, page 45 // details and the request information. 46 type listResp struct { 47 // The list of the instances. 48 Instances []Instance `json:"instances"` 49 // The request ID. 50 RequestId string `json:"request_id"` 51 // The page information. 52 PageInfo pageInfo `json:"page_info"` 53 } 54 55 // pageInfo is the structure that represents the page information. 56 type pageInfo struct { 57 // The next marker information. 58 NextMarker string `json:"next_marker"` 59 // The number of the instances in current page. 60 CurrentCount int `json:"current_count"` 61 } 62 63 // InstancePage represents the response pages of the List method. 64 type InstancePage struct { 65 pagination.MarkerPageBase 66 } 67 68 // IsEmpty returns true if a ListResult no instance. 69 func (r InstancePage) IsEmpty() (bool, error) { 70 resp, err := extractInstances(r) 71 return len(resp) == 0, err 72 } 73 74 // LastMarker returns the last marker index in a ListResult. 75 func (r InstancePage) LastMarker() (string, error) { 76 resp, err := extractPageInfo(r) 77 if err != nil { 78 return "", err 79 } 80 if resp.NextMarker != "" { 81 return "", nil 82 } 83 return resp.NextMarker, nil 84 } 85 86 // extractPageInfo is a method which to extract the response of the page information. 87 func extractPageInfo(r pagination.Page) (*pageInfo, error) { 88 var s listResp 89 err := r.(InstancePage).Result.ExtractInto(&s) 90 return &s.PageInfo, err 91 } 92 93 // extractInstances is a method which to extract the response to an instance list. 94 func extractInstances(r pagination.Page) ([]Instance, error) { 95 var s listResp 96 err := r.(InstancePage).Result.ExtractInto(&s) 97 return s.Instances, err 98 }