Example #1
0
func (s *connSuite) TestConnect(c *gc.C) {
	google.SetRawConn(s.Conn, nil)
	service := &compute.Service{}
	s.PatchValue(google.NewRawConnection, func(auth *google.Credentials) (*compute.Service, error) {
		return service, nil
	})

	conn, err := google.Connect(s.ConnCfg, s.Credentials)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(google.ExposeRawService(conn), gc.Equals, service)
}
Example #2
0
	uuid  string
	cloud environs.CloudSpec
	gce   gceConnection

	lock sync.Mutex // lock protects access to ecfg
	ecfg *environConfig

	// namespace is used to create the machine and device hostnames.
	namespace instance.Namespace
}

// Function entry points defined as variables so they can be overridden
// for testing purposes.
var (
	newConnection = func(conn google.ConnectionConfig, creds *google.Credentials) (gceConnection, error) {
		return google.Connect(conn, creds)
	}
	destroyEnv = common.Destroy
	bootstrap  = common.Bootstrap
)

func newEnviron(cloud environs.CloudSpec, cfg *config.Config) (*environ, error) {
	ecfg, err := newConfig(cfg, nil)
	if err != nil {
		return nil, errors.Annotate(err, "invalid config")
	}

	credAttrs := cloud.Credential.Attributes()
	if cloud.Credential.AuthType() == jujucloud.JSONFileAuthType {
		contents := credAttrs[credAttrFile]
		credential, err := parseJSONAuthFile(strings.NewReader(contents))
Example #3
0
	defer env.lock.Unlock()

	if env.ecfg == nil {
		return errors.New("cannot set config on uninitialized env")
	}

	if err := env.ecfg.update(cfg); err != nil {
		return errors.Annotate(err, "invalid config change")
	}
	return nil
}

var newConnection = func(ecfg *environConfig) (gceConnection, error) {
	connCfg := ecfg.newConnection()
	auth := ecfg.auth()
	return google.Connect(connCfg, auth)
}

// Config returns the configuration data with which the env was created.
func (env *environ) Config() *config.Config {
	env.lock.Lock()
	cfg := env.ecfg.Config
	env.lock.Unlock()
	return cfg
}

var bootstrap = common.Bootstrap

// Bootstrap creates a new instance, chosing the series and arch out of
// available tools. The series and arch are returned along with a func
// that must be called to finalize the bootstrap process by transferring