Esempio n. 1
0
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
}
Esempio n. 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
}
Esempio n. 3
0
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
}
Esempio n. 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)
}