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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/client/filtering.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:
15
15
 
16
16
        "github.com/juju/juju/network"
17
17
        "github.com/juju/juju/state"
 
18
        "github.com/juju/juju/status"
18
19
)
19
20
 
20
21
var InvalidFormatErr = errors.Errorf("the given filter did not match any known patterns.")
182
183
        return matchExposure(patterns, s)
183
184
}
184
185
 
185
 
func unitMatchSubnet(u *state.Unit, patterns []string) (bool, bool, error) {
186
 
        pub, pubErr := u.PublicAddress()
187
 
        if pubErr != nil && !network.IsNoAddress(pubErr) {
188
 
                return true, false, errors.Trace(pubErr)
189
 
        }
190
 
        priv, privErr := u.PrivateAddress()
191
 
        if privErr != nil && !network.IsNoAddress(privErr) {
192
 
                return true, false, errors.Trace(privErr)
193
 
        }
194
 
        if pubErr != nil && privErr != nil {
195
 
                return true, false, nil
196
 
        }
197
 
        return matchSubnet(patterns, pub.Value, priv.Value)
198
 
}
199
 
 
200
186
func unitMatchPort(u *state.Unit, patterns []string) (bool, bool, error) {
201
187
        portRanges, err := u.OpenedPorts()
202
188
        if err != nil {
337
323
        return false, false, nil
338
324
}
339
325
 
340
 
func matchWorkloadStatus(patterns []string, workloadStatus state.Status, agentStatus state.Status) (bool, bool, error) {
 
326
func matchWorkloadStatus(patterns []string, workloadStatus status.Status, agentStatus status.Status) (bool, bool, error) {
341
327
        oneValidStatus := false
342
328
        for _, p := range patterns {
343
329
                // If the pattern isn't a known status, ignore it.
344
 
                ps := state.Status(p)
 
330
                ps := status.Status(p)
345
331
                if !ps.KnownWorkloadStatus() {
346
332
                        continue
347
333
                }
349
335
                oneValidStatus = true
350
336
                // To preserve current expected behaviour, we only report on workload status
351
337
                // if the agent itself is not in error.
352
 
                if agentStatus != state.StatusError && workloadStatus.WorkloadMatches(ps) {
 
338
                if agentStatus != status.StatusError && workloadStatus.WorkloadMatches(ps) {
353
339
                        return true, true, nil
354
340
                }
355
341
        }
356
342
        return false, oneValidStatus, nil
357
343
}
358
344
 
359
 
func matchAgentStatus(patterns []string, status state.Status) (bool, bool, error) {
 
345
func matchAgentStatus(patterns []string, agentStatus status.Status) (bool, bool, error) {
360
346
        oneValidStatus := false
361
347
        for _, p := range patterns {
362
348
                // If the pattern isn't a known status, ignore it.
363
 
                ps := state.Status(p)
 
349
                ps := status.Status(p)
364
350
                if !ps.KnownAgentStatus() {
365
351
                        continue
366
352
                }
367
353
 
368
354
                oneValidStatus = true
369
 
                if status.Matches(ps) {
 
355
                if agentStatus.Matches(ps) {
370
356
                        return true, true, nil
371
357
                }
372
358
        }