github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/css/v1/snapshots/Create.go (about) 1 package snapshots 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 6 ) 7 8 // CreateOpts contains options for creating a snapshot. 9 // This object is passed to the snapshots.Create function. 10 type CreateOpts struct { 11 Name string `json:"name" required:"true"` 12 Description string `json:"description,omitempty"` 13 Indices string `json:"indices,omitempty"` 14 } 15 16 // Create will create a new snapshot based on the values in CreateOpts. 17 // To extract the result from the response, call the Extract method on the CreateResult. 18 func Create(client *golangsdk.ServiceClient, opts CreateOpts, clusterId string) (*Snapshot, error) { 19 b, err := golangsdk.BuildRequestBody(opts, "") 20 if err != nil { 21 return nil, err 22 } 23 24 raw, err := client.Post(client.ServiceURL("clusters", clusterId, "index_snapshot"), b, nil, nil) 25 if err != nil { 26 return nil, err 27 } 28 29 var res Snapshot 30 err = extract.IntoStructPtr(raw.Body, &res, "backup") 31 return &res, err 32 }