Skip to content

Commit 9b97815

Browse files
committed
Added timout and no-optimize arguments and implemented optimized query option
1 parent d85f95e commit 9b97815

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

bin/pywmitool

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import time
1010
import getpass
1111
from aiowmi.connection import Connection
1212
from aiowmi.query import Query
13-
from aiowmi.exceptions import WbemFalse
13+
from aiowmi.exceptions import WbemFalse, ServerNotOptimized
1414
from aiowmi.const import (
1515
WBEM_FLAG_DIRECT_READ,
1616
WBEM_FLAG_USE_AMENDED_QUALIFIERS,
@@ -20,19 +20,30 @@ from aiowmi.const import (
2020
)
2121

2222

23-
async def main(address, username, password, domain, wqlstr, namespace):
24-
query = Query(wqlstr, namespace=namespace)
23+
async def main(
24+
address, username, password, domain,
25+
wqlstr, namespace, timeout, noopt):
26+
query = Query(wqlstr, namespace=namespace)
2527

2628
start = time.time()
2729
service = None
2830

2931
conn = Connection(address, username, password, domain=domain)
30-
await conn.connect()
32+
await conn.connect(timeout=timeout)
3133
try:
3234
service = await conn.negotiate_ntlm()
3335

3436
await query.start(conn, service)
3537

38+
if not noopt:
39+
try:
40+
await query.optimize()
41+
logging.debug('Using Smart Enum requests')
42+
except ServerNotOptimized:
43+
logging.debug('Server is not optimized')
44+
else:
45+
logging.debug('Optimize disabled')
46+
3647
while True:
3748
try:
3849
res = await query.next()
@@ -67,7 +78,7 @@ async def main(address, username, password, domain, wqlstr, namespace):
6778
logging.debug(f'done in {end-start}')
6879

6980

70-
__version__ = (0, 1, 1) # Update setup.py as well
81+
__version__ = (0, 1, 2) # Update setup.py as well
7182

7283
if __name__ == '__main__':
7384
parser = argparse.ArgumentParser()
@@ -113,6 +124,18 @@ if __name__ == '__main__':
113124
default='root/cimv2',
114125
help='Namespace, defaults to `root/cimv2`')
115126

127+
parser.add_argument(
128+
'-t',
129+
'--timeout',
130+
type=int,
131+
default=5,
132+
help='Timeout in seconds')
133+
134+
parser.add_argument(
135+
'--no-optimize',
136+
action='store_true',
137+
help='Disable Smart Enum for optimized queries')
138+
116139
parser.add_argument(
117140
'--debug',
118141
action='store_true',
@@ -132,7 +155,7 @@ if __name__ == '__main__':
132155
sys.exit(__version__)
133156

134157
logger = logging.getLogger()
135-
logger.setLevel(logging.DEBUG)
158+
logger.setLevel(logging.DEBUG if args.debug else logging.WARNING)
136159

137160
ch = logging.StreamHandler()
138161

@@ -154,4 +177,6 @@ if __name__ == '__main__':
154177
args.domain,
155178
args.wql,
156179
args.namespace,
157-
))
180+
args.timeout,
181+
args.no_optimize
182+
))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
except IOError:
1414
long_description = ''
1515

16-
version = '0.1.1' # Update version in bin/pywmitool as well
16+
version = '0.1.2' # Update version in bin/pywmitool as well
1717

1818
setup(
1919
name='pywmitool',

0 commit comments

Comments
 (0)