Skip to content

Commit cfddd65

Browse files
committed
Support volume type create in V3
Add create API in V3's volume type resource
1 parent 06f0a57 commit cfddd65

5 files changed

Lines changed: 0 additions & 239 deletions

File tree

openstack/blockstorage/v3/volumetypes/requests.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package volumetypes
22

33
import (
44
"github.com/gophercloud/gophercloud"
5-
"github.com/gophercloud/gophercloud/pagination"
65
)
76

87
// CreateOptsBuilder allows extensions to add additional parameters to the
@@ -43,60 +42,3 @@ func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r Create
4342
})
4443
return
4544
}
46-
47-
// Delete will delete the existing Volume Type with the provided ID.
48-
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
49-
_, r.Err = client.Delete(deleteURL(client, id), nil)
50-
return
51-
}
52-
53-
// Get retrieves the Volume Type with the provided ID. To extract the Volume Type object
54-
// from the response, call the Extract method on the GetResult.
55-
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
56-
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
57-
return
58-
}
59-
60-
// List returns Volume types.
61-
func List(client *gophercloud.ServiceClient) pagination.Pager {
62-
url := listURL(client)
63-
64-
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
65-
return VolumeTypePage{pagination.SinglePageBase(r)}
66-
})
67-
}
68-
69-
// UpdateOptsBuilder allows extensions to add additional parameters to the
70-
// Update request.
71-
type UpdateOptsBuilder interface {
72-
ToVolumeTypeUpdateMap() (map[string]interface{}, error)
73-
}
74-
75-
// UpdateOpts contain options for updating an existing Volume Type. This object is passed
76-
// to the volumetypes.Update function. For more information about the parameters, see
77-
// the Volume Type object.
78-
type UpdateOpts struct {
79-
Name string `json:"name,omitempty"`
80-
Description string `json:"description,omitempty"`
81-
IsPublic bool `json:"is_public"`
82-
}
83-
84-
// ToVolumeUpdateMap assembles a request body based on the contents of an
85-
// UpdateOpts.
86-
func (opts UpdateOpts) ToVolumeTypeUpdateMap() (map[string]interface{}, error) {
87-
return gophercloud.BuildRequestBody(opts, "volume_type")
88-
}
89-
90-
// Update will update the Volume Type with provided information. To extract the updated
91-
// Volume Type from the response, call the Extract method on the UpdateResult.
92-
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
93-
b, err := opts.ToVolumeTypeUpdateMap()
94-
if err != nil {
95-
r.Err = err
96-
return
97-
}
98-
_, r.Err = client.Put(updateURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
99-
OkCodes: []int{200},
100-
})
101-
return
102-
}

