Esempio n. 1
0
func (s *ConfigSuite) TestServiceGet(c *C) {
	for i, t := range getTests {
		c.Logf("test %d. %s", i, t.about)
		ch := s.AddTestingCharm(c, t.charm)
		svc, err := s.State.AddService(fmt.Sprintf("test%d", i), ch)
		c.Assert(err, IsNil)

		var constraintsv constraints.Value
		if t.constraints != "" {
			constraintsv = constraints.MustParse(t.constraints)
			err = svc.SetConstraints(constraintsv)
			c.Assert(err, IsNil)
		}
		if t.config != nil {
			settings, err := ch.Config().ParseSettingsStrings(t.config)
			c.Assert(err, IsNil)
			err = svc.UpdateConfigSettings(settings)
			c.Assert(err, IsNil)
		}
		expect := t.expect
		expect.Constraints = constraintsv
		expect.Service = svc.Name()
		expect.Charm = ch.Meta().Name
		got, err := statecmd.ServiceGet(s.State, params.ServiceGet{svc.Name()})
		c.Assert(err, IsNil)
		c.Assert(got, DeepEquals, expect)
	}
}
Esempio n. 2
0
// Run fetches the configuration of the service and formats
// the result as a YAML string.
func (c *GetCommand) Run(ctx *cmd.Context) error {
	conn, err := juju.NewConnFromName(c.EnvName)
	if err != nil {
		return err
	}
	defer conn.Close()

	params := params.ServiceGet{
		ServiceName: c.ServiceName,
	}

	results, err := statecmd.ServiceGet(conn.State, params)
	if err != nil {
		return err
	}

	resultsMap := map[string]interface{}{
		"service":  results.Service,
		"charm":    results.Charm,
		"settings": results.Config,
	}
	return c.out.Write(ctx, resultsMap)
}
Esempio n. 3
0
// ServiceGet returns the configuration for a service.
func (c *Client) ServiceGet(args params.ServiceGet) (params.ServiceGetResults, error) {
	return statecmd.ServiceGet(c.api.state, args)
}
Esempio n. 4
0
func (s *ConfigSuite) TestServiceGetUnknownService(c *C) {
	_, err := statecmd.ServiceGet(s.State, params.ServiceGet{ServiceName: "unknown"})
	c.Assert(err, ErrorMatches, `service "unknown" not found`)
}