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

« back to all changes in this revision

Viewing changes to src/github.com/juju/gomaasapi/controller.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
252
252
        Domain       string
253
253
        Zone         string
254
254
        AgentName    string
 
255
        OwnerData    map[string]string
255
256
}
256
257
 
257
258
// Machines implements Controller.
263
264
        params.MaybeAdd("domain", args.Domain)
264
265
        params.MaybeAdd("zone", args.Zone)
265
266
        params.MaybeAdd("agent_name", args.AgentName)
 
267
        // At the moment the MAAS API doesn't support filtering by owner
 
268
        // data so we do that ourselves below.
266
269
        source, err := c.getQuery("machines", params.Values)
267
270
        if err != nil {
268
271
                return nil, NewUnexpectedError(err)
274
277
        var result []Machine
275
278
        for _, m := range machines {
276
279
                m.controller = c
277
 
                result = append(result, m)
 
280
                if ownerDataMatches(m.ownerData, args.OwnerData) {
 
281
                        result = append(result, m)
 
282
                }
278
283
        }
279
284
        return result, nil
280
285
}
281
286
 
 
287
func ownerDataMatches(ownerData, filter map[string]string) bool {
 
288
        for key, value := range filter {
 
289
                if ownerData[key] != value {
 
290
                        return false
 
291
                }
 
292
        }
 
293
        return true
 
294
}
 
295
 
282
296
// StorageSpec represents one element of storage constraints necessary
283
297
// to be satisfied to allocate a machine.
284
298
type StorageSpec struct {