~axwalk/juju-core/gocryptossh-proxycommand

« back to all changes in this revision

Viewing changes to state/machine.go

  • Committer: Tim Penhey
  • Date: 2013-04-14 22:12:49 UTC
  • mto: (1142.2.6 string-set)
  • mto: This revision was merged to the branch mainline in revision 1152.
  • Revision ID: tim.penhey@canonical.com-20130414221249-tk8f6emctl1f8w63
Trivial rename of trivial -> utils.

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
                {