github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/er/v3/instances/requests.go (about) 1 package instances 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // ListOpts allows to filter list data using given parameters. 9 type ListOpts struct { 10 // Number of records to be queried. 11 // The valid value is range from 0 to 2000. 12 Limit int `q:"limit"` 13 // The ID of the instance of the last record on the previous page. 14 // If it is empty, it is the first page of the query. 15 // This parameter must be used together with limit. 16 // The valid value is range from 1 to 128. 17 Marker string `q:"marker"` 18 // The enterprise project IDs of the instance to be queried. 19 EnterpriseProjectIds []string `q:"enterprise_project_id"` 20 // The status list of the instance to be queried. 21 Statuses []string `q:"state"` 22 // The instance IDs to be queried. 23 IDs []string `q:"id"` 24 // The resource IDs corresponding to the connection. 25 ResourceIds []string `q:"resource_id"` 26 // Whether resources belong to the current renant. If this parameter is set to true, only resources belonging to the 27 // current tenant are queried, excluding shared resources. If the value is false, the current tenant and resources 28 // shared with the tenant are queried. 29 OwnedBySelf bool `q:"owned_by_self"` 30 // The list of the destinations, support for querying multiple instances. 31 SortKey []string `q:"sort_key"` 32 // The returned results are arranged in ascending or descending order, the default is asc. 33 SortDir []string `q:"sort_dir"` 34 } 35 36 // List is a method to query the list of the instances using given parameters. 37 func List(client *golangsdk.ServiceClient, opts ListOpts) ([]Instance, error) { 38 url := rootURL(client) 39 query, err := golangsdk.BuildQueryString(opts) 40 if err != nil { 41 return nil, err 42 } 43 url += query.String() 44 45 pages, err := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 46 p := InstancePage{pagination.MarkerPageBase{PageResult: r}} 47 p.MarkerPageBase.Owner = p 48 return p 49 }).AllPages() 50 51 if err != nil { 52 return nil, err 53 } 54 return extractInstances(pages) 55 }