1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/names"
11
"launchpad.net/gnuflag"
13
"github.com/juju/juju/cmd/juju/common"
14
"github.com/juju/juju/constraints"
17
const getConstraintsDoc = `
18
Shows the list of constraints that have been set on the specified service
19
using juju service set-constraints. You can also view constraints
20
set for an environment by using juju environment get-constraints.
22
Constraints set on a service are combined with environment constraints for
23
commands (such as juju deploy) that provision machines for services. Where
24
environment and service constraints overlap, the service constraints take
29
juju help service set-constraints
35
const setConstraintsDoc = `
36
Sets machine constraints on specific service, which are used as the
37
default constraints for all new machines provisioned by that service.
38
You can also set constraints on an environment by using
39
juju environment set-constraints.
41
Constraints set on a service are combined with environment constraints for
42
commands (such as juju deploy) that provision machines for services. Where
43
environment and service constraints overlap, the service constraints take
48
set-constraints wordpress mem=4G (all new wordpress machines must have at least 4GB of RAM)
52
juju help service get-constraints
58
// ServiceGetConstraintsCommand shows the constraints for a service.
59
// It is just a wrapper for the common GetConstraintsCommand which
60
// enforces that a service is specified.
61
type ServiceGetConstraintsCommand struct {
62
common.GetConstraintsCommand
65
func (c *ServiceGetConstraintsCommand) Info() *cmd.Info {
67
Name: "get-constraints",
69
Purpose: "view constraints on a service",
70
Doc: getConstraintsDoc,
74
func (c *ServiceGetConstraintsCommand) Init(args []string) error {
76
return fmt.Errorf("no service name specified")
78
if !names.IsValidService(args[0]) {
79
return fmt.Errorf("invalid service name %q", args[0])
82
c.ServiceName = args[0]
86
// ServiceSetConstraintsCommand sets the constraints for a service.
87
// It is just a wrapper for the common SetConstraintsCommand which
88
// enforces that a service is specified.
89
type ServiceSetConstraintsCommand struct {
90
common.SetConstraintsCommand
93
func (c *ServiceSetConstraintsCommand) Info() *cmd.Info {
95
Name: "set-constraints",
96
Args: "<service> [key=[value] ...]",
97
Purpose: "set constraints on a service",
98
Doc: setConstraintsDoc,
102
// SetFlags overrides SetFlags for SetConstraintsCommand since that
103
// will register a flag to specify the service, and the flag is not
104
// required with this service supercommand.
105
func (c *ServiceSetConstraintsCommand) SetFlags(f *gnuflag.FlagSet) {}
107
func (c *ServiceSetConstraintsCommand) Init(args []string) (err error) {
109
return fmt.Errorf("no service name specified")
111
if !names.IsValidService(args[0]) {
112
return fmt.Errorf("invalid service name %q", args[0])
115
c.ServiceName, args = args[0], args[1:]
117
c.Constraints, err = constraints.Parse(args...)