Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2051 from /issues/2046-static-ip
Browse files Browse the repository at this point in the history
Fix plugin accepting --ip address
  • Loading branch information
awh committed Mar 16, 2016
2 parents 4eaeb0f + eee77d4 commit 4b5fb27
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions api/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (client *Client) LookupIP(ID string) (*net.IPNet, error) {
}

// Claim a specific IP on behalf of the ID
func (client *Client) ClaimIP(ID string, addr net.IP) error {
_, err := client.httpVerb("PUT", fmt.Sprintf("/ip/%s/%s", ID, addr), nil)
func (client *Client) ClaimIP(ID string, cidr *net.IPNet) error {
_, err := client.httpVerb("PUT", fmt.Sprintf("/ip/%s/%s", ID, cidr), nil)
return err
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/ipam/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (i *ipam) RequestAddress(poolID string, address net.IP, options map[string]
return
}
if address != nil { // try to claim specific address requested
if err = i.weave.ClaimIP("_", address); err != nil {
ip = &net.IPNet{IP: address, Mask: subnet.Mask}
if err = i.weave.ClaimIP("_", ip); err != nil {
return
}
ip = &net.IPNet{IP: address, Mask: subnet.Mask}
} else {
if _, iprange, err = net.ParseCIDR(parts[2]); err != nil {
return
Expand Down
20 changes: 20 additions & 0 deletions test/820_plugin_subnet_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash

. ./config.sh

start_suite "Test Docker Network plugin with specified subnet"

weave_on $HOST1 launch

# using ssh rather than docker -H because CircleCI docker client is older
$SSH $HOST1 docker network create --driver weavemesh --ipam-driver weavemesh --subnet 10.40.0.0/16 testsubnet

$SSH $HOST1 docker run --name=c1 -dt --net=testsubnet --ip 10.40.0.1 $SMALL_IMAGE /bin/sh
$SSH $HOST1 docker run --name=c2 -dt --net=testsubnet $SMALL_IMAGE /bin/sh

assert "container_ip $HOST1 c1" "10.40.0.1"
assert "container_ip $HOST1 c2" "10.40.0.2" # assuming linear allocation strategy
assert_raises "exec_on $HOST1 c1 $PING c2"
assert_raises "exec_on $HOST1 c2 $PING c1"

end_suite

0 comments on commit 4b5fb27

Please sign in to comment.