Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 2571c77

Browse files
committed
allow rackspace flavor extra_specs
1 parent e83aa01 commit 2571c77

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

rackspace/compute/v2/flavors/delegate.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ func ListDetail(client *gophercloud.ServiceClient, opts os.ListOptsBuilder) pagi
3636
}
3737

3838
// Get returns details about a single flavor, identity by ID.
39-
func Get(client *gophercloud.ServiceClient, id string) os.GetResult {
40-
return os.Get(client, id)
39+
func Get(client *gophercloud.ServiceClient, id string) GetResult {
40+
var res GetResult
41+
_, res.Err = client.Get(getURL(client, id), &res.Body, nil)
42+
return res
4143
}
4244

4345
// ExtractFlavors interprets a page of List results as Flavors.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package flavors
2+
3+
import (
4+
"reflect"
5+
6+
"github.com/jrperritt/gophercloud"
7+
"github.com/mitchellh/mapstructure"
8+
)
9+
10+
// ExtraSpecs provide additional information about the flavor.
11+
type ExtraSpecs struct {
12+
// The number of data disks
13+
NumDataDisks uint `mapstructure:"number_of_data_disks"`
14+
// The flavor class
15+
Class string `mapstructure:"class"`
16+
// Relative measure of disk I/O performance from 0-99, where higher is faster
17+
DiskIOIndex uint `mapstructure:"disk_io_index"`
18+
PolicyClass string `mapstructure:"policy_class"`
19+
}
20+
21+
// Flavor records represent (virtual) hardware configurations for server resources in a region.
22+
type Flavor struct {
23+
// The Id field contains the flavor's unique identifier.
24+
// For example, this identifier will be useful when specifying which hardware configuration to use for a new server instance.
25+
ID string `mapstructure:"id"`
26+
27+
// The Disk and RA< fields provide a measure of storage space offered by the flavor, in GB and MB, respectively.
28+
Disk int `mapstructure:"disk"`
29+
RAM int `mapstructure:"ram"`
30+
31+
// The Name field provides a human-readable moniker for the flavor.
32+
Name string `mapstructure:"name"`
33+
34+
RxTxFactor float64 `mapstructure:"rxtx_factor"`
35+
36+
// Swap indicates how much space is reserved for swap.
37+
// If not provided, this field will be set to 0.
38+
Swap int `mapstructure:"swap"`
39+
40+
// VCPUs indicates how many (virtual) CPUs are available for this flavor.
41+
VCPUs int `mapstructure:"vcpus"`
42+
43+
// ExtraSpecs provides extra information about the flavor
44+
ExtraSpecs ExtraSpecs `mapstructure:"OS-FLV-WITH-EXT-SPECS:extra_specs"`
45+
}
46+
47+
// GetResult temporarily holds the response from a Get call.
48+
type GetResult struct {
49+
gophercloud.Result
50+
}
51+
52+
// Extract provides access to the individual Flavor returned by the Get function.
53+
func (gr GetResult) Extract() (*Flavor, error) {
54+
if gr.Err != nil {
55+
return nil, gr.Err
56+
}
57+
58+
var result struct {
59+
Flavor Flavor `mapstructure:"flavor"`
60+
}
61+
62+
cfg := &mapstructure.DecoderConfig{
63+
DecodeHook: defaulter,
64+
Result: &result,
65+
}
66+
decoder, err := mapstructure.NewDecoder(cfg)
67+
if err != nil {
68+
return nil, err
69+
}
70+
err = decoder.Decode(gr.Body)
71+
return &result.Flavor, err
72+
}
73+
74+
func defaulter(from, to reflect.Kind, v interface{}) (interface{}, error) {
75+
if (from == reflect.String) && (to == reflect.Int) {
76+
return 0, nil
77+
}
78+
return v, nil
79+
}

rackspace/compute/v2/flavors/urls.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package flavors
2+
3+
import (
4+
"github.com/rackspace/gophercloud"
5+
)
6+
7+
func getURL(client *gophercloud.ServiceClient, id string) string {
8+
return client.ServiceURL("flavors", id)
9+
}

0 commit comments

Comments
 (0)