2 # This module allows us to parse a machine placement directive into a
3 # Placement object suitable for passing through the websocket API.
5 # Once https://bugs.launchpad.net/juju/+bug/1645480 is addressed, this
6 # module should be deprecated.
9 from .client
import client
16 Given a string in the format `scope:directive`, or simply `scope`
17 or `directive`, return a Placement object suitable for passing
18 back over the websocket API.
25 if type(directive
) in [dict, client
.Placement
]:
26 # We've been handed something that we can simply hand back to
27 # the api. (Forwards compatibility)
31 # Planner has given us a scope and directive in string form
32 scope
, directive
= directive
.split(":")
33 return client
.Placement(scope
=scope
, directive
=directive
)
35 if directive
.isdigit():
36 # Planner has given us a machine id (we rely on juju core to
37 # verify its validity.)
38 return client
.Placement(scope
=MACHINE_SCOPE
, directive
=directive
)
40 # Planner has probably given us a container type. Leave it up to
41 # juju core to verify that it is valid.
42 return client
.Placement(scope
=directive
)