// removeStorageInstancesOps returns the transaction operations to remove all
// storage instances owned by the specified entity.
323573
func removeStorageInstancesOps(im *storageBackend, owner names.Tag, force bool) ([]txn.Op, error) {
	coll, closer := im.mb.db().GetCollection(storageInstancesC)
	defer closer()

	var docs []storageInstanceDoc
	err := coll.Find(bson.D{{"owner", owner.String()}}).Select(bson.D{{"id", true}}).All(&docs)
	if err != nil {
		return nil, errors.Annotatef(err, "cannot get storage instances for %s", owner)
	}
	ops := make([]txn.Op, 0, len(docs))
	var removalErr error
	for _, doc := range docs {
		si := &storageInstance{im, doc}
		storageInstanceOps, err := removeStorageInstanceOps(si, nil, force)
		if err != nil {
			removalErr = errors.Trace(err)
			logger.Warningf("error determining operations for storage instance %v removal: %v", si.StorageTag().Id(), err)
		}
		ops = append(ops, storageInstanceOps...)
	}
	if !force && removalErr != nil {
		return nil, removalErr
	}
	return ops, nil
}
53192
func (env *maasEnviron) StopInstances(ctx context.ProviderCallContext, ids ...instance.Id) error {
	// Shortcut to exit quickly if 'instances' is an empty slice or nil.
	if len(ids) == 0 {
		return nil
	}

	if env.usingMAAS2() {
		err := env.releaseNodes2(ctx, ids, true)
		if err != nil {
			return errors.Trace(err)
		}
	} else {
		nodes := env.getMAASClient().GetSubObject("nodes")
		err := env.releaseNodes1(ctx, nodes, getSystemIdValues("nodes", ids), true)
		if err != nil {
			return errors.Trace(err)
		}
	}
	return common.RemoveStateInstances(env.Storage(), ids...)

}
11317
func (cache *HealthStatusCache) DeleteInstance(serviceID string, instanceID int) {
	cache.mu.Lock()
	defer cache.mu.Unlock()
	for key := range cache.data {
		if key.ServiceID == serviceID && key.InstanceID == instanceID {
			cache.delete(key)
		}
	}
}
1307408
func (ns nsRefcounts_) RemoveOp(coll mongo.Collection, key string, value int) (txn.Op, error) {
	refcount, err := ns.read(coll, key)
	if err != nil {
		return txn.Op{}, errors.Trace(err)
	}
	if refcount != value {
		logger.Tracef("reference of %s(%q) had %d refs, expected %d", coll.Name(), key, refcount, value)
		return txn.Op{}, errRefcountChanged
	}
	return ns.JustRemoveOp(coll.Name(), key, value), nil
}
1283085
func (ms *Module) ForgetResourceInstanceAll(addr addrs.ResourceInstance) {
	rs := ms.Resource(addr.Resource)
	if rs == nil {
		return
	}
	delete(rs.Instances, addr.Key)

	if rs.EachMode == NoEach && len(rs.Instances) == 0 {
		// Also clean up if we only expect to have one instance anyway
		// and there are none. We leave the resource behind if an each mode
		// is active because an empty list or map of instances is a valid state.
		delete(ms.Resources, addr.Resource.String())
	}
}
1293629
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
}
499379
func (v *InstancesView) RemoveClassAttribute(a Attribute) error {
	v.classAttrs[a] = false
	return nil
}
52114
func (c *gceCloudImplementation) DeleteInstance(i *cloudinstances.CloudInstanceGroupMember) error {
	return recreateCloudInstanceGroupMember(c, i)
}
1291524
func NewClearObjectStoreArgs(securityOrigin string, databaseName string, objectStoreName string) *ClearObjectStoreArgs {
	args := new(ClearObjectStoreArgs)
	args.SecurityOrigin = securityOrigin
	args.DatabaseName = databaseName
	args.ObjectStoreName = objectStoreName
	return args
}
922922
func (sto *Storage) removeOldest() bool {
	ctx := context.TODO()
	k, v := sto.lru.RemoveOldest()
	if v == nil {
		return false
	}
	sb := v.(blob.SizedRef)
	// TODO: run these without sto.mu held in background
	// goroutine? at least pass a context?
	err := sto.cache.RemoveBlobs(ctx, []blob.Ref{sb.Ref})
	if err != nil {
		log.Printf("proxycache: could not remove oldest blob %v (%d bytes): %v", sb.Ref, sb.Size, err)
		sto.lru.Add(k, v)
		return false
	}
	if sto.debug {
		log.Printf("proxycache: removed blob %v (%d bytes)", sb.Ref, sb.Size)
	}
	sto.cacheBytes -= int64(sb.Size)
	return true
}
971869
func DeleteInstance(svc Service, instance *cloudinstances.CloudInstanceGroupMember) error {
	glog.V(2).Infof("Detaching instance %q from Elastigroup", instance.ID)

	return svc.Detach(
		context.Background(),
		instance.CloudInstanceGroup.Raw.(Elastigroup).Id(),
		[]string{instance.ID})
}
688236
func (c *VSphereCloud) DeleteInstance(i *cloudinstances.CloudInstanceGroupMember) error {
	glog.V(8).Infof("vSphere cloud provider DeleteInstance not implemented yet")
	return fmt.Errorf("vSphere cloud provider does not support deleting cloud instances at this time.")
}
1192647
func (c *Client) DeleteImageStore(p *DeleteImageStoreParameter) (*Result, error) {
	obj, err := c.Request("deleteImageStore", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Result), err
}
707356
func validateRemoveOwnerStorageInstanceOps(si *storageInstance) ([]txn.Op, error) {
	var ops []txn.Op
	var charmMeta *charm.Meta
	owner := si.maybeOwner()
	switch owner.Kind() {
	case names.ApplicationTagKind:
		app, err := si.sb.application(owner.Id())
		if err != nil {
			return nil, errors.Trace(err)
		}
		if app.Life() != Alive {
			return nil, nil
		}
		ch, _, err := app.Charm()
		if err != nil {
			return nil, errors.Trace(err)
		}
		charmMeta = ch.Meta()
		ops = append(ops, txn.Op{
			C:  applicationsC,
			Id: app.Name(),
			Assert: bson.D{
				{"life", Alive},
				{"charmurl", ch.URL},
			},
		})
	case names.UnitTagKind:
		u, err := si.sb.unit(owner.Id())
		if err != nil {
			return nil, errors.Trace(err)
		}
		if u.Life() != Alive {
			return nil, nil
		}
		ch, err := u.charm()
		if err != nil {
			return nil, errors.Trace(err)
		}
		charmMeta = ch.Meta()
		ops = append(ops, txn.Op{
			C:      unitsC,
			Id:     u.doc.Name,
			Assert: bson.D{{"life", Alive}},
		})
		ops = append(ops, u.assertCharmOps(ch)...)
	default:
		return nil, errors.Errorf(
			"invalid storage owner %s",
			names.ReadableString(owner),
		)
	}
	_, currentCountOp, err := validateStorageCountChange(
		si.sb, owner, si.StorageName(), -1, charmMeta,
	)
	if err != nil {
		return nil, errors.Trace(err)
	}
	ops = append(ops, currentCountOp)
	return ops, nil
}
839890
func (sb *storageBackend) StorageInstanceFilesystem(tag names.StorageTag) (Filesystem, error) {
	f, err := sb.storageInstanceFilesystem(tag)
	return f, err
}
290641
func (r *Relation) removeLocalEndpointOps(ep Endpoint, departingUnitName string, op *ForcedOperation) ([]txn.Op, error) {
	var asserts bson.D
	hasRelation := bson.D{{"relationcount", bson.D{{"$gt", 0}}}}
	departingUnitApplicationMatchesEndpoint := func() bool {
		s, err := names.UnitApplication(departingUnitName)
		return err == nil && s == ep.ApplicationName
	}
	var cleanupOps []txn.Op
	if departingUnitName == "" {
		// We're constructing a destroy operation, either of the relation
		// or one of its applications, and can therefore be assured that both
		// applications are Alive.
		asserts = append(hasRelation, isAliveDoc...)
	} else if departingUnitApplicationMatchesEndpoint() {
		// This application must have at least one unit -- the one that's
		// departing the relation -- so it cannot be ready for removal.
		cannotDieYet := bson.D{{"unitcount", bson.D{{"$gt", 0}}}}
		asserts = append(hasRelation, cannotDieYet...)
	} else {
		// This application may require immediate removal.
		// Check if the application is Dying, and if so, queue up a potential
		// cleanup in case this was the last reference.
		applications, closer := r.st.db().GetCollection(applicationsC)
		defer closer()

		asserts = append(hasRelation)
		var appDoc applicationDoc
		if err := applications.FindId(ep.ApplicationName).One(&appDoc); err == nil {
			if appDoc.Life != Alive {
				cleanupOps = append(cleanupOps, newCleanupOp(
					cleanupApplication,
					ep.ApplicationName,
					false, // destroyStorage
					op.Force,
				))
			}
		} else if !op.Force {
			return nil, errors.Trace(err)
		}
	}
	return append([]txn.Op{{
		C:      applicationsC,
		Id:     r.st.docID(ep.ApplicationName),
		Assert: asserts,
		Update: bson.D{{"$inc", bson.D{{"relationcount", -1}}}},
	}}, cleanupOps...), nil
}
714503
func (s *storage) RemoveAccess(token string) error {
	// TODO: return no error if registry returns IsNotFound
	return s.accesstoken.Delete(token, nil)
}