~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_instance.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:
22
22
        "github.com/juju/juju/environs"
23
23
        "github.com/juju/juju/environs/imagemetadata"
24
24
        "github.com/juju/juju/environs/instances"
 
25
        "github.com/juju/juju/environs/tags"
25
26
        "github.com/juju/juju/instance"
26
 
        "github.com/juju/juju/provider/common"
27
 
        "github.com/juju/juju/state/multiwatcher"
28
27
        "github.com/juju/juju/tools"
29
28
)
30
29
 
59
58
var unsupportedConstraints = []string{
60
59
        constraints.CpuPower,
61
60
        constraints.Tags,
 
61
        constraints.VirtType,
62
62
}
63
63
 
64
64
// ConstraintsValidator is defined on the Environs interface.
142
142
        }
143
143
        logger.Debugf("joyent user data: %d bytes", len(userData))
144
144
 
 
145
        instanceTags := make(map[string]string)
 
146
        for tag, value := range args.InstanceConfig.Tags {
 
147
                instanceTags[tagKey(tag)] = value
 
148
        }
 
149
        instanceTags[tagKey("group")] = "juju"
 
150
        instanceTags[tagKey("model")] = env.Config().Name()
 
151
 
 
152
        args.InstanceConfig.Tags = instanceTags
 
153
        logger.Debugf("Now tags are:  %+v", args.InstanceConfig.Tags)
 
154
 
145
155
        var machine *cloudapi.Machine
146
156
        machine, err = env.compute.cloudapi.CreateMachine(cloudapi.CreateMachineOpts{
147
 
                //Name:  env.machineFullName(machineConf.MachineId),
148
157
                Package:  spec.InstanceType.Name,
149
158
                Image:    spec.Image.Id,
150
159
                Metadata: map[string]string{"metadata.cloud-init:user-data": string(userData)},
151
 
                Tags:     map[string]string{"tag.group": "juju", "tag.env": env.Config().Name()},
 
160
                Tags:     args.InstanceConfig.Tags,
152
161
        })
153
162
        if err != nil {
154
163
                return nil, errors.Annotate(err, "cannot create instances")
156
165
        machineId := machine.Id
157
166
 
158
167
        logger.Infof("provisioning instance %q", machineId)
 
168
        logger.Infof("machine created with tags %+v", machine.Tags)
159
169
 
160
170
        machine, err = env.compute.cloudapi.GetMachine(machineId)
161
171
        if err != nil {
179
189
                env:     env,
180
190
        }
181
191
 
182
 
        if multiwatcher.AnyJobNeedsState(args.InstanceConfig.Jobs...) {
183
 
                if err := common.AddStateInstance(env.Storage(), inst.Id()); err != nil {
184
 
                        logger.Errorf("could not record instance in provider-state: %v", err)
185
 
                }
186
 
        }
187
 
 
188
192
        disk64 := uint64(machine.Disk)
189
193
        hc := instance.HardwareCharacteristics{
190
194
                Arch:     &spec.Image.Arch,
200
204
        }, nil
201
205
}
202
206
 
 
207
// Joyent tag must be prefixed with "tag."
 
208
func tagKey(aKey string) string {
 
209
        return "tag." + aKey
 
210
}
 
211
 
203
212
func (env *joyentEnviron) AllInstances() ([]instance.Instance, error) {
204
213
        instances := []instance.Instance{}
205
214
 
206
215
        filter := cloudapi.NewFilter()
207
 
        filter.Set("tag.group", "juju")
208
 
        filter.Set("tag.env", env.Config().Name())
 
216
        filter.Set(tagKey("group"), "juju")
 
217
        filter.Set(tagKey(tags.JujuModel), env.Config().UUID())
209
218
 
210
219
        machines, err := env.compute.cloudapi.ListMachines(filter)
211
220
        if err != nil {
278
287
                return errors.Annotate(err, "cannot stop all instances")
279
288
        default:
280
289
        }
281
 
        return common.RemoveStateInstances(env.Storage(), ids...)
 
290
        return nil
282
291
}
283
292
 
284
293
func (env *joyentEnviron) stopInstance(id string) error {