@@ -393,7 +393,9 @@ When the username is specified by the "-u" option, only the VNCs owned by the us
393
393
394
394
// filling access node hosts
395
395
go func () {
396
- var mlist []string
396
+
397
+ // counter for number of nodes to visit
398
+ mcnt := 0
397
399
398
400
// 1. read machinelist from user provided hosts from commandline arguments
399
401
sort .Strings (args )
@@ -402,11 +404,12 @@ When the username is specified by the "-u" option, only the VNCs owned by the us
402
404
n = fmt .Sprintf ("%s.%s" , n , NetDomain )
403
405
}
404
406
log .Debugf ("add node %s\n " , n )
405
- mlist = append (mlist , n )
407
+ nodes <- n
408
+ mcnt ++
406
409
}
407
410
408
411
// 2. read machinelist from the machinelist file
409
- if len ( mlist ) == 0 {
412
+ if mcnt == 0 {
410
413
// read nodes from user provided machinelist
411
414
412
415
if fml , err := os .Open (vncMachineListFile ); err == nil {
@@ -417,7 +420,8 @@ When the username is specified by the "-u" option, only the VNCs owned by the us
417
420
if ! strings .HasSuffix (n , fmt .Sprintf (".%s" , NetDomain )) {
418
421
n = fmt .Sprintf ("%s.%s" , n , NetDomain )
419
422
}
420
- mlist = append (mlist , n )
423
+ nodes <- n
424
+ mcnt ++
421
425
}
422
426
423
427
if err := scanner .Err (); err != nil {
@@ -429,7 +433,7 @@ When the username is specified by the "-u" option, only the VNCs owned by the us
429
433
}
430
434
431
435
// 3. read machinelist from the Gangalia
432
- if len ( mlist ) == 0 {
436
+ if mcnt == 0 {
433
437
// TODO: append hostname of all of the access nodes.
434
438
accs , err := dg .GetAccessNodes ()
435
439
// sort nodes
@@ -438,28 +442,20 @@ When the username is specified by the "-u" option, only the VNCs owned by the us
438
442
log .Errorln (err )
439
443
}
440
444
441
- mlist = append (mlist , accs ... )
445
+ for _ , n := range accs {
446
+ nodes <- n
447
+ }
442
448
}
443
449
444
- // fill mlist to node channel
445
- for _ , n := range mlist {
446
- nodes <- n
447
- }
450
+ // close the nodes channel
448
451
close (nodes )
449
452
}()
450
453
451
454
// reorganise internal data structure for sorting
452
455
var _vncs []trqhelper.VNCServer
453
- for d := range vncservers {
454
- _vncs = append (_vncs , d )
455
- }
456
-
457
- // sort _vncs and make tabluar display on stdout
458
- table := tablewriter .NewWriter (os .Stdout )
459
- table .SetHeader ([]string {"Username" , "VNC session" })
460
-
461
- sort .Slice (_vncs , func (i , j int ) bool {
462
456
457
+ // function for sorting VNC sessions by host.
458
+ vncSortByHost := func (i , j int ) bool {
463
459
datai := strings .Split (_vncs [i ].ID , ":" )
464
460
dataj := strings .Split (_vncs [j ].ID , ":" )
465
461
@@ -474,8 +470,17 @@ When the username is specified by the "-u" option, only the VNCs owned by the us
474
470
idj , _ := strconv .ParseUint (dataj [1 ], 10 , 32 )
475
471
476
472
return idi < idj
477
- })
473
+ }
474
+
475
+ for d := range vncservers {
476
+ _vncs = append (_vncs , d )
477
+ // perform sorting when a vnc session is added to the list.
478
+ sort .Slice (_vncs , vncSortByHost )
479
+ }
478
480
481
+ // sort _vncs and make tabluar display on stdout
482
+ table := tablewriter .NewWriter (os .Stdout )
483
+ table .SetHeader ([]string {"Username" , "VNC session" })
479
484
for _ , vnc := range _vncs {
480
485
table .Append ([]string {vnc .Owner , vnc .ID })
481
486
}
0 commit comments