~rogpeppe/juju-core/256-more-status

« back to all changes in this revision

Viewing changes to state/statecmd/setconstraints.go

statecmd: don't use juju.Conn unnecessarily

There's an associated cost when the API uses juju.Conn,
so we want to avoid it when reasonable.
This change moves some operations from juju into
state because they don't require juju.Conn's associated
Environ.

R=fwereade, dimitern
CC=
https://codereview.appspot.com/7945044

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
package statecmd
4
4
 
5
5
import (
6
 
        "launchpad.net/juju-core/juju"
7
6
        "launchpad.net/juju-core/state"
8
7
        "launchpad.net/juju-core/state/api/params"
9
8
)
10
9
 
11
10
// SetServiceContstraints sets the constraints for a given service
12
11
func SetServiceConstraints(st *state.State, args params.SetServiceConstraints) error {
13
 
        conn, err := juju.NewConnFromState(st)
 
12
        svc, err := st.Service(args.ServiceName)
14
13
        if err != nil {
15
14
                return err
16
15
        }
17
 
        var svc *state.Service
18
 
        if svc, err = conn.State.Service(args.ServiceName); err != nil {
19
 
                return err
20
 
        }
21
16
        return svc.SetConstraints(args.Constraints)
22
17
}