Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1183)

Side by Side Diff: state/api/machiner/machiner.go

Issue 11463044: state/api/machiner: Cleanup tests and code (Closed)
Patch Set: Created 10 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « state/api/machiner/machine.go ('k') | state/api/machiner/machiner_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package machiner 4 package machiner
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 8
9 "launchpad.net/juju-core/state/api/common" 9 "launchpad.net/juju-core/state/api/common"
10 "launchpad.net/juju-core/state/api/params" 10 "launchpad.net/juju-core/state/api/params"
11 ) 11 )
12 12
13 // State provides access to the Machiner API facade. 13 // State provides access to the Machiner API facade.
14 type State struct { 14 type State struct {
15 caller common.Caller 15 caller common.Caller
16 } 16 }
17 17
18 // NewState creates a new client-side Machiner facade. 18 // NewState creates a new client-side Machiner facade.
19 func NewState(caller common.Caller) *State { 19 func NewState(caller common.Caller) *State {
20 return &State{caller} 20 return &State{caller}
21 } 21 }
22 22
23 // machineLife requests the lifecycle of the given machine from the server. 23 // machineLife requests the lifecycle of the given machine from the server.
24 func (s *State) machineLife(tag string) (params.Life, error) { 24 func (st *State) machineLife(tag string) (params.Life, error) {
25 var result params.LifeResults 25 var result params.LifeResults
26 args := params.Entities{ 26 args := params.Entities{
27 Entities: []params.Entity{{Tag: tag}}, 27 Entities: []params.Entity{{Tag: tag}},
28 } 28 }
29 » err := s.caller.Call("Machiner", "", "Life", args, &result) 29 » err := st.caller.Call("Machiner", "", "Life", args, &result)
30 if err != nil { 30 if err != nil {
31 return "", err 31 return "", err
32 } 32 }
33 if len(result.Results) != 1 { 33 if len(result.Results) != 1 {
34 return "", fmt.Errorf("expected one result, got %d", len(result. Results)) 34 return "", fmt.Errorf("expected one result, got %d", len(result. Results))
35 } 35 }
36 if err := result.Results[0].Error; err != nil { 36 if err := result.Results[0].Error; err != nil {
37 return "", err 37 return "", err
38 } 38 }
39 return result.Results[0].Life, nil 39 return result.Results[0].Life, nil
40 } 40 }
41 41
42 // Machine provides access to methods of a state.Machine through the facade. 42 // Machine provides access to methods of a state.Machine through the facade.
43 func (s *State) Machine(tag string) (*Machine, error) { 43 func (st *State) Machine(tag string) (*Machine, error) {
44 » life, err := s.machineLife(tag) 44 » life, err := st.machineLife(tag)
45 if err != nil { 45 if err != nil {
46 return nil, err 46 return nil, err
47 } 47 }
48 return &Machine{ 48 return &Machine{
49 » » tag: tag, 49 » » tag: tag,
50 » » life: life, 50 » » life: life,
51 » » mstate: s, 51 » » st: st,
52 }, nil 52 }, nil
53 } 53 }
OLDNEW
« no previous file with comments | « state/api/machiner/machine.go ('k') | state/api/machiner/machiner_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b