Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Gophercloud to v2-beta.2 #201

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gnocchi/metric/v1/archivepolicies/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ through the Gnocchi API.

Example of Listing archive policies

allPages, err := archivepolicies.List(gnocchiClient).AllPages()
allPages, err := archivepolicies.List(gnocchiClient).AllPages(ctx)
if err != nil {
panic(err)
}
Expand Down
18 changes: 10 additions & 8 deletions gnocchi/metric/v1/archivepolicies/requests.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package archivepolicies

import (
"context"

"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/pagination"
)
Expand All @@ -13,8 +15,8 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {
}

// Get retrieves a specific Gnocchi archive policy based on its name.
func Get(c *gophercloud.ServiceClient, archivePolicyName string) (r GetResult) {
_, r.Err = c.Get(getURL(c, archivePolicyName), &r.Body, nil)
func Get(ctx context.Context, c *gophercloud.ServiceClient, archivePolicyName string) (r GetResult) {
_, r.Err = c.Get(ctx, getURL(c, archivePolicyName), &r.Body, nil)
return
}

Expand Down Expand Up @@ -64,13 +66,13 @@ func (opts CreateOpts) ToArchivePolicyCreateMap() (map[string]interface{}, error
}

// Create requests the creation of a new Gnocchi archive policy on the server.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToArchivePolicyCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
_, r.Err = client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})

Expand All @@ -95,26 +97,26 @@ func (opts UpdateOpts) ToArchivePolicyUpdateMap() (map[string]interface{}, error
}

