github.com/gophercloud/gophercloud@v1.11.0/openstack/orchestration/v1/stacktemplates/requests.go (about)

     1  package stacktemplates
     2  
     3  import "github.com/gophercloud/gophercloud"
     4  
     5  // Get retreives data for the given stack template.
     6  func Get(c *gophercloud.ServiceClient, stackName, stackID string) (r GetResult) {
     7  	resp, err := c.Get(getURL(c, stackName, stackID), &r.Body, nil)
     8  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
     9  	return
    10  }
    11  
    12  // ValidateOptsBuilder describes struct types that can be accepted by the Validate call.
    13  // The ValidateOpts struct in this package does.
    14  type ValidateOptsBuilder interface {
    15  	ToStackTemplateValidateMap() (map[string]interface{}, error)
    16  }
    17  
    18  // ValidateOpts specifies the template validation parameters.
    19  type ValidateOpts struct {
    20  	Template    string `json:"template" or:"TemplateURL"`
    21  	TemplateURL string `json:"template_url" or:"Template"`
    22  }
    23  
    24  // ToStackTemplateValidateMap assembles a request body based on the contents of a ValidateOpts.
    25  func (opts ValidateOpts) ToStackTemplateValidateMap() (map[string]interface{}, error) {
    26  	return gophercloud.BuildRequestBody(opts, "")
    27  }
    28  
    29  // Validate validates the given stack template.
    30  func Validate(c *gophercloud.ServiceClient, opts ValidateOptsBuilder) (r ValidateResult) {
    31  	b, err := opts.ToStackTemplateValidateMap()
    32  	if err != nil {
    33  		r.Err = err
    34  		return
    35  	}
    36  	resp, err := c.Post(validateURL(c), b, &r.Body, &gophercloud.RequestOpts{
    37  		OkCodes: []int{200},
    38  	})
    39  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    40  	return
    41  }