From f82c99ace0838a1254eb9e16c0abdc4e1ff0b14a Mon Sep 17 00:00:00 2001 From: kwanhur Date: Sun, 20 Mar 2022 16:37:56 +0800 Subject: [PATCH] feat: subcommand flush Signed-off-by: kwanhur --- CHANGELOG.md | 2 +- README.md | 24 +++++++++++++++++++++--- command.go | 10 +++++++++- operation.go | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbad7f9..79e41cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- ipvsctl sub-command `daemon`, `local-address`, `connection` +- ipvsctl sub-command `daemon`, `flush`, `local-address`, `connection` - support import from stdin, compatible with ipvsadm dump format ## [v1.0.0] - 2022-03-19 diff --git a/README.md b/README.md index 5a7d433..9ce5eb3 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ A modern Linux Virtual Server controller. ## Description -`ipvsctl` is similar to `ipvsadm`, `ipvsctl` support multiple modern operations, include sub-commands `service`, `server`, `timeout`, `zero`, `daemon`. +`ipvsctl` is similar to `ipvsadm`, `ipvsctl` support multiple modern operations, include sub-commands `service`, `server`, `timeout`, `daemon`, `zero`, `flush`. ## Commands @@ -54,6 +54,7 @@ AUTHOR: COMMANDS: zero, z Zero ipvs all the virtual service stats(byte packet and rate counters) + flush, f, clear Flush out the virtual server table service, s, svc, vs Operates virtual service[vip:vport protocol] (TCP UDP STCP)/(IPv4 IPv6) server, ser, svr, d, dst, dest, destination, rs, realserver Operates real server[rip:rport] (IPv4/IPv6) timeout, t, to, out Operates timeout (tcp tcpfin udp) @@ -88,7 +89,7 @@ COMMANDS: update, u, up Update ipvs virtual service del, d, delete Del ipvs virtual service zero, z Zero ipvs virtual server stats(byte packet and rate counters) - flush, f, clear Flush ipvs, all the rules will be clear + flush, f, clear Flush out the virtual server table help, h Shows a list of commands or help for one command OPTIONS: @@ -469,6 +470,23 @@ OPTIONS: --help, -h show help (default: false) ``` +### Flush + +It's used to clear out the virtual server table. + +```shell +./ipvsctl flush -h +NAME: + ipvsctl flush - Flush out the virtual server table + +USAGE: + ipvsctl flush [command options] [arguments...] + +OPTIONS: + --yes, --force, -f, -y Are you agree to do it?[yes/no] (default: false) + --help, -h show help (default: false) +``` + ### Daemon The connection synchronization daemon is implemented inside the Linux kernel. The master daemon running at the primary load balancer multicasts changes of @@ -532,7 +550,7 @@ OPTIONS: --help, -h show help (default: false) ``` -#### Del Daemon +#### Delete Daemon Stop the connection synchronization daemon. diff --git a/command.go b/command.go index a08cc29..42ce158 100644 --- a/command.go +++ b/command.go @@ -115,6 +115,13 @@ func (o *Operator) BasicCommands() []*cli.Command { Action: o.Zero(), Flags: flags, }, + { + Name: "flush", + Aliases: []string{"f", "clear"}, + Usage: "Flush out the virtual server table", + Action: o.FlushService(), + Flags: flags, + }, } } @@ -186,8 +193,9 @@ func (o *Operator) ServiceCommands() []*cli.Command { { Name: "flush", Aliases: []string{"f", "clear"}, - Usage: "Flush ipvs, all the rules will be clear", + Usage: "Flush out the virtual server table", Action: o.FlushService(), + Flags: flags, }, }, }, diff --git a/operation.go b/operation.go index d85957d..f2d19f4 100644 --- a/operation.go +++ b/operation.go @@ -352,7 +352,7 @@ func (o *Operator) ZeroService() cli.ActionFunc { } } -// FlushService clear out all of the Linux virtual table +// FlushService clear out all the Linux virtual table func (o *Operator) FlushService() cli.ActionFunc { return func(c *cli.Context) error { o.ctx = c