provider/vsphere: remove incorrect getSnapshot pattern #4920

Merged
merged 2 commits into from Mar 30, 2016
Jump to file or symbol
Failed to load files and symbols.
+8 −21
Split
@@ -24,13 +24,13 @@ type environ struct {
common.SupportsUnitPlacementPolicy
name string
- ecfg *environConfig
client *client
- lock sync.Mutex
- archLock sync.Mutex
-
+ archLock sync.Mutex // archLock protects access to the following fields.
supportedArchitectures []string
+
+ lock sync.Mutex // lock protects access the following fields.
+ ecfg *environConfig
}
func newEnviron(cfg *config.Config) (*environ, error) {
@@ -77,17 +77,12 @@ func (env *environ) SetConfig(cfg *config.Config) error {
return nil
}
-// getSnapshot returns a copy of the environment. This is useful for
-// ensuring the env you are using does not get changed by other code
-// while you are using it.
-func (env *environ) getSnapshot() *environ {
- e := *env
- return &e
-}
-
// Config returns the configuration data with which the env was created.
func (env *environ) Config() *config.Config {
- return env.getSnapshot().ecfg.Config
+ env.lock.Lock()
+ cfg := env.ecfg.Config
+ env.lock.Unlock()
+ return cfg
}
//this variable is exported, because it has to be rewritten in external unit tests
@@ -36,8 +36,6 @@ func (*environ) MaintainInstance(args environs.StartInstanceParams) error {
// StartInstance implements environs.InstanceBroker.
func (env *environ) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) {
- env = env.getSnapshot()
-
if args.InstanceConfig.HasNetworks() {
return nil, errors.New("starting instances with networks is not supported yet")
}
@@ -169,8 +167,6 @@ func (env *environ) AllInstances() ([]instance.Instance, error) {
// StopInstances implements environs.InstanceBroker.
func (env *environ) StopInstances(instances ...instance.Id) error {
- env = env.getSnapshot()
-
var ids []string
for _, id := range instances {
ids = append(ids, string(id))
@@ -62,8 +62,6 @@ func (env *environ) Instances(ids []instance.Id) ([]instance.Instance, error) {
// will see they are not tracked in state, assume they're stale/rogue,
// and shut them down.
func (env *environ) instances() ([]instance.Instance, error) {
- env = env.getSnapshot()
-
prefix := common.MachineFullName(env.Config().UUID(), "")
instances, err := env.client.Instances(prefix)
err = errors.Trace(err)
@@ -82,8 +80,6 @@ func (env *environ) instances() ([]instance.Instance, error) {
// ControllerInstances returns the IDs of the instances corresponding
// to juju controllers.
func (env *environ) ControllerInstances() ([]instance.Id, error) {
- env = env.getSnapshot()
-
prefix := common.MachineFullName(env.Config().ControllerUUID(), "")
instances, err := env.client.Instances(prefix)
if err != nil {