github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/api/deployer/unit.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package deployer 5 6 import ( 7 "gopkg.in/juju/names.v2" 8 9 "github.com/juju/juju/api/common" 10 "github.com/juju/juju/apiserver/params" 11 "github.com/juju/juju/status" 12 ) 13 14 // Unit represents a juju unit as seen by the deployer worker. 15 type Unit struct { 16 tag names.UnitTag 17 life params.Life 18 st *State 19 } 20 21 // Tag returns the unit's tag. 22 func (u *Unit) Tag() string { 23 return u.tag.String() 24 } 25 26 // Name returns the unit's name. 27 func (u *Unit) Name() string { 28 return u.tag.Id() 29 } 30 31 // Life returns the unit's lifecycle value. 32 func (u *Unit) Life() params.Life { 33 return u.life 34 } 35 36 // Refresh updates the cached local copy of the unit's data. 37 func (u *Unit) Refresh() error { 38 life, err := common.Life(u.st.facade, u.tag) 39 if err != nil { 40 return err 41 } 42 u.life = life 43 return nil 44 } 45 46 // Remove removes the unit from state, calling EnsureDead first, then Remove. 47 // It will fail if the unit is not present. 48 func (u *Unit) Remove() error { 49 var result params.ErrorResults 50 args := params.Entities{ 51 Entities: []params.Entity{{Tag: u.tag.String()}}, 52 } 53 err := u.st.facade.FacadeCall("Remove", args, &result) 54 if err != nil { 55 return err 56 } 57 return result.OneError() 58 } 59 60 // SetPassword sets the unit's password. 61 func (u *Unit) SetPassword(password string) error { 62 var result params.ErrorResults 63 args := params.EntityPasswords{ 64 Changes: []params.EntityPassword{ 65 {Tag: u.tag.String(), Password: password}, 66 }, 67 } 68 err := u.st.facade.FacadeCall("SetPasswords", args, &result) 69 if err != nil { 70 return err 71 } 72 return result.OneError() 73 } 74 75 // SetStatus sets the status of the unit. 76 func (u *Unit) SetStatus(unitStatus status.Status, info string, data map[string]interface{}) error { 77 var result params.ErrorResults 78 args := params.SetStatus{ 79 Entities: []params.EntityStatusArgs{ 80 {Tag: u.tag.String(), Status: unitStatus.String(), Info: info, Data: data}, 81 }, 82 } 83 err := u.st.facade.FacadeCall("SetStatus", args, &result) 84 if err != nil { 85 return err 86 } 87 return result.OneError() 88 }