3
3
from twisted.internet.defer import inlineCallbacks
5
from juju.control.utils import get_environment
6
from juju.machine.constraints import Constraints
5
from juju.control import legacy
6
from juju.control.utils import get_environment, sync_environment_state
7
from juju.state.environment import EnvironmentStateManager
7
8
from juju.state.service import ServiceStateManager
34
35
"""Set machine constraints for the environment, or for a named service.
36
37
environment = get_environment(options)
38
env_config = options.environments
37
39
return constraints_set(
38
environment, options.service, options.constraints)
40
env_config, environment, options.service, options.constraints)
42
def constraints_set(environment, service_name, constraint_strs):
44
def constraints_set(env_config, environment, service_name, constraint_strs):
44
46
Machine constraints allow you to pick the hardware to which your services
45
47
will be deployed. Examples:
47
49
$ juju set-constraints --service-name mysql mem=8G cpu=4
49
$ juju set-constraints ec2-instance-type=t1.micro
51
"arch", "cpu" and "mem" are always available; other constraints are
52
provider-specific, and will be ignored if specified in an environment of
53
the wrong kind. The recognised constraints are currently:
55
* arch (CPU architecture: x86/amd64/arm; unset by default)
56
* cpu (processing power in Amazon ECU; 1 by default)
57
* mem (memory in [MGT]iB; 512M by default)
58
* ec2-region (us-east-1 by default)
59
* ec2-zone (unset by default)
60
* ec2-instance-type (unset by default)
61
* orchestra-classes (unset by default)
62
* orchestra-name (unset by default)
51
$ juju set-constraints instance-type=t1.micro
53
Available constraints vary by provider type, and will be ignored if not
54
understood by the current environment's provider. The current set of
55
available constraints across all providers is:
59
* arch (CPU architecture: i386/amd64/arm; amd64 by default)
60
* cpu (processing power in Amazon ECU; 1 by default)
61
* mem (memory in [MGT]iB; 512M by default)
62
* instance-type (unset by default)
63
* ec2-zone (unset by default)
67
* orchestra-classes (unset by default)
71
* maas-name (unset by default)
64
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.
68
76
New constraints set on an entity will completely replace that entity's
69
77
pre-existing constraints.
72
80
service constraints, just specify "name=" (rather than just not specifying
73
81
the constraint at all, which will cause it to inherit the environment's
84
To entirely unset a constraint, specify "name=any".
76
constraints = Constraints.from_strs(environment.type, constraint_strs)
78
if service_name is None:
79
raise NotImplementedError("Environment constraints not implemented")
81
86
provider = environment.get_machine_provider()
87
constraint_set = yield provider.get_constraint_set()
88
constraints = constraint_set.parse(constraint_strs)
82
89
client = yield provider.connect()
84
service_state_manager = ServiceStateManager(client)
85
service = yield service_state_manager.get_service_state(service_name)
86
yield service.set_constraints(constraints)
91
yield legacy.check_constraints(client, constraint_strs)
92
yield sync_environment_state(client, env_config, environment.name)
93
if service_name is None:
94
esm = EnvironmentStateManager(client)
95
yield esm.set_constraints(constraints)
97
ssm = ServiceStateManager(client)
98
service = yield ssm.get_service_state(service_name)
99
yield service.set_constraints(constraints)
88
101
yield client.close()