// machineStatusHistory returns status history for the given machine.
6268
func (c *Client) machineStatusHistory(machineTag names.MachineTag, filter status.StatusHistoryFilter, kind status.HistoryKind) ([]params.DetailedStatus, error) {
	machine, err := c.api.stateAccessor.Machine(machineTag.Id())
	if err != nil {
		return nil, errors.Trace(err)
	}
	var sInfo []status.StatusInfo
	if kind == status.KindMachineInstance || kind == status.KindContainerInstance {
		sInfo, err = machine.InstanceStatusHistory(filter)
	} else {
		sInfo, err = machine.StatusHistory(filter)
	}
	if err != nil {
		return nil, errors.Trace(err)
	}
	return agentStatusFromStatusInfo(sInfo, kind), nil
}
915920
func (st stateShim) AllMachines() ([]Machine, error) {
	machines, err := st.State.AllMachines()
	if err != nil {
		return nil, errors.Trace(err)
	}
	result := make([]Machine, len(machines))
	for i, m := range machines {
		result[i] = m
	}
	return result, nil
}
1222765
func (api *API) CheckMachines(args params.ModelArgs) (params.ErrorResults, error) {
	tag, err := names.ParseModelTag(args.ModelTag)
	if err != nil {
		return params.ErrorResults{}, errors.Trace(err)
	}
	st, err := api.pool.Get(tag.Id())
	if err != nil {
		return params.ErrorResults{}, errors.Trace(err)
	}
	defer st.Release()

	return credentialcommon.ValidateExistingModelCredential(
		credentialcommon.NewPersistentBackend(st.State),
		api.callContext,
	)
}
155826
func (a *AAgent) AllMachineStates() (states []MachineState, err error) {
	states = []MachineState{}

	a.Lock()
	defer a.Unlock()

	for _, m := range a.machines {
		state := MachineState{
			Name:                 m.machine.Name(),
			Version:              m.machine.Version(),
			Path:                 m.machine.Directory(),
			ID:                   m.machine.InstanceID(),
			State:                m.machine.State(),
			StartTimeUTC:         m.machine.StartTime().Unix(),
			AvailableTransitions: m.machine.AvailableTransitions(),
		}

		states = append(states, state)
	}

	return states, nil
}
805039
func (st *State) AllMachineRemovals() ([]string, error) {
	removals, close := st.db().GetCollection(machineRemovalsC)
	defer close()

	var docs []machineRemovalDoc
	err := removals.Find(nil).All(&docs)
	if err != nil {
		return nil, errors.Trace(err)
	}
	results := make([]string, len(docs))
	for i := range docs {
		results[i] = docs[i].MachineID
	}
	return results, nil
}
914125
func (st *State) cleanupDyingMachine(machineId string, cleanupArgs []bson.Raw) error {
	var force bool
	switch n := len(cleanupArgs); n {
	case 0:
		// Old cleanups have no args, so follow the old behaviour.
	case 1:
		if err := cleanupArgs[0].Unmarshal(&force); err != nil {
			return errors.Annotate(err, "unmarshalling cleanup arg 'force'")
		}
	default:
		return errors.Errorf("expected 0-1 arguments, got %d", n)
	}
	machine, err := st.Machine(machineId)
	if errors.IsNotFound(err) {
		return nil
	} else if err != nil {
		return err
	}
	return cleanupDyingMachineResources(machine, force)
}
1335024
func (p *terminalPrompter) SetHistory(history []string) {
	p.State.ReadHistory(strings.NewReader(strings.Join(history, "\n")))
}
1334101
func (s *Client) MachineStatus() (model.UpgradeSeriesStatus, error) {
	var results params.UpgradeSeriesStatusResults
	args := params.Entities{
		Entities: []params.Entity{{Tag: s.authTag.String()}},
	}

	err := s.facade.FacadeCall("MachineStatus", args, &results)
	if err != nil {
		return "", errors.Trace(err)
	}
	if len(results.Results) != 1 {
		return "", errors.Errorf("expected 1 result, got %d", len(results.Results))
	}

	r := results.Results[0]
	if r.Error == nil {
		return r.Status, nil
	}

	if params.IsCodeNotFound(r.Error) {
		return "", errors.NewNotFound(r.Error, "")
	}
	return "", errors.Trace(r.Error)
}
875620
func (c *Client) CheckMachines(modelUUID string) ([]error, error) {
	var result params.ErrorResults
	args := params.ModelArgs{names.NewModelTag(modelUUID).String()}
	err := c.caller.FacadeCall("CheckMachines", args, &result)
	if err != nil {
		return nil, errors.Trace(err)
	}
	var results []error
	for _, res := range result.Results {
		results = append(results, errors.Errorf(res.Error.Message))
	}
	return results, nil
}
534629
func (m *CoreOSMachine) Refresh() {
	m.RLock()
	defer m.RUnlock()

	cs := m.currentState()
	if cs == nil {
		log.Warning("Unable to refresh machine state")
	} else {
		m.dynamicState = cs
	}
}
908715
func (c *statusContext) processMachine(machine *state.Machine) (out params.DetailedStatus) {
	wrapped := &contextMachine{machine, c}
	statusInfo, err := c.presence.MachineStatus(wrapped)
	populateStatusFromStatusInfoAndErr(&out, statusInfo, err)

	out.Life = processLife(machine)

	if t, err := machine.AgentTools(); err == nil {
		out.Version = t.Version.Number.String()
	}
	return
}
1370048
func (m *MockFacade) MachineStatus() (model.UpgradeSeriesStatus, error) {
	ret := m.ctrl.Call(m, "MachineStatus")
	ret0, _ := ret[0].(model.UpgradeSeriesStatus)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
909341
func (c *CloudAPI) StopMachine(machineID string) error {
	if err := c.ProcessFunctionHook(c, machineID); err != nil {
		return err
	}

	for _, machine := range c.machines {
		if machine.Id == machineID {
			machine.State = "stopped"
			machine.Updated = time.Now().Format("2013-11-26T19:47:13.448Z")
			return nil
		}
	}

	return fmt.Errorf("Machine %s not found", machineID)
}
382168
func (st *State) MachinesWithTransientErrors() ([]MachineStatusResult, error) {
	var results params.StatusResults
	err := st.facade.FacadeCall("MachinesWithTransientErrors", nil, &results)
	if err != nil {
		return []MachineStatusResult{}, err
	}
	machines := make([]MachineStatusResult, len(results.Results))
	for i, status := range results.Results {
		if status.Error != nil {
			continue
		}
		machines[i].Machine = &Machine{
			tag:  names.NewMachineTag(status.Id),
			life: status.Life,
			st:   st,
		}
		machines[i].Status = status
	}
	return machines, nil
}
168194
func (m *Manager) CountSMSHistorySince(phonenumber string, since time.Time) (int, error) {
	return m.collection.Find(bson.M{"createdat": bson.M{"$gte": since}}).Count()
}
733508
func GetHostStatus(api libmachine.API) (string, error) {
	exists, err := api.Exists(cfg.GetMachineName())
	if err != nil {
		return "", errors.Wrapf(err, "%s exists", cfg.GetMachineName())
	}
	if !exists {
		return state.None.String(), nil
	}

	host, err := api.Load(cfg.GetMachineName())
	if err != nil {
		return "", errors.Wrapf(err, "load")
	}

	s, err := host.Driver.GetState()
	if err != nil {
		return "", errors.Wrap(err, "state")
	}
	return s.String(), nil
}
296823
func (st *State) machineLife(tag names.MachineTag) (params.Life, error) {
	return common.OneLife(st.facade, tag)
}