func (st *mockState) StorageAttachment( storageTag names.StorageTag, unitTag names.UnitTag, ) (params.StorageAttachment, error) { if unitTag != st.unit.tag { return params.StorageAttachment{}, ¶ms.Error{Code: params.CodeNotFound} } attachment, ok := st.storageAttachment[params.StorageAttachmentId{ UnitTag: unitTag.String(), StorageTag: storageTag.String(), }] if !ok { return params.StorageAttachment{}, ¶ms.Error{Code: params.CodeNotFound} } if attachment.Kind == params.StorageKindUnknown { return params.StorageAttachment{}, ¶ms.Error{Code: params.CodeNotProvisioned} } return attachment, nil }
// RemoveStorageAttachment removes the storage attachment with the // specified unit and storage tags from state. This method is only // expected to succeed if the storage attachment is Dead. func (sa *StorageAccessor) RemoveStorageAttachment(storageTag names.StorageTag, unitTag names.UnitTag) error { var results params.ErrorResults args := params.StorageAttachmentIds{ Ids: []params.StorageAttachmentId{{ StorageTag: storageTag.String(), UnitTag: unitTag.String(), }}, } err := sa.facade.FacadeCall("RemoveStorageAttachments", args, &results) if err != nil { return err } if len(results.Results) != 1 { return errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return result.Error } return nil }
// WatchStorageAttachments starts a watcher for changes to the info // of the storage attachment with the specified unit and storage tags. func (sa *StorageAccessor) WatchStorageAttachment(storageTag names.StorageTag, unitTag names.UnitTag) (watcher.NotifyWatcher, error) { var results params.NotifyWatchResults args := params.StorageAttachmentIds{ Ids: []params.StorageAttachmentId{{ StorageTag: storageTag.String(), UnitTag: unitTag.String(), }}, } err := sa.facade.FacadeCall("WatchStorageAttachments", args, &results) if err != nil { return nil, err } if len(results.Results) != 1 { return nil, errors.Errorf("expected 1 result, got %d", len(results.Results)) } result := results.Results[0] if result.Error != nil { return nil, result.Error } w := apiwatcher.NewNotifyWatcher(sa.facade.RawAPICaller(), result) return w, nil }
// StorageAttachment returns the storage attachment with the specified // unit and storage tags. func (sa *StorageAccessor) StorageAttachment(storageTag names.StorageTag, unitTag names.UnitTag) (params.StorageAttachment, error) { if sa.facade.BestAPIVersion() < 2 { return params.StorageAttachment{}, errors.NotImplementedf("StorageAttachment() (need V2+)") } args := params.StorageAttachmentIds{ Ids: []params.StorageAttachmentId{{ StorageTag: storageTag.String(), UnitTag: unitTag.String(), }}, } var results params.StorageAttachmentResults err := sa.facade.FacadeCall("StorageAttachments", args, &results) if err != nil { return params.StorageAttachment{}, errors.Trace(err) } if len(results.Results) != 1 { panic(errors.Errorf("expected 1 result, got %d", len(results.Results))) } result := results.Results[0] if result.Error != nil { return params.StorageAttachment{}, result.Error } return result.Result, nil }