github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/usage/doc.go (about) 1 /* 2 Package usage provides information and interaction with the 3 SimpleTenantUsage extension for the OpenStack Compute service. 4 5 Due to the way the API responses are formatted, it is not recommended to 6 query by using the AllPages convenience method. Instead, use the EachPage 7 method to view each result page-by-page. 8 9 This is because the usage calculations are done _per page_ and not as 10 an aggregated total of the entire usage set. 11 12 Example to Retrieve Usage for a Single Tenant: 13 14 start := time.Date(2017, 01, 21, 10, 4, 20, 0, time.UTC) 15 end := time.Date(2017, 01, 21, 10, 4, 20, 0, time.UTC) 16 17 singleTenantOpts := usage.SingleTenantOpts{ 18 Start: &start, 19 End: &end, 20 } 21 22 err := usage.SingleTenant(computeClient, tenantID, singleTenantOpts).EachPage(func(page pagination.Page) (bool, error) { 23 tenantUsage, err := usage.ExtractSingleTenant(page) 24 if err != nil { 25 return false, err 26 } 27 28 fmt.Printf("%+v\n", tenantUsage) 29 30 return true, nil 31 }) 32 33 if err != nil { 34 panic(err) 35 } 36 37 Example to Retrieve Usage for All Tenants: 38 39 allTenantsOpts := usage.AllTenantsOpts{ 40 Detailed: true, 41 } 42 43 err := usage.AllTenants(computeClient, allTenantsOpts).EachPage(func(page pagination.Page) (bool, error) { 44 allTenantsUsage, err := usage.ExtractAllTenants(page) 45 if err != nil { 46 return false, err 47 } 48 49 fmt.Printf("%+v\n", allTenantsUsage) 50 51 return true, nil 52 }) 53 54 if err != nil { 55 panic(err) 56 } 57 58 */ 59 package usage