openstack/blockstorage/v3/volumetypes/results.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,3 @@ func ExtractVolumeTypesInto(r pagination.Page, v interface{}) error {
7979
type CreateResult struct {
8080
commonResult
8181
}
82-
83-
// GetResult contains the response body and error from a Get request.
84-
type GetResult struct {
85-
commonResult
86-
}
87-
88-
// UpdateResult contains the response body and error from an Update request.
89-
type UpdateResult struct {
90-
commonResult
91-
}
92-
93-
// DeleteResult contains the response body and error from a Delete request.
94-
type DeleteResult struct {
95-
gophercloud.ErrResult
96-
}

openstack/blockstorage/v3/volumetypes/testing/fixtures.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,6 @@ import (
99
fake "github.com/gophercloud/gophercloud/testhelper/client"
1010
)
1111

12-
func MockListResponse(t *testing.T) {
13-
th.Mux.HandleFunc("/types", func(w http.ResponseWriter, r *http.Request) {
14-
th.TestMethod(t, r, "GET")
15-
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
16-
17-
w.Header().Add("Content-Type", "application/json")
18-
w.WriteHeader(http.StatusOK)
19-
20-
fmt.Fprintf(w, `
21-
{
22-
"volume_types": [
23-
{
24-
"name": "SSD",
25-
"qos_specs_id": null,
26-
"extra_specs": {
27-
"volume_backend_name": "lvmdriver-1"
28-
},
29-
"is_public": true,
30-
"id": "6685584b-1eac-4da6-b5c3-555430cf68ff",
31-
"description": null
32-
},
33-
{
34-
"name": "SATA",
35-
"qos_specs_id": null,
36-
"extra_specs": {
37-
"volume_backend_name": "lvmdriver-1"
38-
},
39-
"is_public": true,
40-
"id": "8eb69a46-df97-4e41-9586-9a40a7533803",
41-
"description": null
42-
}
43-
]
44-
}
45-
`)
46-
})
47-
}
48-
49-
func MockGetResponse(t *testing.T) {
50-
th.Mux.HandleFunc("/types/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
51-
th.TestMethod(t, r, "GET")
52-
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
53-
54-
w.Header().Add("Content-Type", "application/json")
55-
w.WriteHeader(http.StatusOK)
56-
fmt.Fprintf(w, `
57-
{
58-
"volume_type": {
59-
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
60-
"name": "vol-type-001",
61-
"description": "volume type 001",
62-
"is_public": true,
63-
"extra_specs": {
64-
"capabilities": "gpu"
65-
}
66-
}
67-
}
68-
`)
69-
})
70-
}
71-
7212
func MockCreateResponse(t *testing.T) {
7313
th.Mux.HandleFunc("/types", func(w http.ResponseWriter, r *http.Request) {
7414
th.TestMethod(t, r, "POST")
@@ -101,28 +41,3 @@ func MockCreateResponse(t *testing.T) {
10141
`)
10242
})
10343
}
104-
105-
func MockDeleteResponse(t *testing.T) {
106-
th.Mux.HandleFunc("/types/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
107-
th.TestMethod(t, r, "DELETE")
108-
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
109-
w.WriteHeader(http.StatusAccepted)
110-
})
111-
}
112-
113-
func MockUpdateResponse(t *testing.T) {
114-
th.Mux.HandleFunc("/types/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
115-
th.TestMethod(t, r, "PUT")
116-
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
117-
w.WriteHeader(http.StatusOK)
118-
fmt.Fprintf(w, `
119-
{
120-
"volume_type": {
121-
"name": "vol-type-002",
122-
"description": "volume type 0001",
123-
"is_public": true,
124-
"id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
125-
}
126-
}`)
127-
})
128-
}

openstack/blockstorage/v3/volumetypes/testing/requests_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,6 @@ import (
88
"github.com/gophercloud/gophercloud/testhelper/client"
99
)
1010

11-
func TestListAll(t *testing.T) {
12-
th.SetupHTTP()
13-
defer th.TeardownHTTP()
14-
15-
MockListResponse(t)
16-
17-
allPages, err := volumetypes.List(client.ServiceClient()).AllPages()
18-
th.AssertNoErr(t, err)
19-
actual, err := volumetypes.ExtractVolumeTypes(allPages)
20-
th.AssertNoErr(t, err)
21-
22-
expected := []volumetypes.VolumeType{
23-
{
24-
ID: "6685584b-1eac-4da6-b5c3-555430cf68ff",
25-
Name: "SSD",
26-
ExtraSpecs: map[string]string{"volume_backend_name": "lvmdriver-1"},
27-
IsPublic: true,
28-
Description: "",
29-
}, {
30-
ID: "8eb69a46-df97-4e41-9586-9a40a7533803",
31-
Name: "SATA",
32-
ExtraSpecs: map[string]string{"volume_backend_name": "lvmdriver-1"},
33-
IsPublic: true,
34-
Description: "",
35-
},
36-
}
37-
th.CheckDeepEquals(t, expected, actual)
38-
}
39-
40-
func TestGet(t *testing.T) {
41-
th.SetupHTTP()
42-
defer th.TeardownHTTP()
43-
44-
MockGetResponse(t)
45-
46-
v, err := volumetypes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
47-
th.AssertNoErr(t, err)
48-
49-
th.AssertEquals(t, v.Name, "vol-type-001")
50-
th.AssertEquals(t, v.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
51-
th.AssertEquals(t, v.ExtraSpecs["capabilities"], "gpu")
52-
}
53-
5411
func TestCreate(t *testing.T) {
5512
th.SetupHTTP()
5613
defer th.TeardownHTTP()
@@ -66,25 +23,3 @@ func TestCreate(t *testing.T) {
6623
th.AssertEquals(t, n.IsPublic, true)
6724
th.AssertEquals(t, n.ID, "6d0ff92a-0007-4780-9ece-acfe5876966a")
6825
}
69-
70-
func TestDelete(t *testing.T) {
71-
th.SetupHTTP()
72-
defer th.TeardownHTTP()
73-
74-
MockDeleteResponse(t)
75-
76-
res := volumetypes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
77-
th.AssertNoErr(t, res.Err)
78-
}
79-
80-
func TestUpdate(t *testing.T) {
81-
th.SetupHTTP()
82-
defer th.TeardownHTTP()
83-
84-
MockUpdateResponse(t)
85-
86-
options := volumetypes.UpdateOpts{Name: "vol-type-002"}
87-
v, err := volumetypes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
88-
th.AssertNoErr(t, err)
89-
th.CheckEquals(t, "vol-type-002", v.Name)
90-
}

openstack/blockstorage/v3/volumetypes/urls.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,3 @@ import "github.com/gophercloud/gophercloud"
55
func createURL(c *gophercloud.ServiceClient) string {
66
return c.ServiceURL("types")
77
}
8-
9-
func listURL(c *gophercloud.ServiceClient) string {
10-
return c.ServiceURL("types")
11-
}
12-
13-
func deleteURL(c *gophercloud.ServiceClient, id string) string {
14-
return c.ServiceURL("types", id)
15-
}
16-
17-
func getURL(c *gophercloud.ServiceClient, id string) string {
18-
return deleteURL(c, id)
19-
}
20-
21-
func updateURL(c *gophercloud.ServiceClient, id string) string {
22-
return deleteURL(c, id)
23-
}

0 commit comments

Comments
 (0)