1package resourcetypes 2 3import ( 4 "github.com/gophercloud/gophercloud" 5) 6 7// ResourceTypeSummary contains the result of listing an available resource 8// type. 9type ResourceTypeSummary struct { 10 ResourceType string `json:"resource_type"` 11 Description string `json:"description"` 12} 13 14// PropertyType represents the expected type of a property or attribute value. 15type PropertyType string 16 17const ( 18 // StringProperty indicates a string property type. 19 StringProperty PropertyType = "string" 20 // IntegerProperty indicates an integer property type. 21 IntegerProperty PropertyType = "integer" 22 // NumberProperty indicates a number property type. It may be an integer or 23 // float. 24 NumberProperty PropertyType = "number" 25 // BooleanProperty indicates a boolean property type. 26 BooleanProperty PropertyType = "boolean" 27 // MapProperty indicates a map property type. 28 MapProperty PropertyType = "map" 29 // ListProperty indicates a list property type. 30 ListProperty PropertyType = "list" 31 // UntypedProperty indicates a property that could have any type. 32 UntypedProperty PropertyType = "any" 33) 34 35// AttributeSchema is the schema of a resource attribute 36type AttributeSchema struct { 37 Description string `json:"description,omitempty"` 38 Type PropertyType `json:"type"` 39} 40 41// MinMaxConstraint is a type of constraint with minimum and maximum values. 42// This is used for both Range and Length constraints. 43type MinMaxConstraint struct { 44 Min float64 `json:"min,omitempty"` 45 Max float64 `json:"max,omitempty"` 46} 47 48// ModuloConstraint constrains an integer to have a certain value given a 49// particular modulus. 50type ModuloConstraint struct { 51 Step int `json:"step,omitempty"` 52 Offset int `json:"offset,omitempty"` 53} 54 55// ConstraintSchema describes all possible types of constraints. Besides the 56// description, only one other field is ever set at a time. 57type ConstraintSchema struct { 58 Description string `json:"description,omitempty"` 59 Range *MinMaxConstraint `json:"range,omitempty"` 60 Length *MinMaxConstraint `json:"length,omitempty"` 61 Modulo *ModuloConstraint `json:"modulo,omitempty"` 62 AllowedValues *[]interface{} `json:"allowed_values,omitempty"` 63 AllowedPattern *string `json:"allowed_pattern,omitempty"` 64 CustomConstraint *string `json:"custom_constraint,omitempty"` 65} 66 67// PropertySchema is the schema of a resource property. 68type PropertySchema struct { 69 Type PropertyType `json:"type"` 70 Description string `json:"description,omitempty"` 71 Default interface{} `json:"default,omitempty"` 72 Constraints []ConstraintSchema `json:"constraints,omitempty"` 73 Required bool `json:"required"` 74 Immutable bool `json:"immutable"` 75 UpdateAllowed bool `json:"update_allowed"` 76 Schema map[string]PropertySchema `json:"schema,omitempty"` 77} 78 79// SupportStatusDetails contains information about the support status of the 80// resource and its history. 81type SupportStatusDetails struct { 82 Status SupportStatus `json:"status"` 83 Message string `json:"message,omitempty"` 84 Version string `json:"version,omitempty"` 85 PreviousStatus *SupportStatusDetails `json:"previous_status,omitempty"` 86} 87 88// ResourceSchema is the schema for a resource type, its attributes, and 89// properties. 90type ResourceSchema struct { 91 ResourceType string `json:"resource_type"` 92 SupportStatus SupportStatusDetails `json:"support_status"` 93 Attributes map[string]AttributeSchema `json:"attributes"` 94 Properties map[string]PropertySchema `json:"properties"` 95} 96 97// ListResult represents the result of a List operation. 98type ListResult struct { 99 gophercloud.Result 100} 101 102// Extract returns a slice of ResourceTypeSummary objects and is called after 103// a List operation. 104func (r ListResult) Extract() (rts []ResourceTypeSummary, err error) { 105 var full struct { 106 ResourceTypes []ResourceTypeSummary `json:"resource_types"` 107 } 108 err = r.ExtractInto(&full) 109 if err == nil { 110 rts = full.ResourceTypes 111 return 112 } 113 114 var basic struct { 115 ResourceTypes []string `json:"resource_types"` 116 } 117 err2 := r.ExtractInto(&basic) 118 if err2 == nil { 119 err = nil 120 rts = make([]ResourceTypeSummary, len(basic.ResourceTypes)) 121 for i, n := range basic.ResourceTypes { 122 rts[i] = ResourceTypeSummary{ResourceType: n} 123 } 124 } 125 return 126} 127 128// GetSchemaResult represents the result of a GetSchema operation. 129type GetSchemaResult struct { 130 gophercloud.Result 131} 132 133// Extract returns a ResourceSchema object and is called after a GetSchema 134// operation. 135func (r GetSchemaResult) Extract() (rts ResourceSchema, err error) { 136 err = r.ExtractInto(&rts) 137 return 138} 139 140// TemplateResult represents the result of a Template get operation. 141type TemplateResult struct { 142 gophercloud.Result 143} 144 145// Extract returns a Template object and is called after a Template get 146// operation. 147func (r TemplateResult) Extract() (template map[string]interface{}, err error) { 148 err = r.ExtractInto(&template) 149 return 150} 151