本文整理匯總了Golang中github.com/juju/juju/apiserver/params.VolumeFilter.IsEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Golang VolumeFilter.IsEmpty方法的具體用法?Golang VolumeFilter.IsEmpty怎麽用?Golang VolumeFilter.IsEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/apiserver/params.VolumeFilter
的用法示例。
在下文中一共展示了VolumeFilter.IsEmpty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ListVolumes
func (a *API) ListVolumes(filter params.VolumeFilter) (params.VolumeItemsResult, error) {
if !filter.IsEmpty() {
return params.VolumeItemsResult{Results: a.filterVolumes(filter)}, nil
}
volumes, err := a.listVolumeAttachments()
if err != nil {
return params.VolumeItemsResult{}, common.ServerError(err)
}
return params.VolumeItemsResult{Results: volumes}, nil
}
示例2: filterVolumes
func filterVolumes(
st storageAccess,
f params.VolumeFilter,
) ([]state.Volume, map[names.VolumeTag][]state.VolumeAttachment, error) {
if f.IsEmpty() {
// No filter was specified: get all volumes, and all attachments.
volumes, err := st.AllVolumes()
if err != nil {
return nil, nil, errors.Trace(err)
}
volumeAttachments := make(map[names.VolumeTag][]state.VolumeAttachment)
for _, v := range volumes {
attachments, err := st.VolumeAttachments(v.VolumeTag())
if err != nil {
return nil, nil, errors.Trace(err)
}
volumeAttachments[v.VolumeTag()] = attachments
}
return volumes, volumeAttachments, nil
}
volumesByTag := make(map[names.VolumeTag]state.Volume)
volumeAttachments := make(map[names.VolumeTag][]state.VolumeAttachment)
for _, machine := range f.Machines {
machineTag, err := names.ParseMachineTag(machine)
if err != nil {
return nil, nil, errors.Trace(err)
}
attachments, err := st.MachineVolumeAttachments(machineTag)
if err != nil {
return nil, nil, errors.Trace(err)
}
for _, attachment := range attachments {
volumeTag := attachment.Volume()
volumesByTag[volumeTag] = nil
volumeAttachments[volumeTag] = append(volumeAttachments[volumeTag], attachment)
}
}
for volumeTag := range volumesByTag {
volume, err := st.Volume(volumeTag)
if err != nil {
return nil, nil, errors.Trace(err)
}
volumesByTag[volumeTag] = volume
}
volumes := make([]state.Volume, 0, len(volumesByTag))
for _, volume := range volumesByTag {
volumes = append(volumes, volume)
}
return volumes, volumeAttachments, nil
}