~juju-qa/ubuntu/trusty/juju/juju-1.25.8

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/service/constraints.go

  • Committer: Nicholas Skaggs
  • Date: 2016-12-02 18:01:10 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161202180110-dl1helep8qfebmhx
ImportĀ upstreamĀ 1.25.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package service
 
5
 
 
6
import (
 
7
        "fmt"
 
8
 
 
9
        "github.com/juju/cmd"
 
10
        "github.com/juju/names"
 
11
        "launchpad.net/gnuflag"
 
12
 
 
13
        "github.com/juju/juju/cmd/juju/common"
 
14
        "github.com/juju/juju/constraints"
 
15
)
 
16
 
 
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.
 
21
 
 
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
 
25
precedence.
 
26
 
 
27
See Also:
 
28
   juju help constraints
 
29
   juju help service set-constraints
 
30
   juju help deploy
 
31
   juju help machine add
 
32
   juju help add-unit
 
33
`
 
34
 
 
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.
 
40
 
 
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
 
44
precedence.
 
45
 
 
46
Example:
 
47
 
 
48
    set-constraints wordpress mem=4G     (all new wordpress machines must have at least 4GB of RAM)
 
49
 
 
50
See Also:
 
51
   juju help constraints
 
52
   juju help service get-constraints
 
53
   juju help deploy
 
54
   juju help machine add
 
55
   juju help add-unit
 
56
`
 
57
 
 
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
 
63
}
 
64
 
 
65
func (c *ServiceGetConstraintsCommand) Info() *cmd.Info {
 
66
        return &cmd.Info{
 
67
                Name:    "get-constraints",
 
68
                Args:    "<service>",
 
69
                Purpose: "view constraints on a service",
 
70
                Doc:     getConstraintsDoc,
 
71
        }
 
72
}
 
73
 
 
74
func (c *ServiceGetConstraintsCommand) Init(args []string) error {
 
75
        if len(args) == 0 {
 
76
                return fmt.Errorf("no service name specified")
 
77
        }
 
78
        if !names.IsValidService(args[0]) {
 
79
                return fmt.Errorf("invalid service name %q", args[0])
 
80
        }
 
81
 
 
82
        c.ServiceName = args[0]
 
83
        return nil
 
84
}
 
85
 
 
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
 
91
}
 
92
 
 
93
func (c *ServiceSetConstraintsCommand) Info() *cmd.Info {
 
94
        return &cmd.Info{
 
95
                Name:    "set-constraints",
 
96
                Args:    "<service> [key=[value] ...]",
 
97
                Purpose: "set constraints on a service",
 
98
                Doc:     setConstraintsDoc,
 
99
        }
 
100
}
 
101
 
 
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) {}
 
106
 
 
107
func (c *ServiceSetConstraintsCommand) Init(args []string) (err error) {
 
108
        if len(args) == 0 {
 
109
                return fmt.Errorf("no service name specified")
 
110
        }
 
111
        if !names.IsValidService(args[0]) {
 
112
                return fmt.Errorf("invalid service name %q", args[0])
 
113
        }
 
114
 
 
115
        c.ServiceName, args = args[0], args[1:]
 
116
 
 
117
        c.Constraints, err = constraints.Parse(args...)
 
118
        return err
 
119
}