Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: juju/control/constraints_set.py

Issue 5845061: juju/control should be aware of subordinates
Patch Set: juju/control should be aware of subordinates Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « juju/control/constraints_get.py ('k') | juju/control/deploy.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import argparse 1 import argparse
2 2
3 from twisted.internet.defer import inlineCallbacks 3 from twisted.internet.defer import inlineCallbacks
4 4
5 from juju.control.utils import get_environment 5 from juju.control import legacy
6 from juju.machine.constraints import Constraints 6 from juju.control.utils import get_environment, sync_environment_state
7 from juju.state.environment import EnvironmentStateManager
7 from juju.state.service import ServiceStateManager 8 from juju.state.service import ServiceStateManager
8 9
9 10
10 def configure_subparser(subparsers): 11 def configure_subparser(subparsers):
11 sub_parser = subparsers.add_parser( 12 sub_parser = subparsers.add_parser(
12 "set-constraints", 13 "set-constraints",
13 help=command.__doc__, 14 help=command.__doc__,
14 formatter_class=argparse.RawDescriptionHelpFormatter, 15 formatter_class=argparse.RawDescriptionHelpFormatter,
15 description=constraints_set.__doc__) 16 description=constraints_set.__doc__)
16 17
(...skipping 10 matching lines...) Expand all
27 nargs="+", 28 nargs="+",
28 help="name=value for constraint to set") 29 help="name=value for constraint to set")
29 30
30 return sub_parser 31 return sub_parser
31 32
32 33
33 def command(options): 34 def command(options):
34 """Set machine constraints for the environment, or for a named service. 35 """Set machine constraints for the environment, or for a named service.
35 """ 36 """
36 environment = get_environment(options) 37 environment = get_environment(options)
38 env_config = options.environments
37 return constraints_set( 39 return constraints_set(
38 environment, options.service, options.constraints) 40 env_config, environment, options.service, options.constraints)
39 41
40 42
41 @inlineCallbacks 43 @inlineCallbacks
42 def constraints_set(environment, service_name, constraint_strs): 44 def constraints_set(env_config, environment, service_name, constraint_strs):
43 """ 45 """
44 Machine constraints allow you to pick the hardware to which your services 46 Machine constraints allow you to pick the hardware to which your services
45 will be deployed. Examples: 47 will be deployed. Examples:
46 48
47 $ juju set-constraints --service-name mysql mem=8G cpu=4 49 $ juju set-constraints --service-name mysql mem=8G cpu=4
48 50
49 $ juju set-constraints ec2-instance-type=t1.micro 51 $ juju set-constraints instance-type=t1.micro
50 52
51 "arch", "cpu" and "mem" are always available; other constraints are 53 Available constraints vary by provider type, and will be ignored if not
52 provider-specific, and will be ignored if specified in an environment of 54 understood by the current environment's provider. The current set of
53 the wrong kind. The recognised constraints are currently: 55 available constraints across all providers is:
54 56
55 * arch (CPU architecture: x86/amd64/arm; unset by default) 57 On Amazon EC2:
56 * cpu (processing power in Amazon ECU; 1 by default) 58
57 * mem (memory in [MGT]iB; 512M by default) 59 * arch (CPU architecture: i386/amd64/arm; amd64 by default)
58 * ec2-region (us-east-1 by default) 60 * cpu (processing power in Amazon ECU; 1 by default)
59 * ec2-zone (unset by default) 61 * mem (memory in [MGT]iB; 512M by default)
60 * ec2-instance-type (unset by default) 62 * instance-type (unset by default)
61 * orchestra-classes (unset by default) 63 * ec2-zone (unset by default)
62 * orchestra-name (unset by default) 64
65 On Orchestra:
66
67 * orchestra-classes (unset by default)
68
69 On MAAS:
70
71 * maas-name (unset by default)
63 72
64 Service settings, if specified, will override environment settings, which 73 Service settings, if specified, will override environment settings, which
65 will in turn override the juju defaults of mem=512M, cpu=1, 74 will in turn override the juju defaults of mem=512M, cpu=1, arch=amd64.
66 ec2-region=us-east-1.
67 75
68 New constraints set on an entity will completely replace that entity's 76 New constraints set on an entity will completely replace that entity's
69 pre-existing constraints. 77 pre-existing constraints.
70 78
71 To override an environment constraint with the juju default when setting 79 To override an environment constraint with the juju default when setting
72 service constraints, just specify "name=" (rather than just not specifying 80 service constraints, just specify "name=" (rather than just not specifying
73 the constraint at all, which will cause it to inherit the environment's 81 the constraint at all, which will cause it to inherit the environment's
74 value). 82 value).
83
84 To entirely unset a constraint, specify "name=any".
75 """ 85 """
76 constraints = Constraints.from_strs(environment.type, constraint_strs)
77
78 if service_name is None:
79 raise NotImplementedError("Environment constraints not implemented")
80
81 provider = environment.get_machine_provider() 86 provider = environment.get_machine_provider()
87 constraint_set = yield provider.get_constraint_set()
88 constraints = constraint_set.parse(constraint_strs)
82 client = yield provider.connect() 89 client = yield provider.connect()
83 try: 90 try:
84 service_state_manager = ServiceStateManager(client) 91 yield legacy.check_constraints(client, constraint_strs)
85 service = yield service_state_manager.get_service_state(service_name) 92 yield sync_environment_state(client, env_config, environment.name)
86 yield service.set_constraints(constraints) 93 if service_name is None:
94 esm = EnvironmentStateManager(client)
95 yield esm.set_constraints(constraints)
96 else:
97 ssm = ServiceStateManager(client)
98 service = yield ssm.get_service_state(service_name)
99 yield service.set_constraints(constraints)
87 finally: 100 finally:
88 yield client.close() 101 yield client.close()
OLDNEW
« no previous file with comments | « juju/control/constraints_get.py ('k') | juju/control/deploy.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b