1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package toolsversionchecker
9
"github.com/juju/errors"
11
"github.com/juju/juju/agent"
12
apiagent "github.com/juju/juju/api/agent"
13
"github.com/juju/juju/api/agenttools"
14
"github.com/juju/juju/api/base"
15
"github.com/juju/juju/cmd/jujud/agent/engine"
16
"github.com/juju/juju/state/multiwatcher"
17
"github.com/juju/juju/worker"
18
"github.com/juju/juju/worker/dependency"
19
"gopkg.in/juju/names.v2"
22
// ManifoldConfig defines the names of the manifolds on which a Manifold will depend.
23
type ManifoldConfig engine.AgentApiManifoldConfig
25
// Manifold returns a dependency manifold that runs a toolsversionchecker worker,
26
// using the api connection resource named in the supplied config.
27
func Manifold(config ManifoldConfig) dependency.Manifold {
28
typedConfig := engine.AgentApiManifoldConfig(config)
29
return engine.AgentApiManifold(typedConfig, newWorker)
32
func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
33
st := apiagent.NewState(apiCaller)
34
isMM, err := isModelManager(a, st)
36
return nil, errors.Trace(err)
39
return nil, dependency.ErrMissing
42
// 4 times a day seems a decent enough amount of checks.
43
checkerParams := VersionCheckerParams{
44
CheckInterval: time.Hour * 6,
46
return New(agenttools.NewFacade(apiCaller), &checkerParams), nil
49
func isModelManager(a agent.Agent, st *apiagent.State) (bool, error) {
50
cfg := a.CurrentConfig()
52
// Grab the tag and ensure that it's for a machine.
53
tag, ok := cfg.Tag().(names.MachineTag)
55
return false, errors.New("this manifold may only be used inside a machine agent")
58
entity, err := st.Entity(tag)
63
for _, job := range entity.Jobs() {
64
if job == multiwatcher.JobManageModel {