diff --git a/build b/build index b0f3724..2f19a2e 100755 --- a/build +++ b/build @@ -37,7 +37,7 @@ echo "Building metadatasvc..." go build -o $GOBIN/metadatasvc ${REPO_PATH}/metadatasvc echo "Building network plugins" -for d in network/plugins/*; do +for d in networking/plugins/*; do plugin=$(basename $d) echo " " $plugin go build -o $GOBIN/$plugin ${REPO_PATH}/$d diff --git a/network/ipam/ipam.go b/networking/ipam/ipam.go similarity index 90% rename from network/ipam/ipam.go rename to networking/ipam/ipam.go index 5804f39..2c4b220 100644 --- a/network/ipam/ipam.go +++ b/networking/ipam/ipam.go @@ -11,7 +11,9 @@ import ( "net" "strings" - "github.com/coreos/rocket/network/util" + "github.com/appc/spec/schema/types" + + "github.com/coreos/rocket/networking/util" ) type options struct { @@ -89,7 +91,7 @@ func parseArgs(args string) (*options, error) { return opts, nil } -func AllocIP(contID, netConf, ifName, args string) (*net.IPNet, net.IP, error) { +func AllocIP(contID types.UUID, netConf, ifName, args string) (*net.IPNet, net.IP, error) { opts, err := parseArgs(args) if err != nil { return nil, nil, err @@ -129,6 +131,6 @@ func AllocIP(contID, netConf, ifName, args string) (*net.IPNet, net.IP, error) { } } -func DeallocIP(contID, netConf, ifName string, ipn *net.IPNet) error { +func DeallocIP(contID types.UUID, netConf, ifName string, ipn *net.IPNet) error { return nil } diff --git a/network/net-plugin.go b/networking/net-plugin.go similarity index 76% rename from network/net-plugin.go rename to networking/net-plugin.go index e8f0482..816677b 100644 --- a/network/net-plugin.go +++ b/networking/net-plugin.go @@ -12,7 +12,9 @@ import ( "path/filepath" "strings" - "github.com/coreos/rocket/network/util" + "github.com/appc/spec/schema/types" + + "github.com/coreos/rocket/networking/util" ) type NetPlugin struct { @@ -60,7 +62,7 @@ func LoadNetPlugins() (map[string]*NetPlugin, error) { npPath := filepath.Join(RktNetPluginsPath, dent.Name()) np, err := LoadNetPlugin(npPath) if err != nil { - log.Printf("Loading %v: %v", npPath, err) + log.Printf("Error loading %v: %v", npPath, err) continue } @@ -70,17 +72,17 @@ func LoadNetPlugins() (map[string]*NetPlugin, error) { return plugins, nil } -func (np *NetPlugin) Add(n *Net, contID, netns, args, ifName string) (*net.IPNet, error) { +func (np *NetPlugin) Add(n *Net, contID types.UUID, netns, args, ifName string) (*net.IPNet, error) { switch { case np.Endpoint != "": - return nil, execHTTP(np.Endpoint, "add", n.Name, contID, netns, n.Filename, args, ifName) + return nil, execHTTP(np.Endpoint, "add", n.Name, contID.String(), netns, n.Filename, args, ifName) default: if len(np.Command.Add) == 0 { return nil, fmt.Errorf("plugin does not define command.add") } - output, err := execCmd(np.Command.Add, n.Name, contID, netns, n.Filename, args, ifName) + output, err := execCmd(np.Command.Add, n.Name, contID.String(), netns, n.Filename, args, ifName) if err != nil { return nil, err } @@ -91,17 +93,17 @@ func (np *NetPlugin) Add(n *Net, contID, netns, args, ifName string) (*net.IPNet } } -func (np *NetPlugin) Del(n *Net, contID, netns, args, ifName string) error { +func (np *NetPlugin) Del(n *Net, contID types.UUID, netns, args, ifName string) error { switch { case np.Endpoint != "": - return execHTTP(np.Endpoint, "del", n.Name, contID, netns, n.Filename, args, ifName) + return execHTTP(np.Endpoint, "del", n.Name, contID.String(), netns, n.Filename, args, ifName) default: if len(np.Command.Del) == 0 { return fmt.Errorf("plugin does not define command.del") } - _, err := execCmd(np.Command.Del, n.Name, contID, netns, n.Filename, args, ifName) + _, err := execCmd(np.Command.Del, n.Name, contID.String(), netns, n.Filename, args, ifName) return err } } @@ -121,8 +123,8 @@ func execCmd(cmd []string, netName, contID, netns, confFile, args, ifName string replaceAll(cmd, "{cont-id}", contID) replaceAll(cmd, "{netns}", netns) replaceAll(cmd, "{conf-file}", confFile) - replaceAll(cmd, "{args}", args) replaceAll(cmd, "{if-name}", ifName) + replaceAll(cmd, "{args}", args) stdout := &bytes.Buffer{} diff --git a/network/net.go b/networking/net.go similarity index 74% rename from network/net.go rename to networking/net.go index c402d60..a554b82 100644 --- a/network/net.go +++ b/networking/net.go @@ -1,33 +1,28 @@ package network import ( - "fmt" "io/ioutil" "log" "os" "path" - "github.com/coreos/rocket/network/util" + "github.com/coreos/rocket/networking/util" ) -const RktNetPath = "/etc/rkt-net.conf.d" -const DefaultIPNet = "172.16.28.0/24" - type Net struct { util.Net args string } -var defaultNet Net +const RktNetPath = "/etc/rkt-net.conf.d" +const DefaultIPNet = "172.16.28.0/24" -func init() { - defaultNet = Net{ - Net: util.Net{ - Name: "default", - Type: "veth", - }, - args: fmt.Sprintf("default,iprange=%v", DefaultIPNet), - } +var defaultNet = Net{ + Net: util.Net{ + Name: "default", + Type: "veth", + }, + args: "default,iprange=" + DefaultIPNet, } func LoadNets() ([]Net, error) { @@ -59,5 +54,4 @@ func LoadNets() ([]Net, error) { nets = append(nets, defaultNet) - return nets, nil -} + return nets, nil } diff --git a/network/network.go b/networking/networking.go similarity index 89% rename from network/network.go rename to networking/networking.go index 23d674a..e4975a3 100644 --- a/network/network.go +++ b/networking/networking.go @@ -11,7 +11,7 @@ import ( "github.com/appc/spec/schema/types" "github.com/coreos/rocket/Godeps/_workspace/src/github.com/vishvananda/netlink" - "github.com/coreos/rocket/network/util" + "github.com/coreos/rocket/networking/util" ) const ( @@ -25,7 +25,7 @@ type activeNet struct { ipn *net.IPNet } -type Network struct { +type Networking struct { MetadataIP net.IP contID types.UUID @@ -36,9 +36,9 @@ type Network struct { plugins map[string]*NetPlugin } -func Setup(contID types.UUID) (*Network, error) { +func Setup(contID types.UUID) (*Networking, error) { var err error - n := Network{contID: contID} + n := Networking{contID: contID} defer func() { // cleanup on error @@ -82,7 +82,7 @@ func Setup(contID types.UUID) (*Network, error) { return &n, nil } -func (n *Network) Teardown() { +func (n *Networking) Teardown() { // teardown everything in reverse order of setup. // this is called during error case as well so not // everything maybe setup. @@ -128,11 +128,11 @@ func basicNetNS() (hostNS, contNS *os.File, err error) { } -func (n *Network) EnterHostNS() error { +func (n *Networking) EnterHostNS() error { return util.SetNS(n.hostNS, syscall.CLONE_NEWNET) } -func (n *Network) EnterContNS() error { +func (n *Networking) EnterContNS() error { return util.SetNS(n.contNS, syscall.CLONE_NEWNET) } @@ -144,7 +144,7 @@ func setupNets(contID types.UUID, netns string, plugins map[string]*NetPlugin, n for i, nt := range nets { plugin, ok := plugins[nt.Type] if !ok { - err = fmt.Errorf("could not find network plugin %q\n", nt.Type) + err = fmt.Errorf("could not find network plugin %q", nt.Type) break } @@ -155,9 +155,9 @@ func setupNets(contID types.UUID, netns string, plugins map[string]*NetPlugin, n log.Printf("Executing net-plugin %v", nt.Type) - an.ipn, err = plugin.Add(&nt, contID.String(), netns, nt.args, an.ifName) + an.ipn, err = plugin.Add(&nt, contID, netns, nt.args, an.ifName) if err != nil { - err = fmt.Errorf("error adding network %q: %v\n", nt.Name, err) + err = fmt.Errorf("error adding network %q: %v", nt.Name, err) break } @@ -179,7 +179,7 @@ func teardownNets(contID types.UUID, netns string, plugins map[string]*NetPlugin nt := nets[i] plugin := plugins[nt.Type] - err := plugin.Del(&nt.Net, contID.String(), netns, nt.args, nt.ifName) + err := plugin.Del(&nt.Net, contID, netns, nt.args, nt.ifName) if err != nil { log.Printf("Error deleting %q: %v", nt.Name, err) } diff --git a/network/plugins/bridge/bridge.go b/networking/plugins/bridge/bridge.go similarity index 99% rename from network/plugins/bridge/bridge.go rename to networking/plugins/bridge/bridge.go index 0f2633b..297eca3 100644 --- a/network/plugins/bridge/bridge.go +++ b/networking/plugins/bridge/bridge.go @@ -12,7 +12,7 @@ import ( "github.com/coreos/rocket/Godeps/_workspace/src/github.com/vishvananda/netlink" - "github.com/coreos/rocket/network/util" + "github.com/coreos/rocket/networking/util" ) const defaultBrName = "rkt0" diff --git a/network/plugins/veth/veth.go b/networking/plugins/veth/veth.go similarity index 90% rename from network/plugins/veth/veth.go rename to networking/plugins/veth/veth.go index 0e5a7c2..ae2dc2a 100644 --- a/network/plugins/veth/veth.go +++ b/networking/plugins/veth/veth.go @@ -9,10 +9,11 @@ import ( "strings" "syscall" + "github.com/appc/spec/schema/types" "github.com/coreos/rocket/Godeps/_workspace/src/github.com/vishvananda/netlink" - "github.com/coreos/rocket/network/ipam" - "github.com/coreos/rocket/network/util" + "github.com/coreos/rocket/networking/ipam" + "github.com/coreos/rocket/networking/util" ) func init() { @@ -35,7 +36,12 @@ func argsHasDefault(args string) bool { func cmdAdd(contID, netns, netConf, ifName, args string) error { var hostVethName string - ipn, gw, err := ipam.AllocIP(contID, netConf, ifName, args) + cid, err := types.NewUUID(contID) + if err != nil { + return fmt.Errorf("Error parsing ContainerID: %v", err) + } + + ipn, gw, err := ipam.AllocIP(*cid, netConf, ifName, args) if err != nil { return err } diff --git a/network/util/cidr.go b/networking/util/cidr.go similarity index 100% rename from network/util/cidr.go rename to networking/util/cidr.go diff --git a/network/util/net.go b/networking/util/net.go similarity index 100% rename from network/util/net.go rename to networking/util/net.go diff --git a/network/util/net_test.go b/networking/util/net_test.go similarity index 100% rename from network/util/net_test.go rename to networking/util/net_test.go diff --git a/network/util/route.go b/networking/util/route.go similarity index 100% rename from network/util/route.go rename to networking/util/route.go diff --git a/network/util/setns.go b/networking/util/setns.go similarity index 100% rename from network/util/setns.go rename to networking/util/setns.go diff --git a/network/util/veth.go b/networking/util/veth.go similarity index 100% rename from network/util/veth.go rename to networking/util/veth.go