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

Unified Diff: juju/conn.go

Issue 8520043: Implement deploy -force-machine=2
Patch Set: Implement deploy -force-machine=2 Created 11 years, 11 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « environs/jujutest/livetests.go ('k') | juju/conn_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: juju/conn.go
=== modified file 'juju/conn.go'
--- juju/conn.go 2013-04-14 22:12:49 +0000
+++ juju/conn.go 2013-04-15 15:37:10 +0000
@@ -190,6 +190,8 @@
// ConfigYAML takes precedence over Config if both are provided.
ConfigYAML string
Constraints constraints.Value
+ // Use string for deploy-to machine to avoid ambiguity around machine 0.
+ ForceMachineId string
}
// DeployService takes a charm and various parameters and deploys it.
@@ -218,7 +220,7 @@
if err := svc.SetConstraints(args.Constraints); err != nil {
return nil, err
}
- _, err = conn.AddUnits(svc, args.NumUnits)
+ _, err = conn.AddUnits(svc, args.NumUnits, args.ForceMachineId)
if err != nil {
return nil, err
}
@@ -284,7 +286,7 @@
// AddUnits starts n units of the given service and allocates machines
// to them as necessary.
-func (conn *Conn) AddUnits(svc *state.Service, n int) ([]*state.Unit, error) {
+func (conn *Conn) AddUnits(svc *state.Service, n int, mid string) ([]*state.Unit, error) {
units := make([]*state.Unit, n)
// TODO store AssignmentPolicy in state, thus removing the need for this
// to use conn.Environ (so the method can be moved off Conn, and into
@@ -296,8 +298,20 @@
if err != nil {
return nil, fmt.Errorf("cannot add unit %d/%d to service %q: %v", i+1, n, svc.Name(), err)
}
- // TODO lp:1101139 (units are not assigned transactionally)
- if err := conn.State.AssignUnit(unit, policy); err != nil {
+ if mid != "" {
+ if n != 1 {
+ return nil, fmt.Errorf("cannot add multiple units of service %q to a single machine", svc.Name())
+ }
+ m, err := conn.State.Machine(mid)
+ if err != nil {
+ return nil, fmt.Errorf("cannot assign unit %q to machine: %v", unit.Name(), err)
+ }
+ err = unit.AssignToMachine(m)
+
+ if err != nil {
+ return nil, err
+ }
+ } else if err := conn.State.AssignUnit(unit, policy); err != nil {
return nil, err
}
units[i] = unit
« no previous file with comments | « environs/jujutest/livetests.go ('k') | juju/conn_test.go » ('j') | no next file with comments »

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