github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/diskmanager/manifold.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package diskmanager 5 6 import ( 7 "github.com/juju/errors" 8 "gopkg.in/juju/names.v2" 9 10 "github.com/juju/juju/agent" 11 "github.com/juju/juju/api/base" 12 apidiskmanager "github.com/juju/juju/api/diskmanager" 13 "github.com/juju/juju/cmd/jujud/agent/engine" 14 "github.com/juju/juju/worker" 15 "github.com/juju/juju/worker/dependency" 16 ) 17 18 // ManifoldConfig defines the names of the manifolds on which a Manifold will depend. 19 type ManifoldConfig engine.AgentAPIManifoldConfig 20 21 // Manifold returns a dependency manifold that runs a diskmanager worker, 22 // using the resource names defined in the supplied config. 23 func Manifold(config ManifoldConfig) dependency.Manifold { 24 typedConfig := engine.AgentAPIManifoldConfig(config) 25 return engine.AgentAPIManifold(typedConfig, newWorker) 26 } 27 28 // newWorker trivially wraps NewWorker for use in a engine.AgentAPIManifold. 29 func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) { 30 t := a.CurrentConfig().Tag() 31 tag, ok := t.(names.MachineTag) 32 if !ok { 33 return nil, errors.Errorf("expected MachineTag, got %#v", t) 34 } 35 36 api := apidiskmanager.NewState(apiCaller, tag) 37 38 return NewWorker(DefaultListBlockDevices, api), nil 39 }