示例#1
0
文件: get.go 项目: rif/golang-stuff
// ServiceGet returns the configuration for the named service.
func ServiceGet(st *state.State, p params.ServiceGet) (params.ServiceGetResults, error) {
	service, err := st.Service(p.ServiceName)
	if err != nil {
		return params.ServiceGetResults{}, err
	}
	settings, err := service.ConfigSettings()
	if err != nil {
		return params.ServiceGetResults{}, err
	}
	charm, _, err := service.Charm()
	if err != nil {
		return params.ServiceGetResults{}, err
	}
	configInfo := describe(settings, charm.Config())
	var constraints constraints.Value
	if service.IsPrincipal() {
		constraints, err = service.Constraints()
		if err != nil {
			return params.ServiceGetResults{}, err
		}
	}
	return params.ServiceGetResults{
		Service:     p.ServiceName,
		Charm:       charm.Meta().Name,
		Config:      configInfo,
		Constraints: constraints,
	}, nil
}
示例#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()
	svc, err := conn.State.Service(c.ServiceName)
	if err != nil {
		return err
	}
	svcfg, err := svc.Config()
	if err != nil {
		return err
	}
	charm, _, err := svc.Charm()
	if err != nil {
		return err
	}
	chcfg := charm.Config().Options

	config := merge(svcfg.Map(), chcfg)

	result := map[string]interface{}{
		"service":  svc.Name(),
		"charm":    charm.Meta().Name,
		"settings": config,
	}
	return c.out.Write(ctx, result)
}
示例#3
0
func (s *clientSuite) TestClientServiceDeployPrincipal(c *C) {
	// TODO(fwereade): test ToMachineSpec directly on srvClient, when we
	// manage to extract it as a package and can thus do it conveniently.
	store, restore := makeMockCharmStore()
	defer restore()
	curl, bundle := addCharm(c, store, "dummy")
	mem4g := constraints.MustParse("mem=4G")
	err := s.APIState.Client().ServiceDeploy(
		curl.String(), "service", 3, "", mem4g,
	)
	c.Assert(err, IsNil)
	service, err := s.State.Service("service")
	c.Assert(err, IsNil)
	charm, force, err := service.Charm()
	c.Assert(err, IsNil)
	c.Assert(force, Equals, false)
	c.Assert(charm.URL(), DeepEquals, curl)
	c.Assert(charm.Meta(), DeepEquals, bundle.Meta())
	c.Assert(charm.Config(), DeepEquals, bundle.Config())

	cons, err := service.Constraints()
	c.Assert(err, IsNil)
	c.Assert(cons, DeepEquals, mem4g)
	units, err := service.AllUnits()
	c.Assert(err, IsNil)
	for _, unit := range units {
		mid, err := unit.AssignedMachineId()
		c.Assert(err, IsNil)
		machine, err := s.State.Machine(mid)
		c.Assert(err, IsNil)
		cons, err := machine.Constraints()
		c.Assert(err, IsNil)
		c.Assert(cons, DeepEquals, mem4g)
	}
}
示例#4
0
// CharmInfo returns information about the requested charm.
func (c *Client) CharmInfo(args params.CharmInfo) (api.CharmInfo, error) {
	curl, err := charm.ParseURL(args.CharmURL)
	if err != nil {
		return api.CharmInfo{}, err
	}
	charm, err := c.api.state.Charm(curl)
	if err != nil {
		return api.CharmInfo{}, err
	}
	info := api.CharmInfo{
		Revision: charm.Revision(),
		URL:      curl.String(),
		Config:   charm.Config(),
		Meta:     charm.Meta(),
	}
	return info, nil
}
示例#5
0
func (s *clientSuite) TestClientServiceDeploySubordinate(c *C) {
	store, restore := makeMockCharmStore()
	defer restore()
	curl, bundle := addCharm(c, store, "logging")
	err := s.APIState.Client().ServiceDeploy(
		curl.String(), "service-name", 0, "", constraints.Value{},
	)
	service, err := s.State.Service("service-name")
	c.Assert(err, IsNil)
	charm, force, err := service.Charm()
	c.Assert(err, IsNil)
	c.Assert(force, Equals, false)
	c.Assert(charm.URL(), DeepEquals, curl)
	c.Assert(charm.Meta(), DeepEquals, bundle.Meta())
	c.Assert(charm.Config(), DeepEquals, bundle.Config())

	units, err := service.AllUnits()
	c.Assert(err, IsNil)
	c.Assert(units, HasLen, 0)
}
示例#6
0
func (s *clientSuite) TestClientCharmInfo(c *C) {
	// Use wordpress for tests so that we can compare Provides and Requires.
	charm := s.AddTestingCharm(c, "wordpress")
	for i, t := range clientCharmInfoTests {
		c.Logf("test %d. %s", i, t.about)
		info, err := s.APIState.Client().CharmInfo(t.url)
		if t.err != "" {
			c.Assert(err, ErrorMatches, t.err)
			continue
		}
		c.Assert(err, IsNil)
		expected := &api.CharmInfo{
			Revision: charm.Revision(),
			URL:      charm.URL().String(),
			Config:   charm.Config(),
			Meta:     charm.Meta(),
		}
		c.Assert(info, DeepEquals, expected)
	}
}