예제 #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
// SetServiceContstraints sets the constraints for a given service
func SetServiceConstraints(st *state.State, args params.SetServiceConstraints) error {
	svc, err := st.Service(args.ServiceName)
	if err != nil {
		return err
	}
	return svc.SetConstraints(args.Constraints)
}
예제 #3
0
// GetServiceConstraints returns the constraints for a given service
func GetServiceConstraints(st *state.State, args params.GetServiceConstraints) (params.GetServiceConstraintsResults, error) {
	svc, err := st.Service(args.ServiceName)
	if err != nil {
		return params.GetServiceConstraintsResults{constraints.Value{}}, err
	}
	constraints, err := svc.Constraints()
	return params.GetServiceConstraintsResults{constraints}, err
}
예제 #4
0
func opClientServiceExpose(c *C, st *api.State, mst *state.State) (func(), error) {
	err := st.Client().ServiceExpose("wordpress")
	if err != nil {
		return func() {}, err
	}
	return func() {
		svc, err := mst.Service("wordpress")
		c.Assert(err, IsNil)
		svc.ClearExposed()
	}, nil
}
예제 #5
0
// ServiceUnexpose changes the juju-managed firewall to unexpose any ports that
// were also explicitly marked by units as open.
func ServiceUnexpose(state *state.State, args params.ServiceUnexpose) error {
	svc, err := state.Service(args.ServiceName)
	if err != nil {
		return err
	}
	return svc.ClearExposed()
}
예제 #6
0
// ServiceDestroy destroys a given service along with all its units and relations.
func ServiceDestroy(state *state.State, args params.ServiceDestroy) error {
	svc, err := state.Service(args.ServiceName)
	if err != nil {
		return err
	}

	return svc.Destroy()
}
예제 #7
0
// AddServiceUnits adds a given number of units to a service.
func AddServiceUnits(state *state.State, args params.AddServiceUnits) ([]*state.Unit, error) {
	conn, err := juju.NewConnFromState(state)
	if err != nil {
		return nil, err
	}
	service, err := state.Service(args.ServiceName)
	if err != nil {
		return nil, err
	}
	if args.NumUnits < 1 {
		return nil, errors.New("must add at least one unit")
	}
	if args.NumUnits > 1 && args.ToMachineSpec != "" {
		return nil, errors.New("cannot use --num-units with --to")
	}
	return conn.AddUnits(service, args.NumUnits, args.ToMachineSpec)
}