github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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/context" 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 implementations 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, callCtx context.ProviderCallContext, args environs.BootstrapParams) (*environs.BootstrapResult, error) { 23 result, err := Bootstrap(ctx, dp.Env, callCtx, 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(ctx context.ProviderCallContext) error { 32 if err := Destroy(dp.Env, ctx); err != nil { 33 return errors.Trace(err) 34 } 35 return nil 36 }