~themue/juju-core/053-env-more-script-friendly

« back to all changes in this revision

Viewing changes to state/machine.go

Merge trunk and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
        "launchpad.net/juju-core/constraints"
8
8
        "launchpad.net/juju-core/state/api/params"
9
9
        "launchpad.net/juju-core/state/presence"
10
 
        "launchpad.net/juju-core/trivial"
 
10
        "launchpad.net/juju-core/utils"
11
11
        "time"
12
12
)
13
13
 
130
130
 
131
131
// SetAgentTools sets the tools that the agent is currently running.
132
132
func (m *Machine) SetAgentTools(t *Tools) (err error) {
133
 
        defer trivial.ErrorContextf(&err, "cannot set agent tools for machine %v", m)
 
133
        defer utils.ErrorContextf(&err, "cannot set agent tools for machine %v", m)
134
134
        if t.Series == "" || t.Arch == "" {
135
135
                return fmt.Errorf("empty series or arch")
136
136
        }
157
157
 
158
158
// SetPassword sets the password for the machine's agent.
159
159
func (m *Machine) SetPassword(password string) error {
160
 
        hp := trivial.PasswordHash(password)
 
160
        hp := utils.PasswordHash(password)
161
161
        ops := []txn.Op{{
162
162
                C:      m.st.machines.Name,
163
163
                Id:     m.doc.Id,
174
174
// PasswordValid returns whether the given password is valid
175
175
// for the given machine.
176
176
func (m *Machine) PasswordValid(password string) bool {
177
 
        return trivial.PasswordHash(password) == m.doc.PasswordHash
 
177
        return utils.PasswordHash(password) == m.doc.PasswordHash
178
178
}
179
179
 
180
180
// Destroy sets the machine lifecycle to Dying if it is Alive. It does
301
301
// Remove removes the machine from state. It will fail if the machine is not
302
302
// Dead.
303
303
func (m *Machine) Remove() (err error) {
304
 
        defer trivial.ErrorContextf(&err, "cannot remove machine %s", m.doc.Id)
 
304
        defer utils.ErrorContextf(&err, "cannot remove machine %s", m.doc.Id)
305
305
        if m.doc.Life != Dead {
306
306
                return fmt.Errorf("machine is not dead")
307
307
        }
344
344
 
345
345
// WaitAgentAlive blocks until the respective agent is alive.
346
346
func (m *Machine) WaitAgentAlive(timeout time.Duration) (err error) {
347
 
        defer trivial.ErrorContextf(&err, "waiting for agent of machine %v", m)
 
347
        defer utils.ErrorContextf(&err, "waiting for agent of machine %v", m)
348
348
        ch := make(chan presence.Change)
349
349
        m.st.pwatcher.Watch(m.globalKey(), ch)
350
350
        defer m.st.pwatcher.Unwatch(m.globalKey(), ch)
382
382
 
383
383
// Units returns all the units that have been assigned to the machine.
384
384
func (m *Machine) Units() (units []*Unit, err error) {
385
 
        defer trivial.ErrorContextf(&err, "cannot get units assigned to machine %v", m)
 
385
        defer utils.ErrorContextf(&err, "cannot get units assigned to machine %v", m)
386
386
        pudocs := []unitDoc{}
387
387
        err = m.st.units.Find(D{{"machineid", m.doc.Id}}).All(&pudocs)
388
388
        if err != nil {
405
405
// SetProvisioned sets the provider specific machine id and nonce for
406
406
// this machine. Once set, the instance id cannot be changed.
407
407
func (m *Machine) SetProvisioned(id InstanceId, nonce string) (err error) {
408
 
        defer trivial.ErrorContextf(&err, "cannot set instance id of machine %q", m)
 
408
        defer utils.ErrorContextf(&err, "cannot set instance id of machine %q", m)
409
409
 
410
410
        if id == "" || nonce == "" {
411
411
                return fmt.Errorf("instance id and nonce cannot be empty")
453
453
// instance for the machine. It will fail if the machine is Dead, or if it
454
454
// is already provisioned.
455
455
func (m *Machine) SetConstraints(cons constraints.Value) (err error) {
456
 
        defer trivial.ErrorContextf(&err, "cannot set constraints")
 
456
        defer utils.ErrorContextf(&err, "cannot set constraints")
457
457
        notProvisioned := D{{"instanceid", ""}}
458
458
        ops := []txn.Op{
459
459
                {
486
486
}
487
487
 
488
488
// Status returns the status of the machine.
489
 
func (m *Machine) Status() (status params.MachineStatus, info string, err error) {
 
489
func (m *Machine) Status() (status params.Status, info string, err error) {
490
490
        doc, err := getStatus(m.st, m.globalKey())
491
491
        if err != nil {
492
492
                return "", "", err
493
493
        }
494
 
        status = params.MachineStatus(doc.Status)
 
494
        status = doc.Status
495
495
        info = doc.StatusInfo
496
496
        return
497
497
}
498
498
 
499
499
// SetStatus sets the status of the machine.
500
 
func (m *Machine) SetStatus(status params.MachineStatus, info string) error {
501
 
        if status == params.MachineError && info == "" {
 
500
func (m *Machine) SetStatus(status params.Status, info string) error {
 
501
        if status == params.StatusError && info == "" {
502
502
                panic("machine error status with no info")
503
503
        }
504
 
        if status == params.MachinePending {
 
504
        if status == params.StatusPending {
505
505
                panic("machine status cannot be set to pending")
506
506
        }
507
507
        doc := statusDoc{
508
 
                Status:     string(status),
 
508
                Status:     status,
509
509
                StatusInfo: info,
510
510
        }
511
511
        ops := []txn.Op{{