func createStorageDetails(st storageAccess, si state.StorageInstance) (*params.StorageDetails, error) { // Get information from underlying volume or filesystem. var persistent bool var statusEntity status.StatusGetter if si.Kind() != state.StorageKindBlock { // TODO(axw) when we support persistent filesystems, // e.g. CephFS, we'll need to do set "persistent" // here too. filesystem, err := st.StorageInstanceFilesystem(si.StorageTag()) if err != nil { return nil, errors.Trace(err) } statusEntity = filesystem } else { volume, err := st.StorageInstanceVolume(si.StorageTag()) if err != nil { return nil, errors.Trace(err) } if info, err := volume.Info(); err == nil { persistent = info.Persistent } statusEntity = volume } status, err := statusEntity.Status() if err != nil { return nil, errors.Trace(err) } // Get unit storage attachments. var storageAttachmentDetails map[string]params.StorageAttachmentDetails storageAttachments, err := st.StorageAttachments(si.StorageTag()) if err != nil { return nil, errors.Trace(err) } if len(storageAttachments) > 0 { storageAttachmentDetails = make(map[string]params.StorageAttachmentDetails) for _, a := range storageAttachments { machineTag, location, err := storageAttachmentInfo(st, a) if err != nil { return nil, errors.Trace(err) } details := params.StorageAttachmentDetails{ a.StorageInstance().String(), a.Unit().String(), machineTag.String(), location, } storageAttachmentDetails[a.Unit().String()] = details } } return ¶ms.StorageDetails{ StorageTag: si.Tag().String(), OwnerTag: si.Owner().String(), Kind: params.StorageKind(si.Kind()), Status: common.EntityStatusFromState(status), Persistent: persistent, Attachments: storageAttachmentDetails, }, nil }
func createParamsStorageInstance(si state.StorageInstance, persistent bool) params.StorageDetails { result := params.StorageDetails{ OwnerTag: si.Owner().String(), StorageTag: si.Tag().String(), Kind: params.StorageKind(si.Kind()), Status: "pending", Persistent: persistent, } return result }
func (s *StorageAPI) fromStateStorageAttachment(stateStorageAttachment state.StorageAttachment) (params.StorageAttachment, error) { machineTag, err := s.st.UnitAssignedMachine(stateStorageAttachment.Unit()) if err != nil { return params.StorageAttachment{}, err } info, err := common.StorageAttachmentInfo(s.st, stateStorageAttachment, machineTag) if err != nil { return params.StorageAttachment{}, err } stateStorageInstance, err := s.st.StorageInstance(stateStorageAttachment.StorageInstance()) if err != nil { return params.StorageAttachment{}, err } return params.StorageAttachment{ stateStorageAttachment.StorageInstance().String(), stateStorageInstance.Owner().String(), stateStorageAttachment.Unit().String(), params.StorageKind(stateStorageInstance.Kind()), info.Location, params.Life(stateStorageAttachment.Life().String()), }, nil }