github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/machineactions/manifold.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Copyright 2016 Cloudbase Solutions SRL 3 // Licensed under the AGPLv3, see LICENCE file for details. 4 5 package machineactions 6 7 import ( 8 "github.com/juju/errors" 9 "gopkg.in/juju/names.v2" 10 "gopkg.in/juju/worker.v1" 11 "gopkg.in/juju/worker.v1/dependency" 12 13 "github.com/juju/juju/agent" 14 "github.com/juju/juju/api/base" 15 "github.com/juju/juju/cmd/jujud/agent/engine" 16 ) 17 18 // ManifoldConfig describes the dependencies of a machine action runner. 19 type ManifoldConfig struct { 20 AgentName string 21 APICallerName string 22 23 NewFacade func(base.APICaller) Facade 24 NewWorker func(WorkerConfig) (worker.Worker, error) 25 } 26 27 // start is used by engine.AgentAPIManifold to create a StartFunc. 28 func (config ManifoldConfig) start(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) { 29 machineTag, ok := a.CurrentConfig().Tag().(names.MachineTag) 30 if !ok { 31 return nil, errors.Errorf("this manifold can only be used inside a machine") 32 } 33 machineActionsFacade := config.NewFacade(apiCaller) 34 return config.NewWorker(WorkerConfig{ 35 Facade: machineActionsFacade, 36 MachineTag: machineTag, 37 HandleAction: HandleAction, 38 }) 39 } 40 41 // Manifold returns a dependency.Manifold as configured. 42 func Manifold(config ManifoldConfig) dependency.Manifold { 43 typedConfig := engine.AgentAPIManifoldConfig{ 44 AgentName: config.AgentName, 45 APICallerName: config.APICallerName, 46 } 47 return engine.AgentAPIManifold(typedConfig, config.start) 48 }