github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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  	"github.com/juju/errors"
     8  	"gopkg.in/juju/names.v2"
     9  
    10  	"github.com/juju/juju/api/base"
    11  	"github.com/juju/juju/apiserver/params"
    12  )
    13  
    14  // Life requests the life cycle of the given entity from the given
    15  // server-side API facade via the given caller.
    16  func Life(caller base.FacadeCaller, tag names.Tag) (params.Life, error) {
    17  	var result params.LifeResults
    18  	args := params.Entities{
    19  		Entities: []params.Entity{{Tag: tag.String()}},
    20  	}
    21  	if err := caller.FacadeCall("Life", args, &result); err != nil {
    22  		return "", err
    23  	}
    24  	if len(result.Results) != 1 {
    25  		return "", errors.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  }