mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
support flush services API
Signed-off-by: m1093782566 <dujun5@huawei.com>
This commit is contained in:
parent
6b3ec6b965
commit
89aeeb294c
3 changed files with 49 additions and 0 deletions
|
@ -116,6 +116,13 @@ func (i *Handle) DelService(s *Service) error {
|
|||
return i.doCmd(s, nil, ipvsCmdDelService)
|
||||
}
|
||||
|
||||
// Flush deletes all existing services in the passed
|
||||
// handle.
|
||||
func (i *Handle) Flush() error {
|
||||
_, err := i.doCmdWithoutAttr(ipvsCmdFlush)
|
||||
return err
|
||||
}
|
||||
|
||||
// NewDestination creates a new real server in the passed ipvs
|
||||
// service which should already be existing in the passed handle.
|
||||
func (i *Handle) NewDestination(s *Service, d *Destination) error {
|
||||
|
|
|
@ -178,6 +178,41 @@ func TestService(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
svcs := []Service{
|
||||
{
|
||||
AddressFamily: nl.FAMILY_V4,
|
||||
SchedName: RoundRobin,
|
||||
Protocol: syscall.IPPROTO_TCP,
|
||||
Port: 80,
|
||||
Address: net.ParseIP("10.20.30.40"),
|
||||
Netmask: 0xFFFFFFFF,
|
||||
},
|
||||
{
|
||||
AddressFamily: nl.FAMILY_V4,
|
||||
SchedName: LeastConnection,
|
||||
Protocol: syscall.IPPROTO_UDP,
|
||||
Port: 8080,
|
||||
Address: net.ParseIP("10.20.30.41"),
|
||||
Netmask: 0xFFFFFFFF,
|
||||
},
|
||||
}
|
||||
// Create services for testing flush
|
||||
for _, svc := range svcs {
|
||||
if !i.IsServicePresent(&svc) {
|
||||
err = i.NewService(&svc)
|
||||
assert.NoError(t, err)
|
||||
checkService(t, i, &svc, true)
|
||||
} else {
|
||||
t.Errorf("svc: %v exists", svc)
|
||||
}
|
||||
}
|
||||
err = i.Flush()
|
||||
assert.NoError(t, err)
|
||||
got, err := i.GetServices()
|
||||
assert.NoError(t, err)
|
||||
if len(got) != 0 {
|
||||
t.Errorf("Unexpected services after flush")
|
||||
}
|
||||
}
|
||||
|
||||
func createDummyInterface(t *testing.T) {
|
||||
|
|
|
@ -402,6 +402,13 @@ func (i *Handle) doGetServicesCmd(svc *Service) ([]*Service, error) {
|
|||
return res, nil
|
||||
}
|
||||
|
||||
// doCmdWithoutAttr a simple wrapper of netlink socket execute command
|
||||
func (i *Handle) doCmdWithoutAttr(cmd uint8) ([][]byte, error) {
|
||||
req := newIPVSRequest(cmd)
|
||||
req.Seq = atomic.AddUint32(&i.seq, 1)
|
||||
return execute(i.sock, req, 0)
|
||||
}
|
||||
|
||||
func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error) {
|
||||
|
||||
var d Destination
|
||||
|
|
Loading…
Reference in a new issue