~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/joyent/environ.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "fmt"
 
8
        "strings"
8
9
        "sync"
9
10
 
 
11
        "github.com/joyent/gosdc/cloudapi"
10
12
        "github.com/juju/errors"
11
13
 
12
14
        "github.com/juju/juju/constraints"
14
16
        "github.com/juju/juju/environs/config"
15
17
        "github.com/juju/juju/environs/imagemetadata"
16
18
        "github.com/juju/juju/environs/simplestreams"
17
 
        "github.com/juju/juju/environs/storage"
 
19
        "github.com/juju/juju/environs/tags"
18
20
        "github.com/juju/juju/instance"
19
21
        "github.com/juju/juju/provider/common"
20
22
        "github.com/juju/juju/state"
39
41
        // affected fields.
40
42
        lock    sync.Mutex
41
43
        ecfg    *environConfig
42
 
        storage storage.Storage
43
44
        compute *joyentCompute
44
45
}
45
46
 
54
55
        }
55
56
        env.name = cfg.Name()
56
57
        var err error
57
 
        env.storage, err = newStorage(env.ecfg, "")
58
 
        if err != nil {
59
 
                return nil, err
60
 
        }
61
58
        env.compute, err = newCompute(env.ecfg)
62
59
        if err != nil {
63
60
                return nil, err
139
136
        return env.getSnapshot().ecfg.Config
140
137
}
141
138
 
142
 
func (env *joyentEnviron) Storage() storage.Storage {
143
 
        return env.getSnapshot().storage
144
 
}
145
 
 
146
139
func (env *joyentEnviron) Bootstrap(ctx environs.BootstrapContext, args environs.BootstrapParams) (*environs.BootstrapResult, error) {
147
140
        return common.Bootstrap(ctx, env, args)
148
141
}
149
142
 
150
143
func (env *joyentEnviron) ControllerInstances() ([]instance.Id, error) {
151
 
        return common.ProviderStateInstances(env, env.Storage())
 
144
        instanceIds := []instance.Id{}
 
145
 
 
146
        filter := cloudapi.NewFilter()
 
147
        filter.Set(tagKey("group"), "juju")
 
148
        filter.Set(tagKey("model"), env.Config().Name())
 
149
        filter.Set(tagKey(tags.JujuModel), env.Config().UUID())
 
150
        filter.Set(tagKey(tags.JujuController), "true")
 
151
 
 
152
        machines, err := env.compute.cloudapi.ListMachines(filter)
 
153
        if err != nil || len(machines) == 0 {
 
154
                return nil, environs.ErrNotBootstrapped
 
155
        }
 
156
 
 
157
        for _, m := range machines {
 
158
                if strings.EqualFold(m.State, "provisioning") || strings.EqualFold(m.State, "running") {
 
159
                        copy := m
 
160
                        ji := &joyentInstance{machine: &copy, env: env}
 
161
                        instanceIds = append(instanceIds, ji.Id())
 
162
                }
 
163
        }
 
164
 
 
165
        return instanceIds, nil
152
166
}
153
167
 
154
168
func (env *joyentEnviron) Destroy() error {
155
 
        if err := common.Destroy(env); err != nil {
156
 
                return errors.Trace(err)
157
 
        }
158
 
        return env.Storage().RemoveAll()
 
169
        return errors.Trace(common.Destroy(env))
159
170
}
160
171
 
161
172
func (env *joyentEnviron) Ecfg() *environConfig {