// Update accepts a UpdateOpts and updates an existing Gnocchi archive policy using the values provided.
func Update(client *gophercloud.ServiceClient, archivePolicyName string, opts UpdateOptsBuilder) (r UpdateResult) {
func Update(ctx context.Context, client *gophercloud.ServiceClient, archivePolicyName string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToArchivePolicyUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Patch(updateURL(client, archivePolicyName), b, &r.Body, &gophercloud.RequestOpts{
_, r.Err = client.Patch(ctx, updateURL(client, archivePolicyName), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})

return
}

// Delete accepts a Gnocchi archive policy by its name.
func Delete(c *gophercloud.ServiceClient, archivePolicyName string) (r DeleteResult) {
func Delete(ctx context.Context, c *gophercloud.ServiceClient, archivePolicyName string) (r DeleteResult) {
requestOpts := &gophercloud.RequestOpts{
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
},
}
_, r.Err = c.Delete(deleteURL(c, archivePolicyName), requestOpts)
_, r.Err = c.Delete(ctx, deleteURL(c, archivePolicyName), requestOpts)
return
}
13 changes: 7 additions & 6 deletions gnocchi/metric/v1/archivepolicies/testing/requests_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testing

import (
"context"
"fmt"
"net/http"
"testing"
Expand All @@ -27,7 +28,7 @@ func TestListArchivePolicies(t *testing.T) {

expected := ListArchivePoliciesExpected
pages := 0
err := archivepolicies.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
err := archivepolicies.List(fake.ServiceClient()).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
pages++

actual, err := archivepolicies.ExtractArchivePolicies(page)
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestListArchivePoliciesAllPages(t *testing.T) {
fmt.Fprintf(w, ArchivePoliciesListResult)
})

allPages, err := archivepolicies.List(fake.ServiceClient()).AllPages()
allPages, err := archivepolicies.List(fake.ServiceClient()).AllPages(context.TODO())
th.AssertNoErr(t, err)
_, err = archivepolicies.ExtractArchivePolicies(allPages)
th.AssertNoErr(t, err)
Expand All @@ -78,7 +79,7 @@ func TestGetArchivePolicy(t *testing.T) {
fmt.Fprintf(w, ArchivePolicyGetResult)
})

s, err := archivepolicies.Get(fake.ServiceClient(), "test_policy").Extract()
s, err := archivepolicies.Get(context.TODO(), fake.ServiceClient(), "test_policy").Extract()
th.AssertNoErr(t, err)

th.AssertDeepEquals(t, s.AggregationMethods, []string{
Expand Down Expand Up @@ -138,7 +139,7 @@ func TestCreate(t *testing.T) {
},
Name: "test_policy",
}
s, err := archivepolicies.Create(fake.ServiceClient(), opts).Extract()
s, err := archivepolicies.Create(context.TODO(), fake.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)

th.AssertDeepEquals(t, s.AggregationMethods, []string{
Expand Down Expand Up @@ -191,7 +192,7 @@ func TestUpdateArchivePolicy(t *testing.T) {
},
},
}
s, err := archivepolicies.Update(fake.ServiceClient(), "test_policy", updateOpts).Extract()
s, err := archivepolicies.Update(context.TODO(), fake.ServiceClient(), "test_policy", updateOpts).Extract()
th.AssertNoErr(t, err)

th.AssertDeepEquals(t, s.AggregationMethods, []string{
Expand Down Expand Up @@ -223,6 +224,6 @@ func TestDelete(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})

res := archivepolicies.Delete(fake.ServiceClient(), "test_policy")
res := archivepolicies.Delete(context.TODO(), fake.ServiceClient(), "test_policy")
th.AssertNoErr(t, res.Err)
}
2 changes: 1 addition & 1 deletion gnocchi/metric/v1/measures/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Example of Listing measures of a known metric
Granularity: "1h",
Start: &startTime,
}
allPages, err := measures.List(gnocchiClient, metricID, listOpts).AllPages()
allPages, err := measures.List(gnocchiClient, metricID, listOpts).AllPages(ctx)
if err != nil {
panic(err)
}
Expand Down
13 changes: 7 additions & 6 deletions gnocchi/metric/v1/measures/requests.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package measures

import (
"context"
"fmt"
"net/url"
"time"
Expand Down Expand Up @@ -121,13 +122,13 @@ func (opts CreateOpts) ToMeasureCreateMap() (map[string]interface{}, error) {
}

// Create requests the creation of a new measures in the single Gnocchi metric.
func Create(client *gophercloud.ServiceClient, metricID string, opts CreateOptsBuilder) (r CreateResult) {
func Create(ctx context.Context, client *gophercloud.ServiceClient, metricID string, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToMeasureCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client, metricID), b["measures"], &r.Body, &gophercloud.RequestOpts{
_, r.Err = client.Post(ctx, createURL(client, metricID), b["measures"], &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{202},
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
Expand Down Expand Up @@ -202,14 +203,14 @@ func (opts BatchCreateMetricsOpts) ToMeasuresBatchCreateMetricsMap() (map[string
}

// BatchCreateMetrics requests the creation of a new measures for different metrics.
func BatchCreateMetrics(client *gophercloud.ServiceClient, opts BatchCreateMetricsOpts) (r BatchCreateMetricsResult) {
func BatchCreateMetrics(ctx context.Context, client *gophercloud.ServiceClient, opts BatchCreateMetricsOpts) (r BatchCreateMetricsResult) {
b, err := opts.ToMeasuresBatchCreateMetricsMap()
if err != nil {
r.Err = err
return
}

_, r.Err = client.Post(batchCreateMetricsURL(client), b["batchCreateMetrics"], &r.Body, &gophercloud.RequestOpts{
_, r.Err = client.Post(ctx, batchCreateMetricsURL(client), b["batchCreateMetrics"], &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{202},
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
Expand Down Expand Up @@ -372,7 +373,7 @@ func (opts BatchCreateResourcesMetricsOpts) ToMeasuresBatchCreateResourcesMetric
}

// BatchCreateResourcesMetrics requests the creation of new measures inside metrics via resource IDs and metric names.
func BatchCreateResourcesMetrics(client *gophercloud.ServiceClient, opts BatchCreateResourcesMetricsOptsBuilder) (r BatchCreateResourcesMetricsResult) {
func BatchCreateResourcesMetrics(ctx context.Context, client *gophercloud.ServiceClient, opts BatchCreateResourcesMetricsOptsBuilder) (r BatchCreateResourcesMetricsResult) {
url := batchCreateResourcesMetricsURL(client)
if opts != nil {
query, err := opts.ToMeasuresBatchCreateResourcesMetricsQuery()
Expand All @@ -389,7 +390,7 @@ func BatchCreateResourcesMetrics(client *gophercloud.ServiceClient, opts BatchCr
return
}

_, r.Err = client.Post(url, b["batchCreateResourcesMetrics"], &r.Body, &gophercloud.RequestOpts{
_, r.Err = client.Post(ctx, url, b["batchCreateResourcesMetrics"], &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{202},
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
Expand Down
9 changes: 5 additions & 4 deletions gnocchi/metric/v1/measures/testing/requests_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testing

import (
"context"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -36,7 +37,7 @@ func TestListMeasures(t *testing.T) {
}
expected := ListMeasuresExpected
pages := 0
err := measures.List(fake.ServiceClient(), metricID, opts).EachPage(func(page pagination.Page) (bool, error) {
err := measures.List(fake.ServiceClient(), metricID, opts).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
pages++

actual, err := measures.ExtractMeasures(page)
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestCreateMeasures(t *testing.T) {
},
},
}
res := measures.Create(fake.ServiceClient(), "9e5a6441-1044-4181-b66e-34e180753040", createOpts)
res := measures.Create(context.TODO(), fake.ServiceClient(), "9e5a6441-1044-4181-b66e-34e180753040", createOpts)
th.AssertNoErr(t, res.Err)
}

Expand Down Expand Up @@ -129,7 +130,7 @@ func TestBatchCreateMetrics(t *testing.T) {
},
},
}
res := measures.BatchCreateMetrics(fake.ServiceClient(), createOpts)
res := measures.BatchCreateMetrics(context.TODO(), fake.ServiceClient(), createOpts)
th.AssertNoErr(t, res.Err)
}

Expand Down Expand Up @@ -209,6 +210,6 @@ func TestBatchCreateResourcesMetrics(t *testing.T) {
},
},
}
res := measures.BatchCreateResourcesMetrics(fake.ServiceClient(), createOpts)
res := measures.BatchCreateResourcesMetrics(context.TODO(), fake.ServiceClient(), createOpts)
th.AssertNoErr(t, res.Err)
}
2 changes: 1 addition & 1 deletion gnocchi/metric/v1/metrics/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Example of Listing metrics
Limit: 25,
}

allPages, err := metrics.List(gnocchiClient, listOpts).AllPages()
allPages, err := metrics.List(gnocchiClient, listOpts).AllPages(ctx)
if err != nil {
panic(err)
}
Expand Down
14 changes: 8 additions & 6 deletions gnocchi/metric/v1/metrics/requests.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package metrics

import (
"context"

"github.com/gophercloud/gophercloud/v2"
"github.com/gophercloud/gophercloud/v2/pagination"
)
Expand Down Expand Up @@ -68,8 +70,8 @@ func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
}

// Get retrieves a specific Gnocchi metric based on its id.
func Get(c *gophercloud.ServiceClient, metricID string) (r GetResult) {
_, r.Err = c.Get(getURL(c, metricID), &r.Body, nil)
func Get(ctx context.Context, c *gophercloud.ServiceClient, metricID string) (r GetResult) {
_, r.Err = c.Get(ctx, getURL(c, metricID), &r.Body, nil)
return
}

Expand Down Expand Up @@ -109,25 +111,25 @@ func (opts CreateOpts) ToMetricCreateMap() (map[string]interface{}, error) {
}

// Create requests the creation of a new Gnocchi metric on the server.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToMetricCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
_, r.Err = client.Post(ctx, createURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
return
}

// Delete accepts a unique ID and deletes the Gnocchi metric associated with it.
func Delete(c *gophercloud.ServiceClient, metricID string) (r DeleteResult) {
func Delete(ctx context.Context, c *gophercloud.ServiceClient, metricID string) (r DeleteResult) {
requestOpts := &gophercloud.RequestOpts{
MoreHeaders: map[string]string{
"Accept": "application/json, */*",
},
}
_, r.Err = c.Delete(deleteURL(c, metricID), requestOpts)
_, r.Err = c.Delete(ctx, deleteURL(c, metricID), requestOpts)
return
}
9 changes: 5 additions & 4 deletions gnocchi/metric/v1/metrics/testing/requests_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testing

import (
"context"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -38,7 +39,7 @@ func TestList(t *testing.T) {

count := 0

metrics.List(fake.ServiceClient(), metrics.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
metrics.List(fake.ServiceClient(), metrics.ListOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
count++
actual, err := metrics.ExtractMetrics(page)
if err != nil {
Expand Down Expand Up @@ -75,7 +76,7 @@ func TestGet(t *testing.T) {
fmt.Fprintf(w, MetricGetResult)
})

s, err := metrics.Get(fake.ServiceClient(), "0ddf61cf-3747-4f75-bf13-13c28ff03ae3").Extract()
s, err := metrics.Get(context.TODO(), fake.ServiceClient(), "0ddf61cf-3747-4f75-bf13-13c28ff03ae3").Extract()
th.AssertNoErr(t, err)

th.AssertDeepEquals(t, s.ArchivePolicy, archivepolicies.ArchivePolicy{
Expand Down Expand Up @@ -144,7 +145,7 @@ func TestCreate(t *testing.T) {
ResourceID: "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55",
Unit: "B/s",
}
s, err := metrics.Create(fake.ServiceClient(), opts).Extract()
s, err := metrics.Create(context.TODO(), fake.ServiceClient(), opts).Extract()
th.AssertNoErr(t, err)

th.AssertEquals(t, s.ArchivePolicyName, "high")
Expand All @@ -167,6 +168,6 @@ func TestDelete(t *testing.T) {
w.WriteHeader(http.StatusNoContent)
})

res := metrics.Delete(fake.ServiceClient(), "01b2953e-de74-448a-a305-c84440697933")
res := metrics.Delete(context.TODO(), fake.ServiceClient(), "01b2953e-de74-448a-a305-c84440697933")
th.AssertNoErr(t, res.Err)
}
2 changes: 1 addition & 1 deletion gnocchi/metric/v1/resources/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Example of Listing resources
Details: True,
}

allPages, err := resources.List(gnocchiClient, listOpts, resourceType).AllPages()
allPages, err := resources.List(gnocchiClient, listOpts, resourceType).AllPages(ctx)
if err != nil {
panic(err)
}
Expand Down
Loading
Loading