// ControllerByName implements ControllersGetter.
429724
func (s *store) ControllerByName(name string) (*ControllerDetails, error) {
	if err := ValidateControllerName(name); err != nil {
		return nil, errors.Trace(err)
	}

	releaser, err := s.acquireLock()
	if err != nil {
		return nil, errors.Annotatef(err,
			"cannot acquire lock file to read controller %s", name,
		)
	}
	defer releaser.Release()

	controllers, err := ReadControllersFile(JujuControllersPath())
	if err != nil {
		return nil, errors.Trace(err)
	}
	if result, ok := controllers.Controllers[name]; ok {
		return &result, nil
	}
	return nil, errors.NotFoundf("controller %s", name)
}
251924
func (d *DataSource) GetByUsername(username string) (Model, bool) {
	return d.GetBy(func(u Model) bool {
		return u.Username == username
	})
}
721299
func (api *DatabaseAPI) SortByName(reverse bool) *DatabaseAPI {
	api.sortByName(reverse)
	return api
}
84645
func SourceByName(name string) (Source, error) {
	for s, n := range sourceNames {
		if n == name {
			return s, nil
		}
	}
	return -1, fmt.Errorf("unknown source %q", name)
}
1063864
func (u *DummyUser) MailboxByName(name string) (Mailbox, error) {
	for _, mailbox := range u.mailboxes {
		if mailbox.Name() == name {
			return mailbox, nil
		}
	}
	return nil, errors.New("Invalid mailbox")
}
905867
func (api *InternetAPI) SortByName(reverse bool) *InternetAPI {
	api.sortByName(reverse)
	return api
}
1238771
func (client *Client) GetRouterGroupByName(name string) (RouterGroup, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetRouterGroups,
		Query:       url.Values{"name": []string{name}},
	})

	if err != nil {
		return RouterGroup{}, err
	}
	var routerGroups []RouterGroup

	var response = Response{
		Result: &routerGroups,
	}

	err = client.connection.Make(request, &response)
	if err != nil {
		return RouterGroup{}, err
	}

	for _, routerGroup := range routerGroups {
		if routerGroup.Name == name {
			return routerGroup, nil
		}
	}

	return RouterGroup{}, routererror.ResourceNotFoundError{}
}
146692
func GetParameterByName(t *templatev1.Template, name string) *templatev1.Parameter {
	for i, param := range t.Parameters {
		if param.Name == name {
			return &(t.Parameters[i])
		}
	}
	return nil
}
1095059
func (um *UserMap) GetByName(name string) (User, error) {
	um.Lock()
	defer um.Unlock()

	for _, user := range um.Map {
		if user.Name == name {
			if user.Options == nil {
				user.Options = make(map[string]interface{})
			}
			return user, nil
		}
	}
	return User{Options: make(map[string]interface{})}, fmt.Errorf("could not find user with name %s", name)
}
470189
func (c *ControllerCommandBase) ControllerName() (string, error) {
	c.assertRunStarted()
	if err := c.initController(); err != nil {
		return "", errors.Trace(err)
	}
	return c._controllerName, nil
}
716205
func (m *Model) ControllerTag() names.ControllerTag {
	return names.NewControllerTag(m.doc.ControllerUUID)
}
142738
func (s *store) ControllerByAPIEndpoints(endpoints ...string) (*ControllerDetails, string, error) {
	releaser, err := s.acquireLock()
	if err != nil {
		return nil, "", errors.Annotatef(err, "cannot acquire lock file to read controllers")
	}
	defer releaser.Release()

	controllers, err := ReadControllersFile(JujuControllersPath())
	if err != nil {
		return nil, "", errors.Trace(err)
	}

	matchEps := set.NewStrings(endpoints...)
	for name, ctrl := range controllers.Controllers {
		if matchEps.Intersection(set.NewStrings(ctrl.APIEndpoints...)).IsEmpty() {
			continue
		}

		return &ctrl, name, nil
	}
	return nil, "", errors.NotFoundf("controller with API endpoints %v", endpoints)
}
129997
func (m *BaseMechanismManager) EnableByName(name string, c *MechanismContext) error {
	mechanism, ok := m.Mechanisms.Get(name)
	if !ok {
		return ErrMechanismNotRegistered
	}

	if mechanism.Enabled() {
		return nil
	}

	atomic.CompareAndSwapInt64(&m.enabled, 0, 1)
	mechanism.Enable(c)
	return nil
}
439056
func (s *RouterService) GetRouterByName(name string, opts ...OptionFunc) (*Router, int, error) {
	id, count, err := s.GetRouterID(name, opts...)
	if err != nil {
		return nil, count, err
	}

	r, count, err := s.GetRouterByID(id, opts...)
	if err != nil {
		return nil, count, err
	}
	return r, count, nil
}
541136
func (env *sessionEnviron) ControllerInstances(ctx context.ProviderCallContext, controllerUUID string) ([]instance.Id, error) {
	instances, err := env.AllInstances(ctx)
	if err != nil {
		return nil, errors.Trace(err)
	}

	var results []instance.Id
	for _, inst := range instances {
		vm := inst.(*environInstance).base
		metadata := vm.Config.ExtraConfig
		var isController bool
		for _, item := range metadata {
			value := item.GetOptionValue()
			if value.Key == tags.JujuIsController && value.Value == "true" {
				isController = true
				break
			}
		}
		if isController {
			results = append(results, inst.Id())
		}
	}
	if len(results) == 0 {
		return nil, environs.ErrNotBootstrapped
	}
	return results, nil
}
1352580
func (api *CrossControllerAPI) ControllerInfo() (params.ControllerAPIInfoResults, error) {
	results := params.ControllerAPIInfoResults{
		Results: make([]params.ControllerAPIInfoResult, 1),
	}
	addrs, caCert, err := api.localControllerInfo()
	if err != nil {
		results.Results[0].Error = common.ServerError(err)
		return results, nil
	}
	results.Results[0].Addresses = addrs
	results.Results[0].CACert = caCert
	return results, nil
}
1242286
func (scope *Scope) FieldByName(name string) (field *Field, ok bool) {
	var (
		dbName           = ToColumnName(name)
		mostMatchedField *Field
	)

	for _, field := range scope.Fields() {
		if field.Name == name || field.DBName == name {
			return field, true
		}
		if field.DBName == dbName {
			mostMatchedField = field
		}
	}
	return mostMatchedField, mostMatchedField != nil
}