Ejemplo n.º 1
0
func opClientServiceDestroy(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	err := service.NewClient(st).Destroy("non-existent")
	if params.IsCodeNotFound(err) {
		err = nil
	}
	return func() {}, err
}
Ejemplo n.º 2
0
func (c *upgradeCharmCommand) newServiceAPIClient() (*apiservice.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return apiservice.NewClient(root), nil
}
Ejemplo n.º 3
0
func opClientDestroyRelation(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	err := service.NewClient(st).DestroyRelation("nosuch1", "nosuch2")
	if params.IsCodeNotFound(err) {
		err = nil
	}
	return func() {}, err
}
Ejemplo n.º 4
0
Archivo: deploy.go Proyecto: makyo/juju
func (d *serviceDeployer) newServiceAPIClient() (*apiservice.Client, error) {
	root, err := d.api.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return apiservice.NewClient(root), nil
}
Ejemplo n.º 5
0
func opClientDestroyServiceUnits(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	err := service.NewClient(st).DestroyUnits("wordpress/99")
	if err != nil && strings.HasPrefix(err.Error(), "no units were destroyed") {
		err = nil
	}
	return func() {}, err
}
Ejemplo n.º 6
0
func (c *removeRelationCommand) getAPI() (serviceDestroyRelationAPI, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return apiservice.NewClient(root), nil
}
Ejemplo n.º 7
0
func (c *setPlanCommand) requestMetricCredentials() ([]byte, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	jclient := service.NewClient(root)
	envUUID := jclient.ModelUUID()
	charmURL, err := jclient.GetCharmURL(c.Service)
	if err != nil {
		return nil, errors.Trace(err)
	}

	hc, err := c.NewClient()
	if err != nil {
		return nil, errors.Trace(err)
	}
	client, err := newAuthorizationClient(api.HTTPClient(hc))
	if err != nil {
		return nil, errors.Trace(err)
	}
	m, err := client.Authorize(envUUID, charmURL.String(), c.Service, c.Plan, httpbakery.OpenWebBrowser)
	if err != nil {
		return nil, errors.Trace(err)
	}
	ms := macaroon.Slice{m}
	return json.Marshal(ms)
}
Ejemplo n.º 8
0
func (s *getSuite) TestGetMaxResolutionInt(c *gc.C) {
	// See the bug http://pad.lv/1217742
	// Get ends up pushing a map[string]interface{} which containts
	// an int64 through a JSON Marshal & Unmarshal which ends up changing
	// the int64 into a float64. We will fix it if we find it is actually a
	// problem.
	const nonFloatInt = (int64(1) << 54) + 1
	const asFloat = float64(nonFloatInt)
	c.Assert(int64(asFloat), gc.Not(gc.Equals), nonFloatInt)
	c.Assert(int64(asFloat)+1, gc.Equals, nonFloatInt)

	ch := s.AddTestingCharm(c, "dummy")
	svc := s.AddTestingService(c, "test-service", ch)

	err := svc.UpdateConfigSettings(map[string]interface{}{"skill-level": nonFloatInt})
	c.Assert(err, jc.ErrorIsNil)
	client := apiservice.NewClient(s.APIState)
	got, err := client.Get(svc.Name())
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(got.Config["skill-level"], jc.DeepEquals, map[string]interface{}{
		"description": "A number indicating skill.",
		"type":        "int",
		"value":       asFloat,
	})
}
Ejemplo n.º 9
0
func opClientAddServiceUnits(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	_, err := service.NewClient(st).AddUnits("nosuch", 1, nil)
	if params.IsCodeNotFound(err) {
		err = nil
	}
	return func() {}, err
}
Ejemplo n.º 10
0
func (c *debugHooksCommand) getServiceAPI() (charmRelationsApi, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return service.NewClient(root), nil
}
Ejemplo n.º 11
0
func opClientServiceSetCharm(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	err := service.NewClient(st).ServiceSetCharm("nosuch", "local:quantal/wordpress", false, false)
	if params.IsCodeNotFound(err) {
		err = nil
	}
	return func() {}, err
}
Ejemplo n.º 12
0
func opClientServiceUnexpose(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	err := service.NewClient(st).Unexpose("wordpress")
	if err != nil {
		return func() {}, err
	}
	return func() {}, nil
}
Ejemplo n.º 13
0
func (c *removeServiceCommand) getAPI() (ServiceRemoveAPI, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return apiservice.NewClient(root), nil
}
Ejemplo n.º 14
0
func (s *getSuite) TestServiceGet(c *gc.C) {
	for i, t := range getTests {
		c.Logf("test %d. %s", i, t.about)
		ch := s.AddTestingCharm(c, t.charm)
		svc := s.AddTestingService(c, fmt.Sprintf("test%d", i), ch)

		var constraintsv constraints.Value
		if t.constraints != "" {
			constraintsv = constraints.MustParse(t.constraints)
			err := svc.SetConstraints(constraintsv)
			c.Assert(err, jc.ErrorIsNil)
		}
		if t.config != nil {
			err := svc.UpdateConfigSettings(t.config)
			c.Assert(err, jc.ErrorIsNil)
		}
		expect := t.expect
		expect.Constraints = constraintsv
		expect.Service = svc.Name()
		expect.Charm = ch.Meta().Name
		client := apiservice.NewClient(s.APIState)
		got, err := client.Get(svc.Name())
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(*got, gc.DeepEquals, expect)
	}
}
Ejemplo n.º 15
0
func (c *exposeCommand) getAPI() (serviceExposeAPI, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return service.NewClient(root), nil
}
Ejemplo n.º 16
0
func opClientSetServiceConstraints(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	nullConstraints := constraints.Value{}
	err := service.NewClient(st).SetConstraints("wordpress", nullConstraints)
	if err != nil {
		return func() {}, err
	}
	return func() {}, nil
}
Ejemplo n.º 17
0
func resetBlogTitle(c *gc.C, st api.Connection) func() {
	return func() {
		err := service.NewClient(st).Set("wordpress", map[string]string{
			"blog-title": "",
		})
		c.Assert(err, jc.ErrorIsNil)
	}
}
Ejemplo n.º 18
0
func opClientServiceSet(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	err := service.NewClient(st).Set("wordpress", map[string]string{
		"blog-title": "foo",
	})
	if err != nil {
		return func() {}, err
	}
	return resetBlogTitle(c, st), nil
}
Ejemplo n.º 19
0
func (c *serviceConstraintsCommand) getAPI() (serviceConstraintsAPI, error) {
	if c.api != nil {
		return c.api, nil
	}
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return service.NewClient(root), nil
}
Ejemplo n.º 20
0
Archivo: get.go Proyecto: exekias/juju
func (c *getCommand) getAPI() (getServiceAPI, error) {
	if c.api != nil {
		return c.api, nil
	}
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return service.NewClient(root), nil
}
Ejemplo n.º 21
0
func opClientServiceExpose(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	err := service.NewClient(st).Expose("wordpress")
	if err != nil {
		return func() {}, err
	}
	return func() {
		svc, err := mst.Service("wordpress")
		c.Assert(err, jc.ErrorIsNil)
		svc.ClearExposed()
	}, nil
}
Ejemplo n.º 22
0
func opClientServiceSetCharm(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	cfg := service.SetCharmConfig{
		ServiceName: "nosuch",
		CharmID: charmstore.CharmID{
			URL: charm.MustParseURL("local:quantal/wordpress"),
		},
	}
	err := service.NewClient(st).SetCharm(cfg)
	if params.IsCodeNotFound(err) {
		err = nil
	}
	return func() {}, err
}
Ejemplo n.º 23
0
func opClientServiceUpdate(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	args := params.ServiceUpdate{
		ServiceName:     "no-such-charm",
		CharmUrl:        "cs:quantal/wordpress-42",
		ForceCharmUrl:   true,
		SettingsStrings: map[string]string{"blog-title": "foo"},
		SettingsYAML:    `"wordpress": {"blog-title": "foo"}`,
	}
	err := service.NewClient(st).ServiceUpdate(args)
	if params.IsCodeNotFound(err) {
		err = nil
	}
	return func() {}, err
}
Ejemplo n.º 24
0
// Run implements cmd.Command.
func (c *setPlanCommand) Run(ctx *cmd.Context) error {
	credentials, err := c.requestMetricCredentials()
	if err != nil {
		return errors.Trace(err)
	}

	root, err := c.NewAPIRoot()
	if err != nil {
		return errors.Trace(err)
	}
	api := service.NewClient(root)

	err = api.SetMetricCredentials(c.Service, credentials)
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}
Ejemplo n.º 25
0
// SetMetricCredentials sets the credentials on the service.
func (s *metricsCredentialsAPIImpl) SetMetricCredentials(serviceName string, data []byte) error {
	return s.api.SetMetricCredentials(serviceName, data)
}

// Close closes the api connection
func (s *metricsCredentialsAPIImpl) Close() error {
	err := s.state.Close()
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}

var getMetricCredentialsAPI = func(state api.Connection) (metricCredentialsAPI, error) {
	return &metricsCredentialsAPIImpl{api: apiservice.NewClient(state), state: state}, nil
}

// getFlags returns the flags with the given names. Only flags that are set and
// whose name is included in flagNames are included.
func getFlags(flagSet *gnuflag.FlagSet, flagNames []string) []string {
	flags := make([]string, 0, flagSet.NFlag())
	flagSet.Visit(func(flag *gnuflag.Flag) {
		for _, name := range flagNames {
			if flag.Name == name {
				flags = append(flags, flagWithMinus(name))
			}
		}
	})
	return flags
}
Ejemplo n.º 26
0
func opClientGetServiceConstraints(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
	_, err := service.NewClient(st).GetConstraints("wordpress")
	return func() {}, err
}
Ejemplo n.º 27
0
func (s *serviceSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)
	s.client = service.NewClient(s.APIState)
	c.Assert(s.client, gc.NotNil)
}