Beispiel #1
0
func main() {
	kingpin.Parse()
	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	dc := &driverCallback{}
	driverOptions := options.Generic{
		"EnableIPTables":     *iptables,
		"EnableIPForwarding": *ipForward,
	}
	genericOption := make(map[string]interface{})
	genericOption[netlabel.GenericData] = driverOptions
	for k, v := range datastore.DefaultScopes("") {
		if !v.IsValid() {
			continue
		}

		genericOption[netlabel.MakeKVProvider(k)] = v.Client.Provider
		genericOption[netlabel.MakeKVProviderURL(k)] = v.Client.Address
		genericOption[netlabel.MakeKVProviderConfig(k)] = v.Client.Config
	}

	err := bridge.Init(dc, genericOption)
	if err != nil {
		logrus.Fatalf("Failed to initialize the bridge: %v", err)
	}

	h := network.NewHandler(dc.driver)
	h.ServeUnix("", pluginName)
}
// Run initializes the driver
func Run(ctx *cli.Context) {
	if ctx.Bool("debug") {
		log.SetLevel(log.DebugLevel)
	}

	d, err := macvlan.NewDriver(version, ctx)
	if err != nil {
		panic(err)
	}
	h := network.NewHandler(d)
	h.ServeUnix("root", "macvlan")
}
Beispiel #3
0
func Run(ctx *cli.Context) {
	SetLogLevel(ctx.String("log-level"))

	var (
		derr, ierr chan error
	)

	//Bind to cluster store
	store, err := NewStore(ctx.String("cluster-store"))
	if err != nil {
		panic(err)
	}

	if !ctx.Bool("no-network") {
		d, err := dnet.NewDriver("global", ctx.String("interface"), store)
		if err != nil {
			panic(err)
		}
		h := network.NewHandler(d)
		derr = make(chan error)
		go func() {
			derr <- h.ServeUnix("root", "dnet")
		}()
		Log.Infof("Running Driver plugin 'dnet', bound on interface %s", ctx.String("interface"))
	}

	if !ctx.Bool("no-ipam") {
		i, err := dipam.NewIpam()
		if err != nil {
			panic(err)
		}
		h := ipam.NewHandler(i)
		ierr = make(chan error)
		go func() {
			ierr <- h.ServeUnix("root", "dhcp")
		}()
		Log.Infof("Running IPAM plugin 'dhcp'")
	}

	if derr == nil && ierr == nil {
		Log.Errorf("You started the daemon without anything to do")
		os.Exit(127)
	}

	select {
	case err := <-derr:
		panic(err)
	case err := <-ierr:
		panic(err)
	}
}
Beispiel #4
0
// Run initializes the driver
func Run(ctx *cli.Context) {
	if ctx.Bool("debug") {
		log.SetLevel(log.DebugLevel)
	}
	log.SetFormatter(&log.TextFormatter{
		ForceColors:      false,
		DisableColors:    true,
		DisableTimestamp: false,
		FullTimestamp:    true,
	})
	d, err := vxlan.NewDriver(ctx.String("scope"), ctx.String("vtepdev"))
	if err != nil {
		panic(err)
	}
	h := network.NewHandler(d)
	h.ServeUnix("root", "vxlan")
}
func main() {
	// Display the version on "-v"
	// Use a new flag set so as not to conflict with existing libraries which use "flag"
	flagSet := flag.NewFlagSet("Calico", flag.ExitOnError)

	version := flagSet.Bool("v", false, "Display version")
	err := flagSet.Parse(os.Args[1:])
	if err != nil {
		log.Fatalln(err)
	}
	if *version {
		fmt.Println(VERSION)
		os.Exit(0)
	}

	initializeClient()

	errChannel := make(chan error)
	networkHandler := network.NewHandler(driver.NewNetworkDriver(client))
	ipamHandler := ipam.NewHandler(driver.NewIpamDriver(client))

	go func(c chan error) {
		log.Infoln("calico-net has started.")
		err := networkHandler.ServeUnix("root", networkPluginName)
		log.Infoln("calico-net has stopped working.")
		c <- err
	}(errChannel)

	go func(c chan error) {
		log.Infoln("calico-ipam has started.")
		err := ipamHandler.ServeUnix("root", ipamPluginName)
		log.Infoln("calico-ipam has stopped working.")
		c <- err
	}(errChannel)

	err = <-errChannel

	log.Fatalln(err)
}
Beispiel #6
0
// Run runs the network driver and starts the server to listen for requests. It will
// block until the server socket has been created.
func Run() {
	h := dnet.NewHandler(driver{})

	go func() {
		err := h.ServeUnix("root", pluginSocket)
		if err != nil {
			// If the driver fails to start, we can't boot any containers,
			// so we may as well panic.
			panic("Failed to serve driver socket server")
		}
	}()

	// The ServeUnix function that handles the plugin socket won't return until
	// the socket is closed, so we can't know exactly when the socket has been
	// created. In order to prevent a race condition where Docker attempts to use
	// the plugin before the socket is up, we simply wait until the socket file
	// exists.
	for {
		if _, err := os.Stat(pluginSocket); err == nil {
			return
		}
		time.Sleep(500 * time.Millisecond)
	}
}