RebuildCustomVolume wipes a custom volume and re-creates an empty one with the same configuration. It is only allowed when the volume has no snapshots and is not used by any running instance.
(projectName string, volName string, op *operations.Operation)
| 6020 | // RebuildCustomVolume wipes a custom volume and re-creates an empty one with the same configuration. |
| 6021 | // It is only allowed when the volume has no snapshots and is not used by any running instance. |
| 6022 | func (b *backend) RebuildCustomVolume(projectName string, volName string, op *operations.Operation) error { |
| 6023 | l := b.logger.AddContext(logger.Ctx{"project": projectName, "volName": volName}) |
| 6024 | l.Debug("RebuildCustomVolume started") |
| 6025 | defer l.Debug("RebuildCustomVolume finished") |
| 6026 | |
| 6027 | err := b.isStatusReady() |
| 6028 | if err != nil { |
| 6029 | return err |
| 6030 | } |
| 6031 | |
| 6032 | if internalInstance.IsSnapshot(volName) { |
| 6033 | return errors.New("Volume name cannot be a snapshot") |
| 6034 | } |
| 6035 | |
| 6036 | // Get the volume. |
| 6037 | curVol, err := VolumeDBGet(b, projectName, volName, drivers.VolumeTypeCustom) |
| 6038 | if err != nil { |
| 6039 | return err |
| 6040 | } |
| 6041 | |
| 6042 | // Check that the volume has no snapshots. |
| 6043 | snapshots, err := VolumeDBSnapshotsGet(b, projectName, volName, drivers.VolumeTypeCustom) |
| 6044 | if err != nil { |
| 6045 | return err |
| 6046 | } |
| 6047 | |
| 6048 | if len(snapshots) > 0 { |
| 6049 | return errors.New("Cannot rebuild custom volume with snapshots") |
| 6050 | } |
| 6051 | |
| 6052 | // Check that the volume isn't in use by running instances. |
| 6053 | err = VolumeUsedByInstanceDevices(b.state, b.Name(), projectName, &curVol.StorageVolume, true, func(dbInst db.InstanceArgs, project api.Project, usedByDevices []string) error { |
| 6054 | inst, err := instance.Load(b.state, dbInst, project) |
| 6055 | if err != nil { |
| 6056 | return err |
| 6057 | } |
| 6058 | |
| 6059 | if inst.IsRunning() { |
| 6060 | return errors.New("Cannot rebuild custom volume used by running instances") |
| 6061 | } |
| 6062 | |
| 6063 | return nil |
| 6064 | }) |
| 6065 | if err != nil { |
| 6066 | return err |
| 6067 | } |
| 6068 | |
| 6069 | // Get the content type. |
| 6070 | dbContentType, err := VolumeContentTypeNameToContentType(curVol.ContentType) |
| 6071 | if err != nil { |
| 6072 | return err |
| 6073 | } |
| 6074 | |
| 6075 | contentType, err := VolumeDBContentTypeToContentType(dbContentType) |
| 6076 | if err != nil { |
| 6077 | return err |
| 6078 | } |
| 6079 |
nothing calls this directly
no test coverage detected