github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/worker/upgrader/error.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package upgrader 5 6 import ( 7 agenttools "launchpad.net/juju-core/agent/tools" 8 "launchpad.net/juju-core/version" 9 ) 10 11 // UpgradeReadyError is returned by an Upgrader to report that 12 // an upgrade is ready to be performed and a restart is due. 13 type UpgradeReadyError struct { 14 AgentName string 15 OldTools version.Binary 16 NewTools version.Binary 17 DataDir string 18 } 19 20 func (e *UpgradeReadyError) Error() string { 21 return "must restart: an agent upgrade is available" 22 } 23 24 // ChangeAgentTools does the actual agent upgrade. 25 // It should be called just before an agent exits, so that 26 // it will restart running the new tools. 27 func (e *UpgradeReadyError) ChangeAgentTools() error { 28 tools, err := agenttools.ChangeAgentTools(e.DataDir, e.AgentName, e.NewTools) 29 if err != nil { 30 return err 31 } 32 logger.Infof("upgraded from %v to %v (%q)", e.OldTools, tools.Version, tools.URL) 33 return nil 34 }