// DestroyController implements the Environ interface.
165848
func (e *environ) DestroyController(ctx context.ProviderCallContext, controllerUUID string) error {
	// In case any hosted environment hasn't been cleaned up yet,
	// we also attempt to delete their resources when the controller
	// environment is destroyed.
	if err := e.destroyControllerManagedEnvirons(ctx, controllerUUID); err != nil {
		return errors.Annotate(err, "destroying managed environs")
	}
	return e.Destroy(ctx)
}
703518
func (o *OracleEnviron) Destroy(ctx context.ProviderCallContext) error {
	return common.Destroy(o, ctx)
}
594542
func (env *environ) Destroy(ctx callcontext.ProviderCallContext) error {
	return env.withSession(ctx, func(env *sessionEnviron) error {
		return env.Destroy(ctx)
	})
}
143777
func (e *Environ) destroyControllerManagedEnvirons(ctx context.ProviderCallContext, controllerUUID string) error {
	// Terminate all instances managed by the controller.
	insts, err := e.allControllerManagedInstances(ctx, controllerUUID, false)
	if err != nil {
		return errors.Annotate(err, "listing instances")
	}
	instIds := make([]instance.Id, len(insts))
	for i, inst := range insts {
		instIds[i] = inst.Id()
	}
	if err := e.terminateInstances(ctx, instIds); err != nil {
		common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
		return errors.Annotate(err, "terminating instances")
	}

	// Delete all volumes managed by the controller.
	cinder, err := e.cinderProvider()
	if err == nil {
		volumes, err := controllerCinderVolumes(cinder.storageAdapter, controllerUUID)
		if err != nil {
			common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
			return errors.Annotate(err, "listing volumes")
		}
		volIds := volumeInfoToVolumeIds(cinderToJujuVolumeInfos(volumes))
		errs := foreachVolume(ctx, cinder.storageAdapter, volIds, destroyVolume)
		for i, err := range errs {
			if err == nil {
				continue
			}
			common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
			return errors.Annotatef(err, "destroying volume %q", volIds[i])
		}
	} else if !errors.IsNotSupported(err) {
		common.HandleCredentialError(IsAuthorisationFailure, err, ctx)
		return errors.Trace(err)
	}

	// Security groups for hosted models are destroyed by the
	// DeleteAllControllerGroups method call from Destroy().
	return nil
}
291808
func (opts *ReadOptions) Destroy() {
	C.rocksdb_readoptions_destroy(opts.c)
	opts.c = nil
}
476366
func (dp DefaultProvider) DestroyEnv(ctx context.ProviderCallContext) error {
	if err := Destroy(dp.Env, ctx); err != nil {
		return errors.Trace(err)
	}
	return nil
}
625939
func (c *MemStore) RemoveController(name string) error {
	c.mu.Lock()
	defer c.mu.Unlock()

	if err := ValidateControllerName(name); err != nil {
		return err
	}
	names := set.NewStrings(name)
	if namedControllerDetails, ok := c.Controllers[name]; ok {
		for name, details := range c.Controllers {
			if details.ControllerUUID == namedControllerDetails.ControllerUUID {
				names.Add(name)
				if name == c.CurrentControllerName {
					c.CurrentControllerName = ""
				}
			}
		}
	}
	for _, name := range names.Values() {
		delete(c.Models, name)
		delete(c.Accounts, name)
		delete(c.BootstrapConfig, name)
		delete(c.Controllers, name)
		delete(c.CookieJars, name)
	}
	return nil
}
1197212
func (opts *IngestExternalFileOptions) Destroy() {
	C.rocksdb_ingestexternalfileoptions_destroy(opts.c)
	opts.c = nil
}
1021999
func (m *MockZonedEnviron) Destroy(arg0 context.ProviderCallContext) error {
	ret := m.ctrl.Call(m, "Destroy", arg0)
	ret0, _ := ret[0].(error)
	return ret0
}
682181
func (m *RCControllerRefManager) ReleaseReplicationController(rc *v1.ReplicationController) error {
	klog.V(4).Infof("patching ReplicationController %s/%s to remove its controllerRef to %s/%s:%s",
		rc.Namespace, rc.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.Controller.GetName())
	deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.Controller.GetUID(), rc.UID)
	err := m.rcControl.PatchReplicationController(rc.Namespace, rc.Name, []byte(deleteOwnerRefPatch))
	if err != nil {
		if kerrors.IsNotFound(err) {
			// If the ReplicationController no longer exists, ignore it.
			return nil
		}
		if kerrors.IsInvalid(err) {
			// Invalid error will be returned in two cases: 1. the ReplicationController
			// has no owner reference, 2. the uid of the ReplicationController doesn't
			// match, which means the ReplicationController is deleted and then recreated.
			// In both cases, the error can be ignored.
			return nil
		}
	}
	return err
}
751726
func NewController(config ControllerConfig) (*Controller, error) {
	c, err := newController(config, newResidentManager(config.Changes))
	return c, errors.Trace(err)
}
210376
func (m *containerManager) DestroyContainer(id instance.Id) error {
	return errors.Trace(m.server.RemoveContainer(string(id)))
}
1271342
func (e *environ) destroyControllerManagedEnvirons(ctx context.ProviderCallContext, controllerUUID string) error {

	// Terminate all instances managed by the controller.
	instIds, err := e.allControllerManagedInstances(ctx, controllerUUID)
	if err != nil {
		return errors.Annotate(err, "listing instances")
	}
	if err := e.terminateInstances(ctx, instIds); err != nil {
		return errors.Annotate(err, "terminating instances")
	}

	// Delete all volumes managed by the controller. (No need to delete root disks manually.)
	volIds, err := e.allControllerManagedVolumes(ctx, controllerUUID, false)
	if err != nil {
		return errors.Annotate(err, "listing volumes")
	}
	errs := foreachVolume(e.ec2, ctx, volIds, destroyVolume)
	for i, err := range errs {
		if err == nil {
			continue
		}
		// (anastasiamac 2018-03-21) This is strange - we do try
		// to destroy all volumes but afterwards, if we have encountered any errors,
		// we will return first one...The same logic happens on detach..?...
		return errors.Annotatef(err, "destroying volume %q", volIds[i])
	}

	// Delete security groups managed by the controller.
	groups, err := e.controllerSecurityGroups(ctx, controllerUUID)
	if err != nil {
		return errors.Trace(err)
	}
	for _, g := range groups {
		if err := deleteSecurityGroupInsistently(e.ec2, ctx, g, clock.WallClock); err != nil {
			return errors.Annotatef(
				err, "cannot delete security group %q (%q)",
				g.Name, g.Id,
			)
		}
	}
	return nil
}
1349857
func (m *Manager) RemoveControllerAndWait(name string) error {
	oldCtrl, err := m.removeAndReturnController(name)
	if err == nil {
		<-oldCtrl.terminated
	}

	return err
}
1195401
func (m *Manager) Destroy(s *Session) error {
	return m.config.Store.Del(s.id, makeStoreOption(m, s))
}
809907
func (opts *FlushOptions) Destroy() {
	C.rocksdb_flushoptions_destroy(opts.c)
	opts.c = nil
}
316051
func (site *Site) Destroy() (*Response, error) {
	resp, err := site.client.Request("DELETE", site.apiPath(), nil, nil)
	if resp != nil && resp.Body != nil {
		resp.Body.Close()
	}
	return resp, err
}