func (a *API) convertStateVolumeToParams(st state.Volume) (params.VolumeInstance, error) { volume := params.VolumeInstance{VolumeTag: st.VolumeTag().String()} if storage, err := st.StorageInstance(); err == nil { volume.StorageTag = storage.String() storageInstance, err := a.storage.StorageInstance(storage) if err != nil { err = errors.Annotatef(err, "getting storage instance %v for volume %v", storage, volume.VolumeTag) return params.VolumeInstance{}, err } owner := storageInstance.Owner() // only interested in Unit for now if unitTag, ok := owner.(names.UnitTag); ok { volume.UnitTag = unitTag.String() } } if info, err := st.Info(); err == nil { volume.HardwareId = info.HardwareId volume.Size = info.Size volume.Persistent = info.Persistent volume.VolumeId = info.VolumeId } status, err := st.Status() if err != nil { return params.VolumeInstance{}, errors.Trace(err) } volume.Status = common.EntityStatusFromState(status) return volume, nil }
func (s mockVolumeListAPI) createTestVolume(id string, persistent bool, storageid, unitid string) params.VolumeInstance { tag := names.NewVolumeTag(id) result := params.VolumeInstance{ VolumeTag: tag.String(), VolumeId: "provider-supplied-" + tag.Id(), HardwareId: "serial blah blah", Persistent: persistent, Size: uint64(1024), } if storageid != "" { result.StorageTag = names.NewStorageTag(storageid).String() } if unitid != "" { result.UnitTag = names.NewUnitTag(unitid).String() } return result }