Skip to content

Commit

Permalink
dnslb-ctl: add block subcommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgooch committed Apr 8, 2021
1 parent 18911d4 commit c952132
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd/dnslb-ctl/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/Cloud-Foundations/Dominator/lib/log"
"github.com/Cloud-Foundations/golib/pkg/loadbalancing/dnslb/config"
)

func blockSubcommand(args []string, logger log.DebugLogger) error {
if err := block(args[0], logger); err != nil {
return fmt.Errorf("Error blocking IP: %s: %s", args[0], err)
}
return nil
}

func block(ip string, logger log.DebugLogger) error {
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM)
cancelChannel := make(chan struct{}, 1)
go func() {
<-signalChannel
logger.Println("caught signal: cleaning up gracefully")
cancelChannel <- struct{}{}
}()
return config.Block(cfgData, ip, *blockDuration, cancelChannel, logger)
}
4 changes: 4 additions & 0 deletions cmd/dnslb-ctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"time"

"github.com/Cloud-Foundations/Dominator/lib/decoders"
"github.com/Cloud-Foundations/Dominator/lib/flags/commands"
Expand All @@ -16,6 +17,8 @@ import (
)

var (
blockDuration = flag.Duration("blockDuration", time.Minute*15,
"Duration to block")
configFile = flag.String("configFile", "",
"Name of file containing configuration")

Expand All @@ -38,6 +41,7 @@ func printUsage() {
var subcommands = []commands.Command{
{"rolling-replace", "region...", 1, 3,
rollingReplaceSubcommand},
{"block", "IP", 1, 1, blockSubcommand},
}

func doMain() int {
Expand Down

0 comments on commit c952132

Please sign in to comment.