blob: e9384e1d8ce1801208737d858290bbb98533c7d0 [file] [log] [blame]
Ash Wilsonb73b7f82014-08-29 15:38:06 -04001package services
2
3import (
4 "github.com/racker/perigee"
5 "github.com/rackspace/gophercloud"
6)
7
8// Create adds a new service of the requested type to the catalog.
9func Create(client *gophercloud.ServiceClient, serviceType string) (*ServiceResult, error) {
10 type request struct {
11 Type string `json:"type"`
12 }
13
14 type response struct {
15 Service ServiceResult `json:"service"`
16 }
17
18 req := request{Type: serviceType}
19 var resp response
20
21 _, err := perigee.Request("POST", getListURL(client), perigee.Options{
Ash Wilsona87ee062014-09-03 11:26:06 -040022 MoreHeaders: client.Provider.AuthenticatedHeaders(),
Ash Wilsonb73b7f82014-08-29 15:38:06 -040023 ReqBody: &req,
24 Results: &resp,
25 OkCodes: []int{201},
26 })
27 if err != nil {
28 return nil, err
29 }
30
31 return &resp.Service, nil
32}