// NewMachine returns a pointer to a Machine value
197701
func NewMachine(vb *VirtualBox, id string) *Machine {
	return &Machine{vb: vb, id: id}
}
279562
func createMachine(c context.Context, m *crimson.Machine) error {
	if err := validateMachineForCreation(m); err != nil {
		return err
	}

	db := database.Get(c)
	// By setting machines.platform_id and machines.rack_id NOT NULL when setting up the database, we can avoid checking if the given
	// platform and rack are valid. MySQL will turn up NULL for their column values which will be rejected as an error.
	_, err := db.ExecContext(c, `
		INSERT INTO machines (name, platform_id, rack_id, description, asset_tag, service_tag, deployment_ticket, drac_password, state)
		VALUES (?, (SELECT id FROM platforms WHERE name = ?), (SELECT id FROM racks WHERE name = ?), ?, ?, ?, ?, ?, ?)
	`, m.Name, m.Platform, m.Rack, m.Description, m.AssetTag, m.ServiceTag, m.DeploymentTicket, m.DracPassword, m.State)
	if err != nil {
		switch e, ok := err.(*mysql.MySQLError); {
		case !ok:
			// Type assertion failed.
		case e.Number == mysqlerr.ER_DUP_ENTRY:
			// e.g. "Error 1062: Duplicate entry 'machine-name' for key 'name'".
			// Name is the only required unique field (ID is required unique, but it's auto-incremented).
			return status.Errorf(codes.AlreadyExists, "duplicate machine %q", m.Name)
		case e.Number == mysqlerr.ER_BAD_NULL_ERROR && strings.Contains(e.Message, "'platform_id'"):
			// e.g. "Error 1048: Column 'platform_id' cannot be null".
			return status.Errorf(codes.NotFound, "platform %q does not exist", m.Platform)
		case e.Number == mysqlerr.ER_BAD_NULL_ERROR && strings.Contains(e.Message, "'rack_id'"):
			// e.g. "Error 1048: Column 'rack_id' cannot be null".
			return status.Errorf(codes.NotFound, "rack %q does not exist", m.Rack)
		}
		return errors.Annotate(err, "failed to create machine").Err()
	}
	return nil
}
742790
func (b *Blueprint) Machine() *Machine {
	fsm := &Machine{
		state:       b.start,
		transitions: b.transitions,
	}

	return fsm
}
898940
func NewModelMachinesWatcher(st state.ModelMachinesWatcher, resources facade.Resources, authorizer facade.Authorizer) *ModelMachinesWatcher {
	return &ModelMachinesWatcher{
		st:         st,
		resources:  resources,
		authorizer: authorizer,
	}
}
969417
func (c *Client) GetMachine(machineID string) (*Machine, error) {
	var resp Machine
	req := request{
		method: client.GET,
		url:    makeURL(apiMachines, machineID),
		resp:   &resp,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to get machine with id: %s", machineID)
	}
	return &resp, nil
}
376851
func (w *mutaterWorker) getMachine(tag names.MachineTag) (instancemutater.MutaterMachine, error) {
	m, err := w.facade.Machine(tag)
	return m, err
}
1038448
func (vb *VirtualBox) FindMachine(nameOrID string) (*Machine, error) {
	if err := vb.assertMobRef(); err != nil {
		return nil, err
	}

	request := findMachineRequest{VbID: vb.mobref, NameOrID: nameOrID}
	response := new(findMachineResponse)
	err := vb.send(request, response)
	if err != nil {
		return nil, err
	}

	m := &Machine{mobref: response.Returnval, vb: vb}
	return m, nil
}
976163
func (c *Conn) DescribeMachine(name string) (machineProps map[string]interface{}, err error) {
	var dbusProps map[string]dbus.Variant
	path, pathErr := c.GetMachine(name)
	if pathErr != nil {
		return nil, pathErr
	}
	obj := c.conn.Object("org.freedesktop.machine1", path)
	err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, "").Store(&dbusProps)
	if err != nil {
		return nil, err
	}
	machineProps = make(map[string]interface{}, len(dbusProps))
	for key, val := range dbusProps {
		machineProps[key] = val.Value()
	}
	return
}
349909
func (n *Netrc) RemoveMachine(name string) {
	for i, machine := range n.machines {
		if machine.Name == name {
			n.machines = append(n.machines[:i], n.machines[i+1:]...)
			// continue removing but start over since the indexes changed
			n.RemoveMachine(name)
			return
		}
	}
}
120822
func (m *MockUpgradeSeriesBackend) Machine(arg0 string) (common.UpgradeSeriesMachine, error) {
	ret := m.ctrl.Call(m, "Machine", arg0)
	ret0, _ := ret[0].(common.UpgradeSeriesMachine)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
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
}
498922
func (c *Controller) removeMachine(ch RemoveMachine) error {
	return errors.Trace(c.removeResident(ch.ModelUUID, func(m *Model) error { return m.removeMachine(ch) }))
}
1340968
func NewMachineManagerAPI(
	backend Backend,
	storageAccess storageInterface,
	pool Pool,
	auth facade.Authorizer,
	modelTag names.ModelTag,
	callCtx context.ProviderCallContext,
	resources facade.Resources,
) (*MachineManagerAPI, error) {
	if !auth.AuthClient() {
		return nil, common.ErrPerm
	}
	return &MachineManagerAPI{
		st:            backend,
		storageAccess: storageAccess,
		pool:          pool,
		authorizer:    auth,
		check:         common.NewBlockChecker(backend),
		modelTag:      modelTag,
		callContext:   callCtx,
		resources:     resources,
	}, nil
}
239313
func (st *State) insertNewMachineOps(mdoc *machineDoc, template MachineTemplate) (prereqOps []txn.Op, machineOp txn.Op, err error) {
	now := st.clock().Now()
	machineStatusDoc := statusDoc{
		Status:    status.Pending,
		ModelUUID: st.ModelUUID(),
		Updated:   now.UnixNano(),
	}
	instanceStatusDoc := statusDoc{
		Status:    status.Pending,
		ModelUUID: st.ModelUUID(),
		Updated:   now.UnixNano(),
	}
	modificationStatusDoc := statusDoc{
		Status:    status.Idle,
		ModelUUID: st.ModelUUID(),
		Updated:   now.UnixNano(),
	}

	prereqOps, machineOp = st.baseNewMachineOps(
		mdoc,
		machineStatusDoc,
		instanceStatusDoc,
		modificationStatusDoc,
		template.Constraints,
	)

	sb, err := NewStorageBackend(st)
	if err != nil {
		return nil, txn.Op{}, errors.Trace(err)
	}
	storageOps, volumeAttachments, filesystemAttachments, err := sb.hostStorageOps(
		mdoc.Id, &storageParams{
			filesystems:           template.Filesystems,
			filesystemAttachments: template.FilesystemAttachments,
			volumes:               template.Volumes,
			volumeAttachments:     template.VolumeAttachments,
		},
	)
	if err != nil {
		return nil, txn.Op{}, errors.Trace(err)
	}
	for _, a := range volumeAttachments {
		mdoc.Volumes = append(mdoc.Volumes, a.tag.Id())
	}
	for _, a := range filesystemAttachments {
		mdoc.Filesystems = append(mdoc.Filesystems, a.tag.Id())
	}
	prereqOps = append(prereqOps, storageOps...)

	// At the last moment we still have statusDoc in scope, set the initial
	// history entry. This is risky, and may lead to extra entries, but that's
	// an intrinsic problem with mixing txn and non-txn ops -- we can't sync
	// them cleanly.
	probablyUpdateStatusHistory(st.db(), machineGlobalKey(mdoc.Id), machineStatusDoc)
	probablyUpdateStatusHistory(st.db(), machineGlobalInstanceKey(mdoc.Id), instanceStatusDoc)
	probablyUpdateStatusHistory(st.db(), machineGlobalModificationKey(mdoc.Id), modificationStatusDoc)
	return prereqOps, machineOp, nil
}
320358
func (m *MockModelCache) Machine(arg0 string) (instancemutater.ModelCacheMachine, error) {
	ret := m.ctrl.Call(m, "Machine", arg0)
	ret0, _ := ret[0].(instancemutater.ModelCacheMachine)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
626283
func (n *Netrc) AddMachine(name, login, password string) {
	machine := n.Machine(name)
	if machine == nil {
		machine = &Machine{}
		n.machines = append(n.machines, machine)
	}
	machine.Name = name
	machine.tokens = []string{"machine ", name, "\n"}
	machine.Set("login", login)
	machine.Set("password", password)
}
383443
func (m *Model) updateMachine(ch MachineChange, rm *residentManager) {
	m.mu.Lock()

	machine, found := m.machines[ch.Id]
	if !found {
		machine = newMachine(m, rm.new())
		m.machines[ch.Id] = machine
		m.hub.Publish(m.topic(modelAddRemoveMachine), []string{ch.Id})
	}
	machine.setDetails(ch)

	m.mu.Unlock()
}