-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfilter_test.py
150 lines (120 loc) · 4.87 KB
/
filter_test.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
Test WSMan Filtering
@copyright: 2010-2015
@author: Joseph Tallieu <[email protected]>
@organization: Dell Inc. - PG Validation
@license: GNU LGLP v2.1
"""
# This file is part of WSManAPI.
#
# WSManAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2.1 of the License, or
# (at your option) any later version.
#
# WSManAPI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with WSManAPI. If not, see <http://www.gnu.org/licenses/>.
import sys
from wsman import WSMan
from wsman.provider.remote import Remote
from wsman.transport.dummy import Dummy
from wsman.transport.process import Subprocess
from wsman.response.reference import Reference
from wsman.response.fault import Fault
from wsman.format.command import OutputFormatter
from wsman.loghandlers.HTMLHandler import HTMLHandler
from wsman.filter import SelectorFilter, XPathFilter, CQLFilter, WQLFilter
from datetime import datetime
import logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S')
# Set up the text log
fmt = OutputFormatter('%(asctime)s %(levelname)s %(name)s %(message)s %(command)s %(output)s %(duration)fs', pretty=False)
fHandle = logging.FileHandler("test_raw2.txt", mode="w")
fHandle.setFormatter(fmt)
# Set up the HTML log
html = HTMLHandler("test_raw2.html", pretty=False)
log = logging.getLogger("")
log.setLevel(logging.INFO)
log.addHandler(fHandle)
log.addHandler(html)
# Remote object
# WSMan test
wsman = WSMan(transport=Subprocess())
CLASSNAME = "DCIM_NICView"
def test_enumerate(ip):
remote = Remote(ip, 'root', 'calvin')
print "Enumerating %s" % CLASSNAME
r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote)
total_count = len(r)
print "Found %d Unfiltered instances" % len(r)
print "XPath Query"
try:
query = XPathFilter(query='../%s[WWN="78:2B:CB:4B:CD:9E"]' % CLASSNAME)
r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
print "CQL Query"
try:
query = CQLFilter(query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' % CLASSNAME)
r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
print "WQL Query"
try:
query = WQLFilter(query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' % CLASSNAME)
r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
print "Selector Query"
try:
query = SelectorFilter(query='{DeviceNumber = "0"}')
r = wsman.enumerate(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
print "Testing enumerate_keys"
r = wsman.enumerate_keys(CLASSNAME, "root/dcim", remote=remote)
print "XPath Query"
try:
query = XPathFilter(query='../%s[WWN="78:2B:CB:4B:CD:9E"]' % CLASSNAME)
r = wsman.enumerate_keys(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
print "CQL Query"
try:
query = CQLFilter(query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' % CLASSNAME)
r = wsman.enumerate_keys(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
print "WQL Query"
try:
query = WQLFilter(query='select * from %s where WWN = "78:2B:CB:4B:CD:9E"' % CLASSNAME)
r = wsman.enumerate_keys(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
print "Selector Query"
try:
query = SelectorFilter(query='{WWN = "78:2B:CB:4B:CD:9E"}')
r = wsman.enumerate_keys(CLASSNAME, "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
except:
print "Error"
"""
r = wsman.enumerate_keys("DCIM_SELLogEntry", "root/dcim", remote=remote, query=query)
print "Found %d instances" % len(r)
"""
if __name__ == "__main__":
test_enumerate(sys.argv[1])