github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/environs/open.go (about)

     1  // Copyright 2011, 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package environs
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  
     9  	"github.com/juju/juju/jujuclient"
    10  )
    11  
    12  // AdminUser is the initial admin user created for all controllers.
    13  const AdminUser = "admin"
    14  
    15  // New returns a new environment based on the provided configuration.
    16  func New(args OpenParams) (Environ, error) {
    17  	p, err := Provider(args.Cloud.Type)
    18  	if err != nil {
    19  		return nil, errors.Trace(err)
    20  	}
    21  	return p.Open(args)
    22  }
    23  
    24  // Destroy destroys the controller and, if successful,
    25  // its associated configuration data from the given store.
    26  func Destroy(
    27  	controllerName string,
    28  	env Environ,
    29  	store jujuclient.ControllerStore,
    30  ) error {
    31  	details, err := store.ControllerByName(controllerName)
    32  	if err != nil && !errors.IsNotFound(err) {
    33  		return errors.Trace(err)
    34  	}
    35  	if err := env.DestroyController(details.ControllerUUID); err != nil {
    36  		return errors.Trace(err)
    37  	}
    38  	err = store.RemoveController(controllerName)
    39  	if err != nil && !errors.IsNotFound(err) {
    40  		return errors.Trace(err)
    41  	}
    42  	return nil
    43  }