// MachineAgentFactoryFn returns a function which instantiates a
// MachineAgent given a machineId.
437677
func MachineAgentFactoryFn(
	agentConfWriter AgentConfigWriter,
	bufferedLogger *logsender.BufferedLogWriter,
	newIntrospectionSocketName func(names.Tag) string,
	preUpgradeSteps upgrades.PreUpgradeStepsFunc,
	rootDir string,
) machineAgentFactoryFnType {
	return func(machineId string, isCaasMachineAgent bool) (*MachineAgent, error) {
		return NewMachineAgent(
			machineId,
			agentConfWriter,
			bufferedLogger,
			worker.NewRunner(worker.RunnerParams{
				IsFatal:       cmdutil.IsFatal,
				MoreImportant: cmdutil.MoreImportant,
				RestartDelay:  jworker.RestartDelay,
			}),
			looputil.NewLoopDeviceManager(),
			newIntrospectionSocketName,
			preUpgradeSteps,
			rootDir,
			isCaasMachineAgent,
		)
	}
}
1369431
func (s *systemdServiceManager) FindAgents(dataDir string) (string, []string, []string, error) {
	var (
		machineAgent  string
		unitAgents    []string
		errAgentNames []string
	)

	agentDir := filepath.Join(dataDir, "agents")
	dir, err := os.Open(agentDir)
	if err != nil {
		return "", nil, nil, errors.Annotate(err, "opening agents dir")
	}
	defer dir.Close()

	entries, err := dir.Readdir(-1)
	if err != nil {
		return "", nil, nil, errors.Annotate(err, "reading agents dir")
	}
	for _, info := range entries {
		name := info.Name()
		tag, err := names.ParseTag(name)
		if err != nil {
			continue
		}
		switch tag.Kind() {
		case names.MachineTagKind:
			machineAgent = name
		case names.UnitTagKind:
			unitAgents = append(unitAgents, name)
		default:
			errAgentNames = append(errAgentNames, name)
			logger.Infof("%s is not of type Machine nor Unit, ignoring", name)
		}
	}
	return machineAgent, unitAgents, errAgentNames, nil
}
609984
func (ocf *outputConfigFlag) getFactory() outputFactory {
	if ocf.Selected == nil {
		return nil
	}

	if o, ok := ocf.Selected.(*outputOption); ok {
		return o.factory
	}
	return nil
}
392313
func NewIdentityProviderFactory(context servicecontext.ServiceContext) service.IdentityProviderFactory {
	factory := &identityProviderFactoryImpl{
		BaseService: base.NewBaseService(context),
	}
	return factory
}
1116268
func (dev *LinkLayerDevice) machineProxy(machineID string) *Machine {
	return &Machine{st: dev.st, doc: machineDoc{Id: machineID}}
}
261955
func getAgentToken(mgr *manager.Manager) (string, error) {
	u, err := mgr.Users.GetByEmail(manager.AgentEmail)
	if err != nil {
		return "", err
	}
	token, err := mgr.Tokens.GetOrCreate(u.Id)
	if err != nil {
		return "", err
	}
	return token.Hash, nil
}
1199234
func (c *UnitStateListCall) MachineID(machineID string) *UnitStateListCall {
	c.urlParams_.Set("machineID", machineID)
	return c
}
1064337
func (f FactoryFunc) New(next Policy, po *PolicyOptions) Policy {
	return f(next, po)
}
112316
func (s *SessionClient) MachineLogin(ctx context.Context, tokenID, tokenSecret string) error {

	ID, err := identity.DecodeFromString(tokenID)
	if err != nil {
		return err
	}

	secret, err := base64.NewFromString(tokenSecret)
	if err != nil {
		return err
	}

	login := apitypes.MachineLogin{
		TokenID: &ID,
		Secret:  secret,
	}

	rawLogin, err := json.Marshal(login)
	if err != nil {
		return err
	}
	return performLogin(ctx, s, "machine", rawLogin)
}
466805
func NewFactory(model interface{}) *Factory {
	fa := &Factory{}
	fa.model = model
	fa.nameIndexMap = make(map[string]int)

	fa.init()
	return fa
}
1266864
func NewNamedFactory(name string, errtext string) ErrorFactory {
	if _, ok := namedFactories[name]; ok {
		panic(fmt.Errorf("error factory name duplicated: %q", name))
	}
	factory := &errorFactory{
		errtext: errtext,
		name:    name,
	}
	namedFactories[name] = factory
	return factory
}
597746
func payloadFactory(t tasks.Task) payloadFn {
	rt := reflect.TypeOf(t).Elem()
	return func(id string) proto.Message {
		p := reflect.New(rt)
		p.Elem().FieldByName("Id").SetString(id)
		return p.Interface().(proto.Message)
	}
}
74108
func (m *API) GetMachineProviderInterfaceInfo(machines params.Entities) params.ProviderInterfaceInfoResults {
	results := make([]params.ProviderInterfaceInfoResult, len(machines.Entities))
	for i, entity := range machines.Entities {
		results[i].MachineTag = entity.Tag

		interfaces, err := m.getInterfaceInfoForOneMachine(entity.Tag)
		if err != nil {
			results[i].Error = common.ServerError(err)
			continue
		}

		infos := make([]params.ProviderInterfaceInfo, len(interfaces))
		for i, info := range interfaces {
			infos[i].InterfaceName = info.InterfaceName
			infos[i].MACAddress = info.MACAddress
			infos[i].ProviderId = string(info.ProviderId)
		}

		results[i].Interfaces = infos
	}
	return params.ProviderInterfaceInfoResults{results}
}
888466
func NewMachineAgentInfo(id, dataDir, logDir string) AgentInfo {
	return NewAgentInfo(AgentKindMachine, id, dataDir, logDir)
}
1349969
func Factory() (QFactory, error) {
	name, err := config.GetString("queue")
	if err != nil {
		name = "rabbitmq"
	}
	if f, ok := factories[name]; ok {
		return f, nil
	}
	return nil, fmt.Errorf("Queue %q is not known.", name)
}
324501
func (f Firewall) machineGroupName(machineId string) string {
	return fmt.Sprintf("juju-%s-%s", f.environ.Config().UUID(), machineId)
}
774402
func GetFactory(out io.Writer) func(context.Context) logging.Logger {
	lock := sync.Mutex{}
	return func(c context.Context) logging.Logger {
		return &jsonLogger{
			ctx:  c,
			lock: &lock,
			out:  out,
		}
	}
}