func (command *commandGet) Execute(resource *handler.Resource) { snapshotID := resource.Params.(*paramsGet).snapshotID snapshot, err := osSnapshots.Get(command.Ctx.ServiceClient, snapshotID).Extract() if err != nil { resource.Err = err return } resource.Result = snapshotSingle(snapshot) }
func (command *commandDelete) Execute(resource *handler.Resource) { snapshotID := resource.Params.(*paramsDelete).snapshotID err := osSnapshots.Delete(command.Ctx.ServiceClient, snapshotID).ExtractErr() if err != nil { resource.Err = err return } if resource.Params.(*paramsDelete).wait { i := 0 for i < 120 { _, err := osSnapshots.Get(command.Ctx.ServiceClient, snapshotID).Extract() if err != nil { break } time.Sleep(5 * time.Second) i++ } resource.Result = fmt.Sprintf("Deleted snapshot [%s]\n", snapshotID) } else { resource.Result = fmt.Sprintf("Deleting snapshot [%s]\n", snapshotID) } }
func (command *commandCreate) Execute(resource *handler.Resource) { opts := resource.Params.(*paramsCreate).opts snapshot, err := osSnapshots.Create(command.Ctx.ServiceClient, opts).Extract() if err != nil { resource.Err = err return } if resource.Params.(*paramsCreate).wait { err = osSnapshots.WaitForStatus(command.Ctx.ServiceClient, snapshot.ID, "available", 600) if err != nil { resource.Err = err return } snapshot, err = osSnapshots.Get(command.Ctx.ServiceClient, snapshot.ID).Extract() if err != nil { resource.Err = err return } } resource.Result = snapshotSingle(snapshot) }
// Get retrieves the Snapshot with the provided ID. To extract the Snapshot // object from the response, call the Extract method on the GetResult. func Get(client *gophercloud.ServiceClient, id string) GetResult { return GetResult{os.Get(client, id)} }