@@ -24,6 +24,7 @@ import (
2424
2525 "github.com/cea-hpc/sshproxy/pkg/utils"
2626
27+ "github.com/iskylite/nodeset"
2728 "github.com/olekukonko/tablewriter"
2829)
2930
@@ -502,7 +503,8 @@ func newEnableParser() *flag.FlagSet {
502503 fs .Usage = func () {
503504 fmt .Fprintf (flag .CommandLine .Output (), `Usage: %s enable HOST [PORT]
504505
505- Enable a previously disabled host in etcd. The default port is %s.
506+ Enable a previously disabled host in etcd. The default port is %s. Host and port
507+ can be nodesets.
506508` , os .Args [0 ], defaultHostPort )
507509 os .Exit (2 )
508510 }
@@ -515,7 +517,7 @@ func newForgetParser() *flag.FlagSet {
515517 fmt .Fprintf (flag .CommandLine .Output (), `Usage: %s forget HOST [PORT]
516518
517519Forget a host in etcd. The default port is %s. Remember that if this host is
518- used, it will appear back in the list.
520+ used, it will appear back in the list. Host and port can be nodesets.
519521` , os .Args [0 ], defaultHostPort )
520522 os .Exit (2 )
521523 }
@@ -527,7 +529,7 @@ func newDisableParser() *flag.FlagSet {
527529 fs .Usage = func () {
528530 fmt .Fprintf (flag .CommandLine .Output (), `Usage: %s disable HOST [PORT]
529531
530- Disabe a host in etcd. The default port is %s.
532+ Disabe a host in etcd. The default port is %s. Host and port can be nodesets.
531533` , os .Args [0 ], defaultHostPort )
532534 os .Exit (2 )
533535 }
@@ -550,25 +552,37 @@ The options are:
550552 return fs
551553}
552554
553- func getHostPortFromCommandLine (args []string ) (string , string , error ) {
554- host , port := "" , defaultHostPort
555+ func getHostPortFromCommandLine (args []string ) ([] string , [] string , error ) {
556+ hostsNodeset , portsNodeset := "" , defaultHostPort
555557 switch len (args ) {
556558 case 2 :
557- host , port = args [0 ], args [1 ]
559+ hostsNodeset , portsNodeset = args [0 ], args [1 ]
558560 case 1 :
559- host = args [0 ]
561+ hostsNodeset = args [0 ]
560562 default :
561- return "" , "" , fmt .Errorf ("wrong number of arguments" )
563+ return [] string {}, [] string {} , fmt .Errorf ("wrong number of arguments" )
562564 }
563- if iport , err := strconv .Atoi (port ); err != nil {
564- return "" , "" , fmt .Errorf ("port must be an integer" )
565- } else if iport < 0 || iport > 65535 {
566- return "" , "" , fmt .Errorf ("port must be in the 0-65535 range" )
565+ hosts , err := nodeset .Expand (hostsNodeset )
566+ if err != nil {
567+ return []string {}, []string {}, fmt .Errorf ("%s" , err )
568+ }
569+ ports , err := nodeset .Expand (portsNodeset )
570+ if err != nil {
571+ return []string {}, []string {}, fmt .Errorf ("%s" , err )
567572 }
568- if _ , _ , err := net .SplitHostPort (host + ":" + port ); err != nil {
569- return "" , "" , fmt .Errorf ("%s" , err )
573+ for _ , port := range ports {
574+ if iport , err := strconv .Atoi (port ); err != nil {
575+ return []string {}, []string {}, fmt .Errorf ("port \" %s\" must be an integer" , port )
576+ } else if iport < 0 || iport > 65535 {
577+ return []string {}, []string {}, fmt .Errorf ("port \" %s\" must be in the 0-65535 range" , port )
578+ }
579+ for _ , host := range hosts {
580+ if _ , _ , err := net .SplitHostPort (host + ":" + port ); err != nil {
581+ return []string {}, []string {}, fmt .Errorf ("%s" , err )
582+ }
583+ }
570584 }
571- return host , port , nil
585+ return hosts , ports , nil
572586}
573587
574588func getErrorBannerFromCommandLine (args []string ) (string , error ) {
@@ -691,30 +705,42 @@ func main() {
691705 case "enable" :
692706 p := parsers [cmd ]
693707 p .Parse (args )
694- host , port , err := getHostPortFromCommandLine (p .Args ())
708+ hosts , ports , err := getHostPortFromCommandLine (p .Args ())
695709 if err != nil {
696710 fmt .Fprintf (os .Stderr , "ERROR: %s\n \n " , err )
697711 p .Usage ()
698712 }
699- enableHost (host , port , * configFile )
713+ for _ , host := range hosts {
714+ for _ , port := range ports {
715+ enableHost (host , port , * configFile )
716+ }
717+ }
700718 case "forget" :
701719 p := parsers [cmd ]
702720 p .Parse (args )
703- host , port , err := getHostPortFromCommandLine (p .Args ())
721+ hosts , ports , err := getHostPortFromCommandLine (p .Args ())
704722 if err != nil {
705723 fmt .Fprintf (os .Stderr , "ERROR: %s\n \n " , err )
706724 p .Usage ()
707725 }
708- forgetHost (host , port , * configFile )
726+ for _ , host := range hosts {
727+ for _ , port := range ports {
728+ forgetHost (host , port , * configFile )
729+ }
730+ }
709731 case "disable" :
710732 p := parsers [cmd ]
711733 p .Parse (args )
712- host , port , err := getHostPortFromCommandLine (p .Args ())
734+ hosts , ports , err := getHostPortFromCommandLine (p .Args ())
713735 if err != nil {
714736 fmt .Fprintf (os .Stderr , "ERROR: %s\n \n " , err )
715737 p .Usage ()
716738 }
717- disableHost (host , port , * configFile )
739+ for _ , host := range hosts {
740+ for _ , port := range ports {
741+ disableHost (host , port , * configFile )
742+ }
743+ }
718744 case "error_banner" :
719745 p := parsers [cmd ]
720746 p .Parse (args )
0 commit comments