Fix api interfaces for orchestration resources
Some of the interfaces don't correspond well to the values
expected by the requests and returned by api.
diff --git a/openstack/orchestration/v1/stackresources/results.go b/openstack/orchestration/v1/stackresources/results.go
index df79d58..51c3c0c 100644
--- a/openstack/orchestration/v1/stackresources/results.go
+++ b/openstack/orchestration/v1/stackresources/results.go
@@ -1,6 +1,7 @@
package stackresources
import (
+ "encoding/json"
"fmt"
"reflect"
"time"
@@ -12,15 +13,18 @@
// Resource represents a stack resource.
type Resource struct {
- Links []gophercloud.Link `mapstructure:"links"`
- LogicalID string `mapstructure:"logical_resource_id"`
- Name string `mapstructure:"resource_name"`
- PhysicalID string `mapstructure:"physical_resource_id"`
- RequiredBy []interface{} `mapstructure:"required_by"`
- Status string `mapstructure:"resource_status"`
- StatusReason string `mapstructure:"resource_status_reason"`
- Type string `mapstructure:"resource_type"`
- UpdatedTime time.Time `mapstructure:"-"`
+ Attributes map[string]interface{} `mapstructure:"attributes"`
+ CreationTime time.Time `mapstructure:"-"`
+ Description string `mapstructure:"description"`
+ Links []gophercloud.Link `mapstructure:"links"`
+ LogicalID string `mapstructure:"logical_resource_id"`
+ Name string `mapstructure:"resource_name"`
+ PhysicalID string `mapstructure:"physical_resource_id"`
+ RequiredBy []interface{} `mapstructure:"required_by"`
+ Status string `mapstructure:"resource_status"`
+ StatusReason string `mapstructure:"resource_status_reason"`
+ Type string `mapstructure:"resource_type"`
+ UpdatedTime time.Time `mapstructure:"-"`
}
// FindResult represents the result of a Find operation.
@@ -54,6 +58,13 @@
}
res.Res[i].UpdatedTime = t
}
+ if date, ok := resource["creation_time"]; ok && date != nil {
+ t, err := time.Parse(gophercloud.STACK_TIME_FMT, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res.Res[i].CreationTime = t
+ }
}
return res.Res, nil
@@ -75,18 +86,6 @@
return len(resources) == 0, nil
}
-// LastMarker returns the last container name in a ListResult.
-func (r ResourcePage) LastMarker() (string, error) {
- resources, err := ExtractResources(r)
- if err != nil {
- return "", err
- }
- if len(resources) == 0 {
- return "", nil
- }
- return resources[len(resources)-1].PhysicalID, nil
-}
-
// ExtractResources interprets the results of a single page from a List() call, producing a slice of Resource entities.
func ExtractResources(page pagination.Page) ([]Resource, error) {
casted := page.(ResourcePage).Body
@@ -94,8 +93,9 @@
var response struct {
Resources []Resource `mapstructure:"resources"`
}
- err := mapstructure.Decode(casted, &response)
-
+ if err := mapstructure.Decode(casted, &response); err != nil {
+ return nil, err
+ }
var resources []interface{}
switch casted.(type) {
case map[string]interface{}:
@@ -115,9 +115,16 @@
}
response.Resources[i].UpdatedTime = t
}
+ if date, ok := resource["creation_time"]; ok && date != nil {
+ t, err := time.Parse(gophercloud.STACK_TIME_FMT, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ response.Resources[i].CreationTime = t
+ }
}
- return response.Resources, err
+ return response.Resources, nil
}
// GetResult represents the result of a Get operation.
@@ -149,6 +156,13 @@
}
res.Res.UpdatedTime = t
}
+ if date, ok := resource["creation_time"]; ok && date != nil {
+ t, err := time.Parse(gophercloud.STACK_TIME_FMT, date.(string))
+ if err != nil {
+ return nil, err
+ }
+ res.Res.CreationTime = t
+ }
return res.Res, nil
}
@@ -192,21 +206,42 @@
return len(rts) == 0, nil
}
+// resourceTypes represents the type that holds the result of ExtractResourceTypes.
+// We define methods on this type to sort it before output
+type resourceTypes []string
+
+func (r resourceTypes) Len() int {
+ return len(r)
+}
+
+func (r resourceTypes) Swap(i, j int) {
+ r[i], r[j] = r[j], r[i]
+}
+
+func (r resourceTypes) Less(i, j int) bool {
+ return r[i] < r[j]
+}
+
// ExtractResourceTypes extracts and returns resource types.
-func ExtractResourceTypes(page pagination.Page) ([]string, error) {
+func ExtractResourceTypes(page pagination.Page) (resourceTypes, error) {
+ casted := page.(ResourceTypePage).Body
+
var response struct {
- ResourceTypes []string `mapstructure:"resource_types"`
+ ResourceTypes resourceTypes `mapstructure:"resource_types"`
}
- err := mapstructure.Decode(page.(ResourceTypePage).Body, &response)
- return response.ResourceTypes, err
+ if err := mapstructure.Decode(casted, &response); err != nil {
+ return nil, err
+ }
+ return response.ResourceTypes, nil
}
// TypeSchema represents a stack resource schema.
type TypeSchema struct {
- Attributes map[string]interface{} `mapstructure:"attributes"`
- Properties map[string]interface{} `mapstrucutre:"properties"`
- ResourceType string `mapstructure:"resource_type"`
+ Attributes map[string]interface{} `mapstructure:"attributes"`
+ Properties map[string]interface{} `mapstrucutre:"properties"`
+ ResourceType string `mapstructure:"resource_type"`
+ SupportStatus map[string]interface{} `mapstructure:"support_status"`
}
// SchemaResult represents the result of a Schema operation.
@@ -230,31 +265,20 @@
return &res, nil
}
-// TypeTemplate represents a stack resource template.
-type TypeTemplate struct {
- HeatTemplateFormatVersion string
- Outputs map[string]interface{}
- Parameters map[string]interface{}
- Resources map[string]interface{}
-}
-
// TemplateResult represents the result of a Template operation.
type TemplateResult struct {
gophercloud.Result
}
-// Extract returns a pointer to a TypeTemplate object and is called after a
+// Extract returns the template and is called after a
// Template operation.
-func (r TemplateResult) Extract() (*TypeTemplate, error) {
+func (r TemplateResult) Extract() ([]byte, error) {
if r.Err != nil {
return nil, r.Err
}
-
- var res TypeTemplate
-
- if err := mapstructure.Decode(r.Body, &res); err != nil {
+ template, err := json.MarshalIndent(r.Body, "", " ")
+ if err != nil {
return nil, err
}
-
- return &res, nil
+ return template, nil
}