本文整理汇总了Golang中github.com/juju/names.ParseFilesystemTag函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseFilesystemTag函数的具体用法?Golang ParseFilesystemTag怎么用?Golang ParseFilesystemTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseFilesystemTag函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Filesystems
// Filesystems returns details of filesystems with the specified tags.
func (s *StorageProvisionerAPI) Filesystems(args params.Entities) (params.FilesystemResults, error) {
canAccess, err := s.getStorageEntityAuthFunc()
if err != nil {
return params.FilesystemResults{}, common.ServerError(common.ErrPerm)
}
results := params.FilesystemResults{
Results: make([]params.FilesystemResult, len(args.Entities)),
}
one := func(arg params.Entity) (params.Filesystem, error) {
tag, err := names.ParseFilesystemTag(arg.Tag)
if err != nil || !canAccess(tag) {
return params.Filesystem{}, common.ErrPerm
}
filesystem, err := s.st.Filesystem(tag)
if errors.IsNotFound(err) {
return params.Filesystem{}, common.ErrPerm
} else if err != nil {
return params.Filesystem{}, err
}
return storagecommon.FilesystemFromState(filesystem)
}
for i, arg := range args.Entities {
var result params.FilesystemResult
filesystem, err := one(arg)
if err != nil {
result.Error = common.ServerError(err)
} else {
result.Result = filesystem
}
results.Results[i] = result
}
return results, nil
}
示例2: createFilesystemInfo
func createFilesystemInfo(result params.FilesystemDetailsResult) (names.FilesystemTag, FilesystemInfo, error) {
details := result.Result
filesystemTag, err := names.ParseFilesystemTag(details.FilesystemTag)
if err != nil {
return names.FilesystemTag{}, FilesystemInfo{}, errors.Trace(err)
}
var info FilesystemInfo
info.ProviderFilesystemId = details.Info.FilesystemId
info.Size = details.Info.Size
info.Status = EntityStatus{
details.Status.Status,
details.Status.Info,
// TODO(axw) we should support formatting as ISO time
common.FormatTime(details.Status.Since, false),
}
if details.VolumeTag != "" {
volumeId, err := idFromTag(details.VolumeTag)
if err != nil {
return names.FilesystemTag{}, FilesystemInfo{}, errors.Trace(err)
}
info.Volume = volumeId
}
if len(details.MachineAttachments) > 0 {
machineAttachments := make(map[string]MachineFilesystemAttachment)
for machineTag, attachment := range details.MachineAttachments {
machineId, err := idFromTag(machineTag)
if err != nil {
return names.FilesystemTag{}, FilesystemInfo{}, errors.Trace(err)
}
machineAttachments[machineId] = MachineFilesystemAttachment{
attachment.MountPoint,
attachment.ReadOnly,
}
}
info.Attachments = &FilesystemAttachments{
Machines: machineAttachments,
}
}
if details.Storage != nil {
storageTag, storageInfo, err := createStorageInfo(*details.Storage)
if err != nil {
return names.FilesystemTag{}, FilesystemInfo{}, errors.Trace(err)
}
info.Storage = storageTag.Id()
if storageInfo.Attachments != nil {
info.Attachments.Units = storageInfo.Attachments.Units
}
}
return filesystemTag, info, nil
}
示例3: FilesystemToState
// FilesystemToState converts a params.Filesystem to state.FilesystemInfo
// and names.FilesystemTag.
func FilesystemToState(v params.Filesystem) (names.FilesystemTag, state.FilesystemInfo, error) {
filesystemTag, err := names.ParseFilesystemTag(v.FilesystemTag)
if err != nil {
return names.FilesystemTag{}, state.FilesystemInfo{}, errors.Trace(err)
}
return filesystemTag, state.FilesystemInfo{
v.Info.Size,
"", // pool is set by state
v.Info.FilesystemId,
}, nil
}
示例4: FilesystemParams
// FilesystemParams returns the parameters for creating the filesystems
// with the specified tags.
func (s *StorageProvisionerAPI) FilesystemParams(args params.Entities) (params.FilesystemParamsResults, error) {
canAccess, err := s.getStorageEntityAuthFunc()
if err != nil {
return params.FilesystemParamsResults{}, err
}
envConfig, err := s.st.EnvironConfig()
if err != nil {
return params.FilesystemParamsResults{}, err
}
results := params.FilesystemParamsResults{
Results: make([]params.FilesystemParamsResult, len(args.Entities)),
}
poolManager := poolmanager.New(s.settings)
one := func(arg params.Entity) (params.FilesystemParams, error) {
tag, err := names.ParseFilesystemTag(arg.Tag)
if err != nil || !canAccess(tag) {
return params.FilesystemParams{}, common.ErrPerm
}
filesystem, err := s.st.Filesystem(tag)
if errors.IsNotFound(err) {
return params.FilesystemParams{}, common.ErrPerm
} else if err != nil {
return params.FilesystemParams{}, err
}
storageInstance, err := storagecommon.MaybeAssignedStorageInstance(
filesystem.Storage,
s.st.StorageInstance,
)
if err != nil {
return params.FilesystemParams{}, err
}
filesystemParams, err := storagecommon.FilesystemParams(
filesystem, storageInstance, envConfig, poolManager,
)
if err != nil {
return params.FilesystemParams{}, err
}
return filesystemParams, nil
}
for i, arg := range args.Entities {
var result params.FilesystemParamsResult
filesystemParams, err := one(arg)
if err != nil {
result.Error = common.ServerError(err)
} else {
result.Result = filesystemParams
}
results.Results[i] = result
}
return results, nil
}
示例5: FilesystemAttachmentToState
// FilesystemAttachmentToState converts a storage.FilesystemAttachment
// to a state.FilesystemAttachmentInfo.
func FilesystemAttachmentToState(in params.FilesystemAttachment) (names.MachineTag, names.FilesystemTag, state.FilesystemAttachmentInfo, error) {
machineTag, err := names.ParseMachineTag(in.MachineTag)
if err != nil {
return names.MachineTag{}, names.FilesystemTag{}, state.FilesystemAttachmentInfo{}, err
}
filesystemTag, err := names.ParseFilesystemTag(in.FilesystemTag)
if err != nil {
return names.MachineTag{}, names.FilesystemTag{}, state.FilesystemAttachmentInfo{}, err
}
info := state.FilesystemAttachmentInfo{
in.Info.MountPoint,
in.Info.ReadOnly,
}
return machineTag, filesystemTag, info, nil
}
示例6: filesystemAttachmentFromParams
func filesystemAttachmentFromParams(in params.FilesystemAttachment) (storage.FilesystemAttachment, error) {
filesystemTag, err := names.ParseFilesystemTag(in.FilesystemTag)
if err != nil {
return storage.FilesystemAttachment{}, errors.Trace(err)
}
machineTag, err := names.ParseMachineTag(in.MachineTag)
if err != nil {
return storage.FilesystemAttachment{}, errors.Trace(err)
}
return storage.FilesystemAttachment{
filesystemTag,
machineTag,
storage.FilesystemAttachmentInfo{
in.Info.MountPoint,
in.Info.ReadOnly,
},
}, nil
}
示例7: filesystemAttachmentParamsFromParams
func filesystemAttachmentParamsFromParams(in params.FilesystemAttachmentParams) (storage.FilesystemAttachmentParams, error) {
machineTag, err := names.ParseMachineTag(in.MachineTag)
if err != nil {
return storage.FilesystemAttachmentParams{}, errors.Trace(err)
}
filesystemTag, err := names.ParseFilesystemTag(in.FilesystemTag)
if err != nil {
return storage.FilesystemAttachmentParams{}, errors.Trace(err)
}
return storage.FilesystemAttachmentParams{
AttachmentParams: storage.AttachmentParams{
Provider: storage.ProviderType(in.Provider),
Machine: machineTag,
InstanceId: instance.Id(in.InstanceId),
ReadOnly: in.ReadOnly,
},
Filesystem: filesystemTag,
FilesystemId: in.FilesystemId,
Path: in.MountPoint,
}, nil
}
示例8: filesystemFromParams
func filesystemFromParams(in params.Filesystem) (storage.Filesystem, error) {
filesystemTag, err := names.ParseFilesystemTag(in.FilesystemTag)
if err != nil {
return storage.Filesystem{}, errors.Trace(err)
}
var volumeTag names.VolumeTag
if in.VolumeTag != "" {
volumeTag, err = names.ParseVolumeTag(in.VolumeTag)
if err != nil {
return storage.Filesystem{}, errors.Trace(err)
}
}
return storage.Filesystem{
filesystemTag,
volumeTag,
storage.FilesystemInfo{
in.Info.FilesystemId,
in.Info.Size,
},
}, nil
}
示例9: filesystemParamsFromParams
func filesystemParamsFromParams(in params.FilesystemParams) (storage.FilesystemParams, error) {
filesystemTag, err := names.ParseFilesystemTag(in.FilesystemTag)
if err != nil {
return storage.FilesystemParams{}, errors.Trace(err)
}
var volumeTag names.VolumeTag
if in.VolumeTag != "" {
volumeTag, err = names.ParseVolumeTag(in.VolumeTag)
if err != nil {
return storage.FilesystemParams{}, errors.Trace(err)
}
}
providerType := storage.ProviderType(in.Provider)
return storage.FilesystemParams{
filesystemTag,
volumeTag,
in.Size,
providerType,
in.Attributes,
in.Tags,
}, nil
}
示例10: oneFilesystemAttachment
func (s *StorageProvisionerAPI) oneFilesystemAttachment(
id params.MachineStorageId, canAccess func(names.MachineTag, names.Tag) bool,
) (state.FilesystemAttachment, error) {
machineTag, err := names.ParseMachineTag(id.MachineTag)
if err != nil {
return nil, err
}
filesystemTag, err := names.ParseFilesystemTag(id.AttachmentTag)
if err != nil {
return nil, err
}
if !canAccess(machineTag, filesystemTag) {
return nil, common.ErrPerm
}
filesystemAttachment, err := s.st.FilesystemAttachment(machineTag, filesystemTag)
if errors.IsNotFound(err) {
return nil, common.ErrPerm
} else if err != nil {
return nil, err
}
return filesystemAttachment, nil
}
示例11: assertParseFilesystemTagInvalid
func assertParseFilesystemTagInvalid(c *gc.C, tag string, expect error) {
_, err := names.ParseFilesystemTag(tag)
c.Assert(err, gc.ErrorMatches, expect.Error())
}
示例12: assertParseFilesystemTag
func assertParseFilesystemTag(c *gc.C, tag string, expect names.FilesystemTag) {
t, err := names.ParseFilesystemTag(tag)
c.Assert(err, gc.IsNil)
c.Assert(t, gc.Equals, expect)
}