-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphit-tool.py
executable file
·581 lines (555 loc) · 20.8 KB
/
graphit-tool.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
#!/usr/bin/env python2
"""graphit-tool
Usage:
graphit-tool [options] mars list [--count] [PATTERN]...
graphit-tool [options] mars put [--chunk-size=NUM] [--replace] FILE...
graphit-tool [options] mars get [--out=DIR] NODEID...
graphit-tool [options] mars del [--chunk-size=NUM] [--del-ci] NODEID...
graphit-tool [options] mars sync NODEID...
graphit-tool [options] mars sync (--count-unsynced|--list-unsynced)
graphit-tool [options] ci (count_orphans|cleanup_orphans)
graphit-tool [options] ci create --attr=ATTR NODEID...
graphit-tool [options] ci create --value=ATTR NODEID
graphit-tool [options] issue list [--all] [--details] [--count] [--status=STATUS]... [PATTERN]...
graphit-tool [options] issue getevent [--field=FIELD...] [--pretty] IID...
graphit-tool [options] vertex get [--field=FIELD...] [--pretty] [--] OGITID...
graphit-tool [options] vertex query [--count] [--list] [--field=FIELD...] [--pretty] [--] QUERY...
graphit-tool [options] vertex del [--] OGITID...
graphit-tool [options] vertex setattr --attr=ATTR --value=VALUE NODEID...
graphit-tool [options] vertex delattr --attr=ATTR NODEID...
graphit-tool [options] token info
graphit-tool [options] token get
Switches:
-o DIR, --out=DIR save node to <node_id>.xml in given directory
-f FIELD, --field=FIELD Return only given fields
-p, --pretty Pretty print JSON data
-c, --count return the number of results, not the results themselves
-C NUM, --chunk-size=NUM Upload NUM MARS nodes in parallel
-R, --replace Replace existing nodes instead of updating them. Before 0.3.2, this
was the default behavior.
-h, --help print help and exit
Options:
-d, --debug print debug messages
"""
import sys
from gevent import monkey; monkey.patch_all()
import codecs
import gevent, gevent.pool
from graphit import GraphitSession, WSO2Error, WSO2AuthClientCredentials, ESQuery, EESQuery, IDQuery, VerbQuery, GraphitError, chunks, XMLValidator, JSONValidator, GraphitNodeError, MARSNode, GraphitNode, MARSNodeError
from docopt import docopt
from ConfigParser import ConfigParser
from requests.structures import CaseInsensitiveDict
import os
import re
import json
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)
if __name__ == '__main__':
args = docopt(__doc__, version='graphit-tool 0.4.1')
if not args['--chunk-size']: args['--chunk-size'] = 10
config = ConfigParser(dict_type=CaseInsensitiveDict)
config.read(['/etc/graphit-tool.conf', os.path.expanduser('~/.graphit-tool.conf')])
session = GraphitSession(config.get('graphit', 'url'))
try:
wso2_verify = config.getboolean('wso2', 'verifycert')
except ValueError:
wso2_verify = config.get('wso2', 'verifycert')
try:
session.auth = WSO2AuthClientCredentials(
config.get('wso2', 'url'),
client = (
config.get('wso2', 'clientid'),
config.get('wso2', 'clientsecret')
),
verify=wso2_verify)
except WSO2Error as e:
print >>sys.stderr, e
sys.exit(10)
try:
session.verify=config.getboolean('graphit', 'verifycert')
except ValueError:
session.verify=config.get('graphit', 'verifycert')
if args['mars'] and args['list']:
q = EESQuery(['+ogit/_type:"ogit/Automation/MARSNode"', '+ogit/_type:*'])
if args['PATTERN']:
q.append(["+ogit/_id:{pat}".format(pat=pattern) for pattern in args['PATTERN']])
#print q
try:
if args['--count']:
for r in session.query(q, fields=['ogit/_id'], count=args['--count']):
print >>sys.stdout, r
sys.exit(0)
else:
for r in session.query(q, fields=['ogit/_id']):
print >>sys.stdout, r['ogit/_id']
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot list nodes: {err}".format(err=e)
sys.exit(5)
if args['issue'] and args['list']:
q = EESQuery(['+ogit/_type:"ogit/Automation/AutomationIssue"', '+ogit/_type:*'], 'AND')
if args['PATTERN']:
q.append(["+ogit/subject:{pat}".format(pat=pattern) for pattern in args['PATTERN']])
if args['--status']:
q.append(EESQuery(["ogit/status:\"{stat}\"".format(stat=status) for status in args['--status']], 'OR'))
if not args['--all']:
q.append(
EESQuery(
[
EESQuery(["ogit/status:RESOLVED", "ogit/_modified-on:[now-12h TO now]"], 'AND'),
EESQuery(["ogit/status:RESOLVED_EXTERNAL", "ogit/_modified-on:[now-12h TO now]"], 'AND'),
"ogit/status:PROCESSING",
"ogit/status:EJECTED",
"ogit/status:WAITING"
], 'OR')
)
print q
try:
fields=['ogit/_id']
if args['--count']:
for r in session.query(q, fields=fields, count=args['--count']):
print >>sys.stdout, r
sys.exit(0)
else:
if args['--details']:
fields.append('ogit/status')
fields.append('ogit/subject')
else:
fields=['ogit/_id']
for r in session.query(q, fields=fields):
if args['--details']:
print >>sys.stdout, "{id}\t{status:17}\t{subject}".format(
id=r['ogit/_id'],
subject=r['ogit/subject'],
status=r['ogit/status']
)
else:
print >>sys.stdout, r['ogit/_id']
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot list issues: {err}".format(err=e)
sys.exit(5)
if args['mars'] and args['get']:
def resumeable(gen):
while True:
try: yield next(gen)
except GraphitNodeError as e: print >>sys.stderr, e
except StopIteration: raise
q = IDQuery(args['NODEID'])
try:
for node in resumeable(session.query(q, fields=[
'ogit/_id', 'ogit/_type', 'ogit/Automation/marsNodeFormalRepresentation'])):
if args['--out']:
with open("{directory}/{basename}.{ext}".format(
directory=args['--out'],
basename=node['ogit/_id'],
ext='xml'), 'w', -1) as f:
MARSNode(None, node).print_node(f)
else:
MARSNode(None, node).print_node(sys.stdout)
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot get nodes: {err}".format(err=e)
sys.exit(5)
if args['mars'] and args['del']:
def delete_node(node):
try:
if args['--del-ci']:
q2 = VerbQuery(node, "ogit/corresponds", ogit_types=['ogit/ConfigurationItem'])
for item in session.query(q2, fields=['ogit/_id']):
print >>sys.stderr, "Deleted corresponding ogit/ConfigurationItem {id}".format(id=item['ogit/_id'])
GraphitNode(session, {'ogit/_id':item['ogit/_id'], 'ogit/_type':'ogit/ConfigurationItem'}).delete()
MARSNode(session, {'ogit/_id':node,'ogit/_type':'ogit/Automation/MARSNode'}).delete()
print >>sys.stderr, "Deleted {id}".format(id = node)
except GraphitNodeError as e:
print >>sys.stderr, e
except GraphitError as e:
print >>sys.stderr, "Failed to delete node {nodeid}: {e}".format(
nodeid=node, e=e)
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
pool = gevent.pool.Pool(size)
for n in args['NODEID']:
pool.spawn(delete_node, n)
pool.join()
sys.exit(0)
if args['mars'] and args['put'] and args['FILE']:
mars_validator = XMLValidator(config.get('mars', 'schema'))
with open(config.get('mars', 'jsonschema')) as schemafile:
json_validator = JSONValidator(schemafile)
def upload_file(filename):
try:
try:
mars_node = MARSNode.from_xmlfile(session, filename, mars_validator)
except MARSNodeError as e:
try:
mars_node = MARSNode.from_jsonfile(session, filename, mars_validator, json_validator)
except MARSNodeError as e2:
print >>sys.stderr, e
print >>sys.stderr, e2
raise MARSNodeError("ERROR: {filename} could not be uploaded!".format(filename=filename))
mars_node.push(replace=args['--replace'])
return (filename, mars_node.data["ogit/_id"])
except MARSNodeError as e:
print >>sys.stderr, e
except GraphitError as e:
print >>sys.stdout, e
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
for result in gevent.pool.Pool(size).imap_unordered(upload_file, args['FILE']):
try:
filename, ogit_id = result
print >>sys.stdout, ogit_id + " (read from " + filename + ") successfully uploaded!"
except TypeError:
pass
sys.exit(0)
if args['mars'] and args['sync']:
def sync_node(node):
MARSNode(session, {
'ogit/_id':node,
'ogit/_type':'ogit/Automation/MARSNode',
'ogit/Automation/deployStatus': None,
'ogit/Automation/isDeployed': None }).update()
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
try:
if args['--count-unsynced']:
q = EESQuery(["+ogit/_type:\"ogit/Automation/MARSNode\"", "+ogit/Automation/isDeployed:\"false\""])
for r in session.query(q, count=True):
print r
sys.exit(0)
elif args['--list-unsynced']:
q = EESQuery(["+ogit/_type:\"ogit/Automation/MARSNode\"", "+ogit/Automation/isDeployed:\"false\""])
for r in session.query(q, fields=['ogit/_id']):
print >>sys.stdout, r['ogit/_id']
sys.exit(0)
else:
pool=gevent.pool.Pool(size)
for n in args['NODEID']:
pool.spawn(sync_node, n)
pool.join()
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot trigger syncing of nodes: {err}".format(err=e)
sys.exit(5)
if args['token'] and args['info']:
print >>sys.stdout, session.auth
if args['token'] and args['get']:
print >>sys.stdout, session.auth.token
if args['ci'] and args['count_orphans']:
q = EESQuery("+ogit/_type:\"ogit/ConfigurationItem\"")
try:
orphsum = 0
def count_corresponds(node):
q2 = VerbQuery(node['ogit/_id'], "ogit/corresponds")
return len(list(session.query(q2, fields=['ogit/_id'])))
for chunk in chunks(session.query(q, fields=['ogit/_id'])):
jobs = [gevent.spawn(count_corresponds, n) for n in chunk]
gevent.joinall(jobs)
orphsum += sum([1 for job in jobs if job.value==0])
print >>sys.stdout, orphsum
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot list nodes: {err}".format(err=e)
sys.exit(5)
if args['ci'] and args['cleanup_orphans']:
q = EESQuery("+ogit/_type:\"ogit/ConfigurationItem\"")
try:
def delete_if_orphan(node):
q2 = VerbQuery(node['ogit/_id'], "ogit/corresponds")
no_conn = len(list(session.query(q2, fields=['ogit/_id'])))
if no_conn == 0:
print >>sys.stdout, "{node} has {no} corresponding vertices, deleting ...".format(
node=node['ogit/_id'], no=no_conn)
GraphitNode(session, {'ogit/_id':node['ogit/_id'], 'ogit/_type':'ogit/ConfigurationItem'}).delete()
else:
print >>sys.stdout, "{node} has {no} corresponding vertices.".format(
node=node['ogit/_id'], no=no_conn)
pool=gevent.pool.Pool(10)
for n in session.query(q, fields=['ogit/_id']):
pool.spawn(delete_if_orphan, n)
pool.join()
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot list nodes: {err}".format(err=e)
sys.exit(5)
if args['ci'] and args['create'] and args['--attr'] and args['NODEID']:
hostname_regex = re.compile('(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)')
def create_missing_ci(mars_id):
try:
mars_node = MARSNode.from_graph(session, mars_id)
#print mars_node.json(pretty_print=True)
except GraphitError as e:
if e.status == 404:
print >>sys.stdout, "{id}: Failure, node does not exists.".format(id=mars_id)
else:
print >>sys.stdout, "{id}: Failure: {err}".format(id=mars_id, err=e)
return
if (args['--attr'] == '_SHORTNAME_'
and mars_node.get_attr('/NodeType') != 'Machine'):
print >>sys.stdout, mars_id + ": _SHORTNAME_ not applicable, works only with machine nodes."
return
elif (args['--attr'] == '_SHORTNAME_'
and mars_node.get_attr('/NodeType') == 'Machine'
and not hostname_regex.match(mars_node.get_attr('/NodeName'))):
print >>sys.stdout, "{id}: _SHORTNAME_ not applicable, '{nn}' is not a valid FQDN'".format(
id=mars_id,
nn=mars_node.get_attr('/NodeName'))
return
elif (args['--attr'] == '_SHORTNAME_'
and mars_node.get_attr('/NodeType') == 'Machine'
and hostname_regex.match(mars_node.get_attr('/NodeName'))):
new_id = mars_node.get_attr('/NodeName').split('.', 1)[0]
elif mars_node.get_attr(args['--attr']):
try:
new_id = json.loads(mars_node.get_attr(args['--attr']))['items'][0][0]
except ValueError:
new_id = mars_node.get_attr(args['--attr'])
else:
print >>sys.stdout, "{id}: Failure, node doesn't have an attribute '{attr}'".format(
id=mars_id, attr=args['--attr'])
return
q = EESQuery(["+ogit/id:\"{new_id}\"".format(new_id=new_id), "+ogit/_type:\"ogit/ConfigurationItem\""])
if len(list(session.query(q, fields=['ogit/_id']))) > 0:
print "{id}: ConfigurationItem with ogit/id '{c}' already exists".format(
id=mars_id, c=new_id)
return
data = {
"ogit/_owner" : mars_node.get_attr('ogit/_owner'),
"ogit/_type" : "ogit/ConfigurationItem",
"ogit/ciType" : mars_node.get_attr('/NodeType'),
"ogit/id" : new_id,
"ogit/name" : new_id
}
try:
ci_node = GraphitNode(session, data)
#print(ci_node.json(pretty_print=True))
ci_node.push()
mars_node.connect('ogit/corresponds', ci_node)
print >>sys.stdout, mars_id + ": ConfigurationItem created: " + ci_node.data['ogit/_id']
return
except GraphitError as e:
print >>sys.stderr, e
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
except GraphitError as e:
print >>sys.stderr, e
sys.exit(1)
list(gevent.pool.Pool(size).imap_unordered(create_missing_ci, args['NODEID']))
sys.exit(0)
if args['ci'] and args['create'] and args['--value'] and args['NODEID']:
def create_missing_ci(mars_id):
try:
mars_node = MARSNode.from_graph(session, mars_id)
except GraphitError as e:
if e.status == 404:
print >>sys.stdout, "{id}: Failure, node does not exists.".format(id=mars_id)
else:
print >>sys.stdout, "{id}: Failure: {err}".format(id=mars_id, err=e)
return
new_id = args['--value']
q = EESQuery(["+ogit/id:\"{new_id}\"".format(new_id=new_id), "+ogit/_type:\"ogit/ConfigurationItem\""])
if len(list(session.query(q, fields=['ogit/_id']))) > 0:
print "{id}: ConfigurationItem with ogit/id '{c}' already exists".format(
id=mars_id, c=new_id)
return
data = {
"ogit/_owner" : mars_node.get_attr('ogit/_owner'),
"ogit/_type" : "ogit/ConfigurationItem",
"ogit/ciType" : mars_node.get_attr('/NodeType'),
"ogit/id" : new_id,
"ogit/name" : new_id
}
try:
ci_node = GraphitNode(session, data)
ci_node.push()
mars_node.connect('ogit/corresponds', ci_node)
print >>sys.stdout, mars_id + ": ConfigurationItem created: " + ci_node.data['ogit/_id']
return
except GraphitError as e:
print >>sys.stderr, e
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
except GraphitError as e:
print >>sys.stderr, e
sys.exit(1)
create_missing_ci(args['NODEID'][0])
sys.exit(0)
if args['vertex'] and args['get'] and args['OGITID']:
q = IDQuery(args['OGITID'])
try:
if args['--count']:
for r in session.query(q, fields=['ogit/_id'], count=args['--count']):
print >>sys.stdout, r
sys.exit(0)
else:
if args['--list']:
args['--field'] = ["ogit/_id"]
for r in session.query(q, fields=args['--field']):
if args['--list']:
print >>sys.stdout, GraphitNode(session,r).data['ogit/_id']
else:
print >>sys.stdout, GraphitNode(session,r).json(pretty_print=args['--pretty'])
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot list nodes: {err}".format(err=e)
sys.exit(5)
except GraphitNodeError as e:
print >>sys.stderr, e
sys.exit(5)
if args['vertex'] and args['del']:
def delete_node(node):
try:
GraphitNode(session, {'ogit/_id':node}).delete()
print >>sys.stderr, "Deleted {id}".format(id = node)
except GraphitNodeError as e:
print >>sys.stderr, e
except GraphitError as e:
print >>sys.stderr, "Failed to delete node {nodeid}: {e}".format(
nodeid=node, e=e)
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
pool = gevent.pool.Pool(size)
for n in args['OGITID']:
pool.spawn(delete_node, n)
pool.join()
sys.exit(0)
if args['vertex'] and args['query']:
q = EESQuery()
for cond in args['QUERY']:
q.append(cond)
print q
try:
if args['--count']:
for r in session.query(q, fields=['ogit/_id'], count=args['--count']):
print >>sys.stdout, r
sys.exit(0)
else:
if args['--list']:
args['--field'] = ["ogit/_id"]
for r in session.query(q, fields=args['--field']):
if args['--list']:
print >>sys.stdout, GraphitNode(session,r).data['ogit/_id']
else:
print >>sys.stdout, GraphitNode(session,r).json(pretty_print=args['--pretty'])
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot list nodes: {err}".format(err=e)
sys.exit(5)
if args['vertex'] and args['setattr'] and args['--attr'] and args['NODEID']:
def set_vertex_attr(node):
data = {
'ogit/_id':node['ogit/_id'],
'ogit/_type':node['ogit/_type'],
args['--attr']:args['--value']
}
GraphitNode(session, data).update()
print >>sys.stdout, "Attribute '{att}' of node '{id}' set to '{val}'".format(
att=args['--attr'],
id=node['ogit/_id'],
val=args['--value'])
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
pool = gevent.pool.Pool(size)
q = IDQuery(args['NODEID'])
for r in session.query(q, fields=['ogit/_id','ogit/_type']):
pool.spawn(set_vertex_attr, r)
pool.join()
sys.exit(0)
if args['vertex'] and args['delattr'] and args['--attr'] and args['NODEID']:
def set_vertex_attr(node):
data = {
'ogit/_id':node['ogit/_id'],
'ogit/_type':node['ogit/_type'],
args['--attr']:None
}
GraphitNode(session, data).update()
print >>sys.stdout, "Attribute '{att}' of node '{id}' deleted".format(
att=args['--attr'],
id=node['ogit/_id'])
try:
size = int(args['--chunk-size'])
if not size >= 1: raise IndexError("--chunk-size has to be >=1")
if size > 9223372036854775808: raise IndexError("--chunk-size has to be <= 9223372036854775808")
except ValueError:
print >>sys.stderr, "--chunk-size has to be numeric"
sys.exit(1)
except IndexError as e:
print >>sys.stderr, e
sys.exit(1)
pool = gevent.pool.Pool(size)
q = IDQuery(args['NODEID'])
for r in session.query(q, fields=['ogit/_id','ogit/_type']):
pool.spawn(set_vertex_attr, r)
pool.join()
sys.exit(0)
if args['issue'] and args['getevent'] and args['IID']:
q = IDQuery(args['IID'])
try:
def print_event(node):
q2 = VerbQuery(node['ogit/_id'], "ogit/corresponds")
for item in session.query(q2, fields=args['--field']):
print >>sys.stdout, GraphitNode(session,item).json(pretty_print=args['--pretty'])
for chunk in chunks(session.query(q, fields=['ogit/_id'])):
jobs = [gevent.spawn(print_event, n) for n in chunk]
gevent.joinall(jobs)
sys.exit(0)
except GraphitError as e:
print >>sys.stderr, "Cannot list nodes: {err}".format(err=e)
sys.exit(5)