github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/common/provider.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package common 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/environs" 10 "github.com/juju/juju/environs/imagemetadata" 11 ) 12 13 // DefaultProvider exposes the various common implementations found in 14 // this package as methods of a single type. This facilitates treating 15 // the implentations as a bundle, e.g. satisfying interfaces. 16 type DefaultProvider struct { 17 // Env is the Juju environment that methods target. 18 Env environs.Environ 19 } 20 21 // BootstrapEnv bootstraps the Juju environment. 22 func (dp DefaultProvider) BootstrapEnv(ctx environs.BootstrapContext, args environs.BootstrapParams) (*environs.BootstrapResult, error) { 23 result, err := Bootstrap(ctx, dp.Env, args) 24 if err != nil { 25 return nil, errors.Trace(err) 26 } 27 return result, nil 28 } 29 30 // DestroyEnv destroys the Juju environment. 31 func (dp DefaultProvider) DestroyEnv() error { 32 if err := Destroy(dp.Env); err != nil { 33 return errors.Trace(err) 34 } 35 return nil 36 } 37 38 // SupportedArchitectures returns all the image architectures for env 39 // matching the constraints. 40 func (dp DefaultProvider) SupportedArchitectures(imageConstraint *imagemetadata.ImageConstraint) ([]string, error) { 41 arches, err := SupportedArchitectures(dp.Env, imageConstraint) 42 if err != nil { 43 return nil, errors.Trace(err) 44 } 45 return arches, nil 46 }