blob: 593927bcbd3d936711ac97754b1f1df38f942a49 [file] [log] [blame]
andrewonlab95ce8322014-10-13 14:12:04 -04001#!/usr/bin/env python
2
3'''
4This driver enters the onos> prompt to issue commands.
5
6Please follow the coding style demonstrated by existing
7functions and document properly.
8
9If you are a contributor to the driver, please
10list your email here for future contact:
11
12jhall@onlab.us
13andrew@onlab.us
Jon Halle8217482014-10-17 13:49:14 -040014shreya@onlab.us
andrewonlab95ce8322014-10-13 14:12:04 -040015
16OCT 13 2014
17
18'''
19
20import sys
21import time
22import pexpect
23import re
24import traceback
25import os.path
26import pydoc
Jon Halla001c392014-10-17 18:50:59 -040027import re
andrewonlab95ce8322014-10-13 14:12:04 -040028sys.path.append("../")
29from drivers.common.clidriver import CLI
30
31class OnosCliDriver(CLI):
32
33 def __init__(self):
34 '''
35 Initialize client
36 '''
37 super(CLI, self).__init__()
38
39 def connect(self,**connectargs):
40 '''
41 Creates ssh handle for ONOS cli.
42 '''
43 try:
44 for key in connectargs:
45 vars(self)[key] = connectargs[key]
46 self.home = "~/ONOS"
47 for key in self.options:
48 if key == "home":
49 self.home = self.options['home']
50 break
51
52
53 self.name = self.options['name']
54 self.handle = super(OnosCliDriver,self).connect(
55 user_name = self.user_name,
56 ip_address = self.ip_address,
57 port = self.port,
58 pwd = self.pwd,
59 home = self.home)
60
61 self.handle.sendline("cd "+ self.home)
62 self.handle.expect("\$")
63 if self.handle:
64 return self.handle
65 else :
66 main.log.info("NO ONOS HANDLE")
67 return main.FALSE
68 except pexpect.EOF:
69 main.log.error(self.name + ": EOF exception found")
70 main.log.error(self.name + ": " + self.handle.before)
71 main.cleanup()
72 main.exit()
73 except:
74 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
75 main.log.error( traceback.print_exc() )
76 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
77 main.cleanup()
78 main.exit()
79
80 def disconnect(self):
81 '''
82 Called when Test is complete to disconnect the ONOS handle.
83 '''
84 response = ''
85 try:
andrewonlab2a6c9342014-10-16 13:40:15 -040086 self.handle.sendline("")
87 self.handle.expect("onos>")
andrewonlabc2d05aa2014-10-13 16:51:10 -040088 self.handle.sendline("system:shutdown")
89 self.handle.expect("Confirm")
andrewonlab2a6c9342014-10-16 13:40:15 -040090 self.handle.sendline("yes")
andrewonlabc2d05aa2014-10-13 16:51:10 -040091 self.handle.expect("\$")
92
andrewonlab95ce8322014-10-13 14:12:04 -040093 except pexpect.EOF:
94 main.log.error(self.name + ": EOF exception found")
95 main.log.error(self.name + ": " + self.handle.before)
96 except:
97 main.log.error(self.name + ": Connection failed to the host")
98 response = main.FALSE
99 return response
100
101 def set_cell(self, cellname):
102 '''
103 Calls 'cell <name>' to set the environment variables on ONOSbench
104
105 Before issuing any cli commands, set the environment variable first.
106 '''
107 try:
108 if not cellname:
109 main.log.error("Must define cellname")
110 main.cleanup()
111 main.exit()
112 else:
113 self.handle.sendline("cell "+str(cellname))
114 #Expect the cellname in the ONOS_CELL variable.
115 #Note that this variable name is subject to change
116 # and that this driver will have to change accordingly
117 self.handle.expect("ONOS_CELL="+str(cellname))
118 handle_before = self.handle.before
119 handle_after = self.handle.after
120 #Get the rest of the handle
121 self.handle.sendline("")
122 self.handle.expect("\$")
123 handle_more = self.handle.before
124
125 main.log.info("Cell call returned: "+handle_before+
126 handle_after + handle_more)
127
128 return main.TRUE
129
130 except pexpect.EOF:
131 main.log.error(self.name + ": EOF exception found")
132 main.log.error(self.name + ": " + self.handle.before)
133 main.cleanup()
134 main.exit()
135 except:
136 main.log.info(self.name+" ::::::")
137 main.log.error( traceback.print_exc())
138 main.log.info(self.name+" ::::::")
139 main.cleanup()
140 main.exit()
141
andrewonlabc2d05aa2014-10-13 16:51:10 -0400142 def start_onos_cli(self, ONOS_ip):
andrewonlab95ce8322014-10-13 14:12:04 -0400143 try:
144 self.handle.sendline("")
145 self.handle.expect("\$")
146
147 #Wait for onos start (-w) and enter onos cli
andrewonlabc2d05aa2014-10-13 16:51:10 -0400148 self.handle.sendline("onos -w "+str(ONOS_ip))
andrewonlab95ce8322014-10-13 14:12:04 -0400149 self.handle.expect("onos>")
150
151 except pexpect.EOF:
152 main.log.error(self.name + ": EOF exception found")
153 main.log.error(self.name + ": " + self.handle.before)
154 main.cleanup()
155 main.exit()
156 except:
157 main.log.info(self.name+" ::::::")
158 main.log.error( traceback.print_exc())
159 main.log.info(self.name+" ::::::")
160 main.cleanup()
161 main.exit()
162
andrewonlaba18f6bf2014-10-13 19:31:54 -0400163 def sendline(self, cmd_str):
164 '''
165 Send a completely user specified string to
166 the onos> prompt. Use this function if you have
167 a very specific command to send.
168
169 Warning: There are no sanity checking to commands
170 sent using this method.
171 '''
172 try:
173 self.handle.sendline("")
174 self.handle.expect("onos>")
175
176 self.handle.sendline(cmd_str)
177 self.handle.expect("onos>")
178
179 handle = self.handle.before
180
181 self.handle.sendline("")
182 self.handle.expect("onos>")
183
184 handle += self.handle.before
185 handle += self.handle.after
186
187 main.log.info("Command sent.")
188
189 return handle
190 except pexpect.EOF:
191 main.log.error(self.name + ": EOF exception found")
192 main.log.error(self.name + ": " + self.handle.before)
193 main.cleanup()
194 main.exit()
195 except:
196 main.log.info(self.name+" ::::::")
197 main.log.error( traceback.print_exc())
198 main.log.info(self.name+" ::::::")
199 main.cleanup()
200 main.exit()
201
andrewonlab95ce8322014-10-13 14:12:04 -0400202 #IMPORTANT NOTE:
203 #For all cli commands, naming convention should match
204 #the cli command replacing ':' with '_'.
205 #Ex) onos:topology > onos_topology
206 # onos:links > onos_links
207 # feature:list > feature_list
andrewonlabc2d05aa2014-10-13 16:51:10 -0400208
209 def add_node(self, node_id, ONOS_ip, tcp_port=""):
210 '''
211 Adds a new cluster node by ID and address information.
212 Required:
213 * node_id
214 * ONOS_ip
215 Optional:
216 * tcp_port
217 '''
218 try:
219 self.handle.sendline("")
220 self.handle.expect("onos>")
221
222 self.handle.sendline("add-node "+
223 str(node_id)+" "+
224 str(ONOS_ip)+" "+
225 str(tcp_port))
226
227 i = self.handle.expect([
228 "Error",
229 "onos>" ])
230
231 #Clear handle to get previous output
232 self.handle.sendline("")
233 self.handle.expect("onos>")
234
235 handle = self.handle.before
236
237 if i == 0:
238 main.log.error("Error in adding node")
239 main.log.error(handle)
240 return main.FALSE
241 else:
242 main.log.info("Node "+str(ONOS_ip)+" added")
243 return main.TRUE
244
245 except pexpect.EOF:
246 main.log.error(self.name + ": EOF exception found")
247 main.log.error(self.name + ": " + self.handle.before)
248 main.cleanup()
249 main.exit()
250 except:
251 main.log.info(self.name+" ::::::")
252 main.log.error( traceback.print_exc())
253 main.log.info(self.name+" ::::::")
254 main.cleanup()
255 main.exit()
256
andrewonlab86dc3082014-10-13 18:18:38 -0400257 def remove_node(self, node_id):
258 '''
259 Removes a cluster by ID
260 Issues command: 'remove-node [<node-id>]'
261 Required:
262 * node_id
263 '''
264 try:
265 self.handle.sendline("")
266 self.handle.expect("onos>")
267
268 self.handle.sendline("remove-node "+str(node_id))
269 self.handle.expect("onos>")
270
271 return main.TRUE
272
273 except pexpect.EOF:
274 main.log.error(self.name + ": EOF exception found")
275 main.log.error(self.name + ": " + self.handle.before)
276 main.cleanup()
277 main.exit()
278 except:
279 main.log.info(self.name+" ::::::")
280 main.log.error( traceback.print_exc())
281 main.log.info(self.name+" ::::::")
282 main.cleanup()
283 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400284
andrewonlab7c211572014-10-15 16:45:20 -0400285 def nodes(self):
286 '''
287 List the nodes currently visible
288 Issues command: 'nodes'
289 Returns: entire handle of list of nodes
290 '''
291 try:
292 self.handle.sendline("")
293 self.handle.expect("onos>")
294
295 self.handle.sendline("nodes")
296 self.handle.expect("onos>")
297
298 self.handle.sendline("")
299 self.handle.expect("onos>")
300
301 handle = self.handle.before
302
303 return handle
304
305 except pexpect.EOF:
306 main.log.error(self.name + ": EOF exception found")
307 main.log.error(self.name + ": " + self.handle.before)
308 main.cleanup()
309 main.exit()
310 except:
311 main.log.info(self.name+" ::::::")
312 main.log.error( traceback.print_exc())
313 main.log.info(self.name+" ::::::")
314 main.cleanup()
315 main.exit()
316
andrewonlab38d6ae22014-10-15 14:23:45 -0400317 def topology(self):
andrewonlabc2d05aa2014-10-13 16:51:10 -0400318 '''
319 Shows the current state of the topology
320 by issusing command: 'onos> onos:topology'
321 '''
andrewonlab95ce8322014-10-13 14:12:04 -0400322 try:
323 self.handle.sendline("")
324 self.handle.expect("onos>")
andrewonlab38d6ae22014-10-15 14:23:45 -0400325 #either onos:topology or 'topology' will work in CLI
andrewonlab95ce8322014-10-13 14:12:04 -0400326 self.handle.sendline("onos:topology")
327 self.handle.expect("onos>")
328
329 handle = self.handle.before
330
331 main.log.info("onos:topology returned: " +
332 str(handle))
333
334 return handle
335
336 except pexpect.EOF:
337 main.log.error(self.name + ": EOF exception found")
338 main.log.error(self.name + ": " + self.handle.before)
339 main.cleanup()
340 main.exit()
341 except:
342 main.log.info(self.name+" ::::::")
343 main.log.error( traceback.print_exc())
344 main.log.info(self.name+" ::::::")
345 main.cleanup()
346 main.exit()
andrewonlabc2d05aa2014-10-13 16:51:10 -0400347
348 def feature_install(self, feature_str):
349 '''
350 Installs a specified feature
351 by issuing command: 'onos> feature:install <feature_str>'
352 '''
353 try:
354 self.handle.sendline("")
355 self.handle.expect("onos>")
356
357 self.handle.sendline("feature:install "+str(feature_str))
358 self.handle.expect("onos>")
359
360 return main.TRUE
361
362 except pexpect.EOF:
363 main.log.error(self.name + ": EOF exception found")
364 main.log.error(self.name + ": " + self.handle.before)
365 main.cleanup()
366 main.exit()
367 except:
368 main.log.info(self.name+" ::::::")
369 main.log.error( traceback.print_exc())
370 main.log.info(self.name+" ::::::")
371 main.cleanup()
372 main.exit()
373
374 def feature_uninstall(self, feature_str):
375 '''
376 Uninstalls a specified feature
377 by issuing command: 'onos> feature:uninstall <feature_str>'
378 '''
379 try:
380 self.handle.sendline("")
381 self.handle.expect("onos>")
382
383 self.handle.sendline("feature:uninstall "+str(feature_str))
384 self.handle.expect("onos>")
385
386 return main.TRUE
387
388 except pexpect.EOF:
389 main.log.error(self.name + ": EOF exception found")
390 main.log.error(self.name + ": " + self.handle.before)
391 main.cleanup()
392 main.exit()
393 except:
394 main.log.info(self.name+" ::::::")
395 main.log.error( traceback.print_exc())
396 main.log.info(self.name+" ::::::")
397 main.cleanup()
398 main.exit()
andrewonlab95ce8322014-10-13 14:12:04 -0400399
Jon Halle8217482014-10-17 13:49:14 -0400400 def devices(self, json_format=True, grep_str=""):
andrewonlab86dc3082014-10-13 18:18:38 -0400401 '''
402 Lists all infrastructure devices
403 Optional argument:
404 * grep_str - pass in a string to grep
405 '''
406 try:
407 self.handle.sendline("")
408 self.handle.expect("onos>")
Jon Halle8217482014-10-17 13:49:14 -0400409
410 if json_format:
411 if not grep_str:
412 self.handle.sendline("devices -j")
413 self.handle.expect("devices -j")
414 self.handle.expect("onos>")
415 else:
416 self.handle.sendline("devices -j | grep '"+
andrewonlab86dc3082014-10-13 18:18:38 -0400417 str(grep_str)+"'")
Jon Halle8217482014-10-17 13:49:14 -0400418 self.handle.expect("devices -j | grep '"+str(grep_str)+"'")
419 self.handle.expect("onos>")
Jon Halla001c392014-10-17 18:50:59 -0400420 handle = self.handle.before
421 print "repr(handle) =", repr(handle)
422 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
423 handle1 = ansi_escape.sub('', handle)
424 print "repr(handle1) = ", repr(handle1)
425 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400426 else:
427 if not grep_str:
428 self.handle.sendline("devices")
429 self.handle.expect("devices")
430 self.handle.expect("onos>")
431 else:
432 self.handle.sendline("devices | grep '"+
433 str(grep_str)+"'")
434 self.handle.expect("devices | grep '"+str(grep_str)+"'")
435 self.handle.expect("onos>")
Jon Halla001c392014-10-17 18:50:59 -0400436 handle = self.handle.before
437 print "handle =",handle
438 return handle
andrewonlab7c211572014-10-15 16:45:20 -0400439 except pexpect.EOF:
440 main.log.error(self.name + ": EOF exception found")
441 main.log.error(self.name + ": " + self.handle.before)
442 main.cleanup()
443 main.exit()
444 except:
445 main.log.info(self.name+" ::::::")
446 main.log.error( traceback.print_exc())
447 main.log.info(self.name+" ::::::")
448 main.cleanup()
449 main.exit()
450
Jon Halle8217482014-10-17 13:49:14 -0400451
452 def links(self, json_format=True, grep_str=""):
453 '''
454 Lists all core links
455 Optional argument:
456 * grep_str - pass in a string to grep
457 '''
458 try:
459 self.handle.sendline("")
460 self.handle.expect("onos>")
461
462 if json_format:
463 if not grep_str:
464 self.handle.sendline("links -j")
465 self.handle.expect("links -j")
466 self.handle.expect("onos>")
467 else:
468 self.handle.sendline("links -j | grep '"+
469 str(grep_str)+"'")
470 self.handle.expect("links -j | grep '"+str(grep_str)+"'")
471 self.handle.expect("onos>")
Jon Halla001c392014-10-17 18:50:59 -0400472 handle = self.handle.before
473 print "repr(handle) =", repr(handle)
474 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
475 handle1 = ansi_escape.sub('', handle)
476 print "repr(handle1) = ", repr(handle1)
477 return handle1
Jon Halle8217482014-10-17 13:49:14 -0400478 else:
479 if not grep_str:
480 self.handle.sendline("links")
481 self.handle.expect("links")
482 self.handle.expect("onos>")
483 else:
484 self.handle.sendline("links | grep '"+
485 str(grep_str)+"'")
486 self.handle.expect("links | grep '"+str(grep_str)+"'")
487 self.handle.expect("onos>")
488
Jon Halla001c392014-10-17 18:50:59 -0400489 handle = self.handle.before
490 print "handle =",handle
491 return handle
Jon Halle8217482014-10-17 13:49:14 -0400492 except pexpect.EOF:
493 main.log.error(self.name + ": EOF exception found")
494 main.log.error(self.name + ": " + self.handle.before)
495 main.cleanup()
496 main.exit()
497 except:
498 main.log.info(self.name+" ::::::")
499 main.log.error( traceback.print_exc())
500 main.log.info(self.name+" ::::::")
501 main.cleanup()
502 main.exit()
503
504
505 def ports(self, json_format=True, grep_str=""):
506 '''
507 Lists all ports
508 Optional argument:
509 * grep_str - pass in a string to grep
510 '''
511 try:
512 self.handle.sendline("")
513 self.handle.expect("onos>")
514
515 if json_format:
516 if not grep_str:
517 self.handle.sendline("ports -j")
518 self.handle.expect("ports -j")
519 self.handle.expect("onos>")
520 else:
521 self.handle.sendline("ports -j | grep '"+
522 str(grep_str)+"'")
523 self.handle.expect("ports -j | grep '"+str(grep_str)+"'")
524 self.handle.expect("onos>")
Jon Halla001c392014-10-17 18:50:59 -0400525 print "repr(handle) =", repr(handle)
526 ansi_escape = re.compile(r'\r\r\n\x1b[^m]*m')
527 handle1 = ansi_escape.sub('', handle)
528 print "repr(handle1) = ", repr(handle1)
529 return handle1
530
Jon Halle8217482014-10-17 13:49:14 -0400531 else:
532 if not grep_str:
533 self.handle.sendline("ports")
534 self.handle.expect("ports")
535 self.handle.expect("onos>")
536 else:
537 self.handle.sendline("ports | grep '"+
538 str(grep_str)+"'")
539 self.handle.expect("ports | grep '"+str(grep_str)+"'")
540 self.handle.expect("onos>")
Jon Halla001c392014-10-17 18:50:59 -0400541 handle = self.handle.before
542 print "handle =",handle
543 return handle
Jon Halle8217482014-10-17 13:49:14 -0400544 except pexpect.EOF:
545 main.log.error(self.name + ": EOF exception found")
546 main.log.error(self.name + ": " + self.handle.before)
547 main.cleanup()
548 main.exit()
549 except:
550 main.log.info(self.name+" ::::::")
551 main.log.error( traceback.print_exc())
552 main.log.info(self.name+" ::::::")
553 main.cleanup()
554 main.exit()
555
556
andrewonlab7c211572014-10-15 16:45:20 -0400557 def device_role(self, device_id, node_id, role):
558 '''
559 Set device role for specified device and node with role
560 Required:
561 * device_id : may be obtained by function get_all_devices_id
562 * node_id : may be obtained by function get_all_nodes_id
563 * role: specify one of the following roles:
564 - master
565 - standby
566 - none
567 '''
568 try:
569 self.handle.sendline("")
570 self.handle.expect("onos>")
571
572 self.handle.sendline("device-role "+
573 str(device_id) + " " +
574 str(node_id) + " " +
575 str(role))
576 i = self.handle.expect([
577 "Error",
578 "onos>"])
579
580 self.handle.sendline("")
581 self.handle.expect("onos>")
582
583 handle = self.handle.before
584
585 if i == 0:
586 main.log.error("device-role command returned error")
587 return handle
588 else:
589 return main.TRUE
590
andrewonlab86dc3082014-10-13 18:18:38 -0400591 except pexpect.EOF:
592 main.log.error(self.name + ": EOF exception found")
593 main.log.error(self.name + ": " + self.handle.before)
594 main.cleanup()
595 main.exit()
596 except:
597 main.log.info(self.name+" ::::::")
598 main.log.error( traceback.print_exc())
599 main.log.info(self.name+" ::::::")
600 main.cleanup()
601 main.exit()
andrewonlab2a6c9342014-10-16 13:40:15 -0400602
andrewonlab3e15ead2014-10-15 14:21:34 -0400603 def paths(self, src_id, dst_id):
604 '''
605 Returns string of paths, and the cost.
606 Issues command: onos:paths <src> <dst>
607 '''
608 try:
609 self.handle.sendline("")
610 self.handle.expect("onos>")
611
612 self.handle.sendline("onos:paths "+
613 str(src_id) + " " + str(dst_id))
614 i = self.handle.expect([
615 "Error",
616 "onos>"])
617
618 self.handle.sendline("")
619 self.handle.expect("onos>")
620
621 handle = self.handle.before
622
623 if i == 0:
624 main.log.error("Error in getting paths")
andrewonlab7c211572014-10-15 16:45:20 -0400625 return (handle, "Error")
andrewonlab3e15ead2014-10-15 14:21:34 -0400626 else:
627 path = handle.split(";")[0]
628 cost = handle.split(";")[1]
629 return (path, cost)
630
631 except pexpect.EOF:
632 main.log.error(self.name + ": EOF exception found")
633 main.log.error(self.name + ": " + self.handle.before)
634 main.cleanup()
635 main.exit()
636 except:
637 main.log.info(self.name+" ::::::")
638 main.log.error( traceback.print_exc())
639 main.log.info(self.name+" ::::::")
640 main.cleanup()
641 main.exit()
andrewonlab3f0a4af2014-10-17 12:25:14 -0400642
643 #TODO:
644 #def hosts(self):
645
646 def get_hosts_id(self, host_list):
647 '''
648 Obtain list of hosts
649 Issues command: 'onos> hosts'
650
651 Required:
652 * host_list: List of hosts obtained by Mininet
653 IMPORTANT:
654 This function assumes that you started your
655 topology with the option '--mac'.
656 Furthermore, it assumes that value of VLAN is '-1'
657 Description:
658 Converts mininet hosts (h1, h2, h3...) into
659 ONOS format (00:00:00:00:00:01/-1 , ...)
660 '''
661
662 try:
663 self.handle.sendline("")
664 self.handle.expect("onos>")
665
666 onos_host_list = []
667
668 for host in host_list:
669 host = host.replace("h", "")
670 host_hex = hex(int(host)).zfill(12)
671 host_hex = str(host_hex).replace('x','0')
672 i = iter(str(host_hex))
673 host_hex = ":".join(a+b for a,b in zip(i,i))
674 host_hex = host_hex + "/-1"
675 onos_host_list.append(host_hex)
676
677 return onos_host_list
678
679 except pexpect.EOF:
680 main.log.error(self.name + ": EOF exception found")
681 main.log.error(self.name + ": " + self.handle.before)
682 main.cleanup()
683 main.exit()
684 except:
685 main.log.info(self.name+" ::::::")
686 main.log.error( traceback.print_exc())
687 main.log.info(self.name+" ::::::")
688 main.cleanup()
689 main.exit()
andrewonlab3e15ead2014-10-15 14:21:34 -0400690
andrewonlab3e15ead2014-10-15 14:21:34 -0400691 #Wrapper functions ****************
andrewonlab7e4d2d32014-10-15 13:23:21 -0400692 #Wrapper functions use existing driver
693 #functions and extends their use case.
694 #For example, we may use the output of
695 #a normal driver function, and parse it
696 #using a wrapper function
andrewonlabc2d05aa2014-10-13 16:51:10 -0400697
andrewonlab7e4d2d32014-10-15 13:23:21 -0400698 def get_all_devices_id(self):
699 '''
700 Use 'devices' function to obtain list of all devices
701 and parse the result to obtain a list of all device
702 id's. Returns this list. Returns empty list if no
703 devices exist
704 List is ordered sequentially
andrewonlab3e15ead2014-10-15 14:21:34 -0400705
706 This function may be useful if you are not sure of the
707 device id, and wish to execute other commands using
708 the ids. By obtaining the list of device ids on the fly,
709 you can iterate through the list to get mastership, etc.
andrewonlab7e4d2d32014-10-15 13:23:21 -0400710 '''
711 try:
712 #Call devices and store result string
713 devices_str = self.devices()
714 id_list = []
715
716 if not devices_str:
717 main.log.info("There are no devices to get id from")
718 return id_list
719
720 #Split the string into list by comma
721 device_list = devices_str.split(",")
722 #Get temporary list of all arguments with string 'id='
723 temp_list = [dev for dev in device_list if "id=" in dev]
724 #Split list further into arguments before and after string
725 # 'id='. Get the latter portion (the actual device id) and
726 # append to id_list
727 for arg in temp_list:
728 id_list.append(arg.split("id=")[1])
729
730 return id_list
731
732 except pexpect.EOF:
733 main.log.error(self.name + ": EOF exception found")
734 main.log.error(self.name + ": " + self.handle.before)
735 main.cleanup()
736 main.exit()
737 except:
738 main.log.info(self.name+" ::::::")
739 main.log.error( traceback.print_exc())
740 main.log.info(self.name+" ::::::")
741 main.cleanup()
742 main.exit()
743
andrewonlab7c211572014-10-15 16:45:20 -0400744 def get_all_nodes_id(self):
745 '''
746 Uses 'nodes' function to obtain list of all nodes
747 and parse the result of nodes to obtain just the
748 node id's.
749 Returns:
750 list of node id's
751 '''
752 try:
753 nodes_str = self.nodes()
754 id_list = []
755
756 if not nodes_str:
757 main.log.info("There are no nodes to get id from")
758 return id_list
759
760 #Sample nodes_str output
761 #id=local, address=127.0.0.1:9876, state=ACTIVE *
762
763 #Split the string into list by comma
764 nodes_list = nodes_str.split(",")
765 temp_list = [node for node in nodes_list if "id=" in node]
766 for arg in temp_list:
767 id_list.append(arg.split("id=")[1])
768
769 return id_list
770
771 except pexpect.EOF:
772 main.log.error(self.name + ": EOF exception found")
773 main.log.error(self.name + ": " + self.handle.before)
774 main.cleanup()
775 main.exit()
776 except:
777 main.log.info(self.name+" ::::::")
778 main.log.error( traceback.print_exc())
779 main.log.info(self.name+" ::::::")
780 main.cleanup()
781 main.exit()
andrewonlab7e4d2d32014-10-15 13:23:21 -0400782
783 #***********************************