예제 #1
0
파일: kill.go 프로젝트: snailwalker/juju
func (c *killCommand) getSystemAPI(info configstore.EnvironInfo) (destroySystemAPI, error) {
	if c.api != nil {
		return c.api, c.apierr
	}

	// Attempt to connect to the API with a short timeout
	apic := make(chan api.Connection)
	errc := make(chan error)
	go func() {
		api, dialErr := c.apiDialerFunc(c.systemName)
		if dialErr != nil {
			errc <- dialErr
			return
		}
		apic <- api
	}()

	var apiRoot api.Connection
	select {
	case err := <-errc:
		return nil, err
	case apiRoot = <-apic:
	case <-time.After(apiTimeout):
		return nil, ErrConnTimedOut
	}

	return systemmanager.NewClient(apiRoot), nil
}
예제 #2
0
// NewSystemManagerAPIClient returns an API client for the SystemManager on
// the current system using the current credentials.
func (c *SysCommandBase) NewSystemManagerAPIClient() (*systemmanager.Client, error) {
	root, err := c.newAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return systemmanager.NewClient(root), nil
}
예제 #3
0
파일: destroy.go 프로젝트: snailwalker/juju
func (c *destroyCommand) getSystemAPI() (destroySystemAPI, error) {
	if c.api != nil {
		return c.api, c.apierr
	}
	root, err := c.NewAPIRoot(c.systemName)
	if err != nil {
		return nil, errors.Trace(err)
	}

	return systemmanager.NewClient(root), nil
}
예제 #4
0
func (s *systemManagerSuite) OpenAPI(c *gc.C) *systemmanager.Client {
	conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
	c.Assert(err, jc.ErrorIsNil)
	s.AddCleanup(func(*gc.C) { conn.Close() })
	return systemmanager.NewClient(conn)
}