LEFT | RIGHT |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package provisioner | 4 package provisioner |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "time" | 8 "time" |
9 | 9 |
10 "launchpad.net/tomb" | 10 "launchpad.net/tomb" |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 func (task *provisionerTask) stopInstances(instances []instance.Instance) error
{ | 394 func (task *provisionerTask) stopInstances(instances []instance.Instance) error
{ |
395 // Although calling StopInstance with an empty slice should produce no c
hange in the | 395 // Although calling StopInstance with an empty slice should produce no c
hange in the |
396 // provider, environs like dummy do not consider this a noop. | 396 // provider, environs like dummy do not consider this a noop. |
397 if len(instances) == 0 { | 397 if len(instances) == 0 { |
398 return nil | 398 return nil |
399 } | 399 } |
400 ids := make([]instance.Id, len(instances)) | 400 ids := make([]instance.Id, len(instances)) |
401 for i, inst := range instances { | 401 for i, inst := range instances { |
402 ids[i] = inst.Id() | 402 ids[i] = inst.Id() |
403 } | 403 } |
404 » if err := task.broker.StopInstances(ids); err != nil { | 404 » if err := task.broker.StopInstances(ids...); err != nil { |
405 logger.Errorf("broker failed to stop instances: %v", err) | 405 logger.Errorf("broker failed to stop instances: %v", err) |
406 return err | 406 return err |
407 } | 407 } |
408 return nil | 408 return nil |
409 } | 409 } |
410 | 410 |
411 func (task *provisionerTask) startMachines(machines []*apiprovisioner.Machine) e
rror { | 411 func (task *provisionerTask) startMachines(machines []*apiprovisioner.Machine) e
rror { |
412 for _, m := range machines { | 412 for _, m := range machines { |
413 if err := task.startMachine(m); err != nil { | 413 if err := task.startMachine(m); err != nil { |
414 return fmt.Errorf("cannot start machine %v: %v", m, err) | 414 return fmt.Errorf("cannot start machine %v: %v", m, err) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 481 |
482 err = machine.SetInstanceInfo(inst.Id(), nonce, metadata, networks, ifac
es) | 482 err = machine.SetInstanceInfo(inst.Id(), nonce, metadata, networks, ifac
es) |
483 if err != nil && params.IsCodeNotImplemented(err) { | 483 if err != nil && params.IsCodeNotImplemented(err) { |
484 return fmt.Errorf("cannot provision instance %v for machine %q w
ith networks: not implemented", inst.Id(), machine) | 484 return fmt.Errorf("cannot provision instance %v for machine %q w
ith networks: not implemented", inst.Id(), machine) |
485 } else if err == nil { | 485 } else if err == nil { |
486 logger.Infof("started machine %s as instance %s with hardware %q
, networks %v, interfaces %v", machine, inst.Id(), metadata, networks, ifaces) | 486 logger.Infof("started machine %s as instance %s with hardware %q
, networks %v, interfaces %v", machine, inst.Id(), metadata, networks, ifaces) |
487 return nil | 487 return nil |
488 } | 488 } |
489 // We need to stop the instance right away here, set error status and go
on. | 489 // We need to stop the instance right away here, set error status and go
on. |
490 task.setErrorStatus("cannot register instance for machine %v: %v", machi
ne, err) | 490 task.setErrorStatus("cannot register instance for machine %v: %v", machi
ne, err) |
491 » if err := task.broker.StopInstances([]instance.Id{inst.Id()}); err != ni
l { | 491 » if err := task.broker.StopInstances(inst.Id()); err != nil { |
492 // We cannot even stop the instance, log the error and quit. | 492 // We cannot even stop the instance, log the error and quit. |
493 logger.Errorf("cannot stop instance %q for machine %v: %v", inst
.Id(), machine, err) | 493 logger.Errorf("cannot stop instance %q for machine %v: %v", inst
.Id(), machine, err) |
494 return err | 494 return err |
495 } | 495 } |
496 return nil | 496 return nil |
497 } | 497 } |
498 | 498 |
499 func (task *provisionerTask) possibleTools(series string, cons constraints.Value
) (coretools.List, error) { | 499 func (task *provisionerTask) possibleTools(series string, cons constraints.Value
) (coretools.List, error) { |
500 if env, ok := task.broker.(environs.Environ); ok { | 500 if env, ok := task.broker.(environs.Environ); ok { |
501 agentVersion, ok := env.Config().AgentVersion() | 501 agentVersion, ok := env.Config().AgentVersion() |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 excludeNetworks := pInfo.ExcludeNetworks | 552 excludeNetworks := pInfo.ExcludeNetworks |
553 nonce := fmt.Sprintf("%s:%s", task.machineTag, uuid.String()) | 553 nonce := fmt.Sprintf("%s:%s", task.machineTag, uuid.String()) |
554 machineConfig := environs.NewMachineConfig(machine.Id(), nonce, includeN
etworks, excludeNetworks, stateInfo, apiInfo) | 554 machineConfig := environs.NewMachineConfig(machine.Id(), nonce, includeN
etworks, excludeNetworks, stateInfo, apiInfo) |
555 return &provisioningInfo{ | 555 return &provisioningInfo{ |
556 Constraints: pInfo.Constraints, | 556 Constraints: pInfo.Constraints, |
557 Series: pInfo.Series, | 557 Series: pInfo.Series, |
558 Placement: pInfo.Placement, | 558 Placement: pInfo.Placement, |
559 MachineConfig: machineConfig, | 559 MachineConfig: machineConfig, |
560 }, nil | 560 }, nil |
561 } | 561 } |
LEFT | RIGHT |