func (command *commandUpdate) Execute(resource *handler.Resource) { opts := resource.Params.(*paramsUpdate).opts volumeID := resource.Params.(*paramsUpdate).volumeID volume, err := osVolumes.Update(command.Ctx.ServiceClient, volumeID, opts).Extract() if err != nil { resource.Err = err return } resource.Result = volumeSingle(volume) }
func resourceBlockStorageVolumeV1Update(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) blockStorageClient, err := config.blockStorageV1Client(d.Get("region").(string)) if err != nil { return fmt.Errorf("Error creating OpenStack block storage client: %s", err) } updateOpts := volumes.UpdateOpts{ Name: d.Get("name").(string), Description: d.Get("description").(string), } if d.HasChange("metadata") { updateOpts.Metadata = resourceVolumeMetadataV1(d) } _, err = volumes.Update(blockStorageClient, d.Id(), updateOpts).Extract() if err != nil { return fmt.Errorf("Error updating OpenStack volume: %s", err) } return resourceBlockStorageVolumeV1Read(d, meta) }
func TestVolumes(t *testing.T) { client, err := newClient(t) th.AssertNoErr(t, err) cv, err := volumes.Create(client, &volumes.CreateOpts{ Size: 1, Name: "gophercloud-test-volume", }).Extract() th.AssertNoErr(t, err) defer func() { err = volumes.WaitForStatus(client, cv.ID, "available", 60) th.AssertNoErr(t, err) err = volumes.Delete(client, cv.ID).ExtractErr() th.AssertNoErr(t, err) }() _, err = volumes.Update(client, cv.ID, &volumes.UpdateOpts{ Name: "gophercloud-updated-volume", }).Extract() th.AssertNoErr(t, err) v, err := volumes.Get(client, cv.ID).Extract() th.AssertNoErr(t, err) t.Logf("Got volume: %+v\n", v) if v.Name != "gophercloud-updated-volume" { t.Errorf("Unable to update volume: Expected name: gophercloud-updated-volume\nActual name: %s", v.Name) } err = volumes.List(client, &volumes.ListOpts{Name: "gophercloud-updated-volume"}).EachPage(func(page pagination.Page) (bool, error) { vols, err := volumes.ExtractVolumes(page) th.CheckEquals(t, 1, len(vols)) return true, err }) th.AssertNoErr(t, err) }
// Update will update the Volume with provided information. To extract the updated // Volume from the response, call the Extract method on the UpdateResult. func Update(client *gophercloud.ServiceClient, id string, opts os.UpdateOptsBuilder) UpdateResult { return UpdateResult{os.Update(client, id, opts)} }