func createFilesystemDetails( st storageAccess, f state.Filesystem, attachments []state.FilesystemAttachment, ) (*params.FilesystemDetails, error) { details := ¶ms.FilesystemDetails{ FilesystemTag: f.FilesystemTag().String(), } if volumeTag, err := f.Volume(); err == nil { details.VolumeTag = volumeTag.String() } if info, err := f.Info(); err == nil { details.Info = storagecommon.FilesystemInfoFromState(info) } if len(attachments) > 0 { details.MachineAttachments = make(map[string]params.FilesystemAttachmentInfo, len(attachments)) for _, attachment := range attachments { stateInfo, err := attachment.Info() var info params.FilesystemAttachmentInfo if err == nil { info = storagecommon.FilesystemAttachmentInfoFromState(stateInfo) } details.MachineAttachments[attachment.Machine().String()] = info } } status, err := f.Status() if err != nil { return nil, errors.Trace(err) } details.Status = common.EntityStatusFromState(status) if storageTag, err := f.Storage(); err == nil { storageInstance, err := st.StorageInstance(storageTag) if err != nil { return nil, errors.Trace(err) } storageDetails, err := createStorageDetails(st, storageInstance) if err != nil { return nil, errors.Trace(err) } details.Storage = storageDetails } return details, nil }
// FilesystemFromState converts a state.Filesystem to params.Filesystem. func FilesystemFromState(f state.Filesystem) (params.Filesystem, error) { info, err := f.Info() if err != nil { return params.Filesystem{}, errors.Trace(err) } result := params.Filesystem{ f.FilesystemTag().String(), "", FilesystemInfoFromState(info), } volumeTag, err := f.Volume() if err == nil { result.VolumeTag = volumeTag.String() } else if err != state.ErrNoBackingVolume { return params.Filesystem{}, errors.Trace(err) } return result, nil }