github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/state/api/common/life.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package common 5 6 import ( 7 "fmt" 8 9 "github.com/juju/juju/state/api/base" 10 "github.com/juju/juju/state/api/params" 11 ) 12 13 // Life requests the life cycle of the given entity from the given 14 // server-side API facade via the given caller. 15 func Life(caller base.Caller, facadeName, tag string) (params.Life, error) { 16 var result params.LifeResults 17 args := params.Entities{ 18 Entities: []params.Entity{{Tag: tag}}, 19 } 20 err := caller.Call(facadeName, "", "Life", args, &result) 21 if err != nil { 22 return "", err 23 } 24 if len(result.Results) != 1 { 25 return "", fmt.Errorf("expected 1 result, got %d", len(result.Results)) 26 } 27 if err := result.Results[0].Error; err != nil { 28 return "", err 29 } 30 return result.Results[0].Life, nil 31 }