Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 1 | // +build acceptance compute quotasets |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 6 | "fmt" |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 7 | "testing" |
| 8 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" |
| 11 | "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 12 | ) |
| 13 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 14 | func TestQuotasetGet(t *testing.T) { |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 15 | client, err := newClient() |
| 16 | if err != nil { |
| 17 | t.Fatalf("Unable to create a compute client: %v", err) |
| 18 | } |
| 19 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 20 | identityClient, err := newIdentityClient() |
| 21 | if err != nil { |
| 22 | t.Fatalf("Unable to get a new identity client: %v", err) |
| 23 | } |
| 24 | |
| 25 | tenantID, err := getTenantID(t, identityClient) |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 26 | if err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 30 | quotaSet, err := quotasets.Get(client, tenantID).Extract() |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 34 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 35 | printQuotaSet(t, quotaSet) |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 36 | } |
| 37 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 38 | func getTenantID(t *testing.T, client *gophercloud.ServiceClient) (string, error) { |
| 39 | allPages, err := tenants.List(client, nil).AllPages() |
| 40 | if err != nil { |
| 41 | t.Fatalf("Unable to get list of tenants: %v", err) |
| 42 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 43 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 44 | allTenants, err := tenants.ExtractTenants(allPages) |
| 45 | if err != nil { |
| 46 | t.Fatalf("Unable to extract tenants: %v", err) |
| 47 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 48 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 49 | for _, tenant := range allTenants { |
| 50 | return tenant.ID, nil |
| 51 | } |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 52 | |
Joe Topjian | 713e51a | 2016-07-25 19:06:25 +0000 | [diff] [blame^] | 53 | return "", fmt.Errorf("Unable to get tenant ID") |
| 54 | } |
| 55 | |
| 56 | func printQuotaSet(t *testing.T, quotaSet *quotasets.QuotaSet) { |
| 57 | t.Logf("instances: %d\n", quotaSet.Instances) |
| 58 | t.Logf("cores: %d\n", quotaSet.Cores) |
| 59 | t.Logf("ram: %d\n", quotaSet.Ram) |
| 60 | t.Logf("key_pairs: %d\n", quotaSet.KeyPairs) |
| 61 | t.Logf("metadata_items: %d\n", quotaSet.MetadataItems) |
| 62 | t.Logf("security_groups: %d\n", quotaSet.SecurityGroups) |
| 63 | t.Logf("security_group_rules: %d\n", quotaSet.SecurityGroupRules) |
| 64 | t.Logf("fixed_ips: %d\n", quotaSet.FixedIps) |
| 65 | t.Logf("floating_ips: %d\n", quotaSet.FloatingIps) |
| 66 | t.Logf("injected_file_content_bytes: %d\n", quotaSet.InjectedFileContentBytes) |
| 67 | t.Logf("injected_file_path_bytes: %d\n", quotaSet.InjectedFilePathBytes) |
| 68 | t.Logf("injected_files: %d\n", quotaSet.InjectedFiles) |
Dan Kirkwood | ed3f5fd | 2016-03-16 12:41:47 -0600 | [diff] [blame] | 69 | } |