-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm_query.go
More file actions
44 lines (36 loc) · 863 Bytes
/
vm_query.go
File metadata and controls
44 lines (36 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package vcdusage
import (
"fmt"
"regexp"
)
type VMQuery struct {
Name *regexp.Regexp
GuestOS *regexp.Regexp
PoweredOn bool
}
type VMQuerySetter func(*VMQuery)
func VMWithNameContaining(contains string) VMQuerySetter {
return func(q *VMQuery) {
q.Name = regexp.MustCompile(fmt.Sprintf("(?i).*%s.*", contains))
}
}
func VMWithNameMatching(pattern *regexp.Regexp) VMQuerySetter {
return func(q *VMQuery) {
q.Name = pattern
}
}
func VMWithGuestOSContaining(contains string) VMQuerySetter {
return func(q *VMQuery) {
q.GuestOS = regexp.MustCompile(fmt.Sprintf("(?i).*%s.*", contains))
}
}
func VMWithGuestOSMatching(pattern *regexp.Regexp) VMQuerySetter {
return func(q *VMQuery) {
q.GuestOS = regexp.MustCompile("(?i)" + pattern.String())
}
}
func VMPoweredOn() VMQuerySetter {
return func(q *VMQuery) {
q.PoweredOn = true
}
}