in plugins/ecs-bridge/commands/commands.go [49:113]
func add(args *skel.CmdArgs, engine engine.Engine) error {
conf, err := types.NewConf(args)
if err != nil {
return err
}
log.Infof("Creating the bridge: %s", conf.BridgeName)
bridge, err := engine.CreateBridge(conf.BridgeName, conf.MTU)
if err != nil {
return err
}
log.Infof("Creating veth pair for namespace: %s", args.Netns)
containerVethInterface, hostVethName, err := engine.CreateVethPair(
args.Netns, conf.MTU, args.IfName)
if err != nil {
return err
}
log.Infof("Attaching veth pair %s to bridge", hostVethName)
hostVethInterface, err := engine.AttachHostVethInterfaceToBridge(hostVethName, bridge)
if err != nil {
return err
}
log.Infof("Running IPAM plugin ADD: %s", conf.IPAM.Type)
result, err := engine.RunIPAMPluginAdd(conf.IPAM.Type, args.StdinData)
if err != nil {
return err
}
// Construct the Interfaces list for the result returned from the IPAM
// plugin. This consists of all the interfaces we know about. This
// includes the bridge, the two ends of the veth interface created
result.Interfaces = []*current.Interface{
// the bridge interface
0: ¤t.Interface{
Name: bridge.Attrs().Name,
Mac: bridge.Attrs().HardwareAddr.String(),
},
// the host veth interface
1: hostVethInterface,
// the container veth interface
2: containerVethInterface,
}
// Set the index for the container veth interface in the `Interfaces`
// list populated above.
// The `ipam.ConfigureIface` method needs this index to be set as it
// needs to know which interface should be used when adding routes
result.IPs[0].Interface = 2
log.Infof("Configuring container's interface: %s", args.Netns)
err = engine.ConfigureContainerVethInterface(args.Netns, result, args.IfName)
if err != nil {
return err
}
log.Infof("Configuring bridge: %s", conf.BridgeName)
err = engine.ConfigureBridge(result, bridge)
if err != nil {
return err
}
return result.Print()
}