// initStateDriver creates a state driver based on the cluster store URL
335135
func initStateDriver(clusterStore string) (core.StateDriver, error) {
	// parse the state store URL
	parts := strings.Split(clusterStore, "://")
	if len(parts) < 2 {
		return nil, core.Errorf("Invalid state-store URL %q", clusterStore)
	}
	stateStore := parts[0]

	// Make sure we support the statestore type
	switch stateStore {
	case utils.EtcdNameStr:
	case utils.ConsulNameStr:
	default:
		return nil, core.Errorf("Unsupported state-store %q", stateStore)
	}

	// Setup instance info
	instInfo := core.InstanceInfo{
		DbURL: clusterStore,
	}

	return utils.NewStateDriver(stateStore, &instInfo)
}
586817
func (b *stdBackend) init() {
	b.etmData = make(map[string]*stdMeasuringPoint)
	b.ssvData = make(map[string]*stdStaySetVariable)
	b.dsrData = make(map[string]DynamicStatusRetriever)
}
962486
func (d *EtcdStateDriver) Init(instInfo *core.InstanceInfo) error {
	var err error
	var endpoint *url.URL

	if instInfo == nil || instInfo.DbURL == "" {
		return errors.New("no etcd config found")
	}
	endpoint, err = url.Parse(instInfo.DbURL)
	if err != nil {
		return err
	}
	if endpoint.Scheme == "etcd" {
		endpoint.Scheme = "http"
	} else if endpoint.Scheme != "http" && endpoint.Scheme != "https" {
		return core.Errorf("invalid etcd URL scheme %q", endpoint.Scheme)
	}
	// TODO: support multi-endpoints
	etcdConfig := client.Config{
		Endpoints: []string{endpoint.String()},
	}

	d.Client, err = client.New(etcdConfig)
	if err != nil {
		log.Fatalf("error creating etcd client. Err: %v", err)
	}

	// Create keys api
	d.KeysAPI = client.NewKeysAPI(d.Client)

	return nil
}
1007584
func Init(cfg config.ClusterConfig) error {
	if inst != nil {
		return errClusterInitialized
	}

	kv := kvdb.Instance()
	if kv == nil {
		return errors.New("KVDB is not yet initialized.  " +
			"A valid KVDB instance required for the cluster to start.")
	}

	inst = &ClusterManager{
		listeners:          list.New(),
		config:             cfg,
		kv:                 kv,
		nodeCache:          make(map[string]api.Node),
		nodeStatuses:       make(map[string]api.Status),
		systemTokenManager: auth.SystemTokenManagerInst(),
	}

	return nil
}
6696
func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
	// Try to load the aufs kernel module
	if err := supportsAufs(); err != nil {
		logger.Error(err)
		return nil, graphdriver.ErrNotSupported
	}

	// Perform feature detection on /var/lib/docker/aufs if it's an existing directory.
	// This covers situations where /var/lib/docker/aufs is a mount, and on a different
	// filesystem than /var/lib/docker.
	// If the path does not exist, fall back to using /var/lib/docker for feature detection.
	testdir := root
	if _, err := os.Stat(testdir); os.IsNotExist(err) {
		testdir = filepath.Dir(testdir)
	}

	fsMagic, err := graphdriver.GetFSMagic(testdir)
	if err != nil {
		return nil, err
	}
	if fsName, ok := graphdriver.FsNames[fsMagic]; ok {
		backingFs = fsName
	}

	switch fsMagic {
	case graphdriver.FsMagicAufs, graphdriver.FsMagicBtrfs, graphdriver.FsMagicEcryptfs:
		logger.Errorf("AUFS is not supported over %s", backingFs)
		return nil, graphdriver.ErrIncompatibleFS
	}

	paths := []string{
		"mnt",
		"diff",
		"layers",
	}

	a := &Driver{
		root:      root,
		uidMaps:   uidMaps,
		gidMaps:   gidMaps,
		pathCache: make(map[string]string),
		ctr:       graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicAufs)),
		locker:    locker.New(),
	}

	rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
	if err != nil {
		return nil, err
	}
	// Create the root aufs driver dir
	if err := idtools.MkdirAllAndChown(root, 0700, idtools.Identity{UID: rootUID, GID: rootGID}); err != nil {
		return nil, err
	}

	// Populate the dir structure
	for _, p := range paths {
		if err := idtools.MkdirAllAndChown(path.Join(root, p), 0700, idtools.Identity{UID: rootUID, GID: rootGID}); err != nil {
			return nil, err
		}
	}

	for _, path := range []string{"mnt", "diff"} {
		p := filepath.Join(root, path)
		entries, err := ioutil.ReadDir(p)
		if err != nil {
			logger.WithError(err).WithField("dir", p).Error("error reading dir entries")
			continue
		}
		for _, entry := range entries {
			if !entry.IsDir() {
				continue
			}
			if strings.HasSuffix(entry.Name(), "-removing") {
				logger.WithField("dir", entry.Name()).Debug("Cleaning up stale layer dir")
				if err := system.EnsureRemoveAll(filepath.Join(p, entry.Name())); err != nil {
					logger.WithField("dir", entry.Name()).WithError(err).Error("Error removing stale layer dir")
				}
			}
		}
	}

	a.naiveDiff = graphdriver.NewNaiveDiffDriver(a, uidMaps, gidMaps)
	return a, nil
}
626840
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
	c := driverapi.Capability{
		DataScope:         datastore.LocalScope,
		ConnectivityScope: datastore.GlobalScope,
	}
	d := &driver{
		networks: networkTable{},
	}
	d.initStore(config)

	return dc.RegisterDriver(ipvlanType, d, c)
}
370860
func determineDriver() {
	drivers := [...]HardwareDriver{NewBeagleboneBlackDTDriver(), NewRaspPiDTDriver(), NewOdroidC1Driver()}
	for _, d := range drivers {
		if d.MatchesHardwareConfig() {
			SetDriver(d)
			return
		}
	}

	fmt.Printf("Unable to select a suitable driver for this board.\n")
}
1160205
func init() {
	graphdriver.Register("windowsfilter", InitFilter)
	// DOCKER_WINDOWSFILTER_NOREEXEC allows for inline processing which makes
	// debugging issues in the re-exec codepath significantly easier.
	if os.Getenv("DOCKER_WINDOWSFILTER_NOREEXEC") != "" {
		logrus.Warnf("WindowsGraphDriver is set to not re-exec. This is intended for debugging purposes only.")
		noreexec = true
	} else {
		reexec.Register("docker-windows-write-layer", writeLayerReexec)
	}
}
1358981
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
	d := &Driver{
		home:      home,
		idMapping: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps),
	}

	if err := d.parseOptions(options); err != nil {
		return nil, err
	}

	rootIDs := d.idMapping.RootPair()
	if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil {
		return nil, err
	}

	setupDriverQuota(d)

	if size := d.getQuotaOpt(); !d.quotaSupported() && size > 0 {
		return nil, quota.ErrQuotaNotSupported
	}

	return graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps), nil
}
329818
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
	d := newDriver()
	if err := d.configure(config); err != nil {
		return err
	}

	c := driverapi.Capability{
		DataScope:         datastore.LocalScope,
		ConnectivityScope: datastore.LocalScope,
	}
	return dc.RegisterDriver(networkType, d, c)
}
1072652
func IsInitialized(driverHome string) bool {
	_, err := os.Stat(driverHome)
	if os.IsNotExist(err) {
		return false
	}
	if err != nil {
		logrus.Warnf("graphdriver.IsInitialized: stat failed: %v", err)
	}
	return !isEmptyDir(driverHome)
}
69529
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
	c := driverapi.Capability{
		DataScope:         datastore.LocalScope,
		ConnectivityScope: datastore.LocalScope,
	}
	return dc.RegisterDriver(networkType, &driver{}, c)
}
675108
func Init(params map[string]string) (volume.VolumeDriver, error) {
	url, ok := params[config.UrlKey]
	if !ok {
		url = DefaultUrl
	}
	version, ok := params[config.VersionKey]
	if !ok {
		version = volume.APIVersion
	}
	c, err := client.NewClient(url, version, "")
	if err != nil {
		return nil, err
	}

	return &driver{VolumeDriver: volumeclient.VolumeDriver(c)}, nil
}
1034825
func (d *OvsDriver) Init(info *core.InstanceInfo) error {

	if info == nil || info.StateDriver == nil {
		return core.Errorf("Invalid arguments. instance-info: %+v", info)
	}

	d.oper.StateDriver = info.StateDriver
	d.localIP = info.VtepIP
	// restore the driver's runtime state if it exists
	err := d.oper.Read(info.HostLabel)
	if core.ErrIfKeyExists(err) != nil {
		log.Errorf("Failed to read driver oper state for key %q. Error: %s",
			info.HostLabel, err)
		return err
	} else if err != nil {
		// create the oper state as it is first time start up
		d.oper.ID = info.HostLabel
		d.oper.CurrPortNum = 0

		// create local endpoint info map
		d.oper.LocalEpInfo = make(map[string]*EpInfo)

		// write the oper
		err = d.oper.Write()
		if err != nil {
			return err
		}
	}

	// make sure LocalEpInfo exists
	if d.oper.LocalEpInfo == nil {
		d.oper.LocalEpInfo = make(map[string]*EpInfo)
		// write the oper
		err = d.oper.Write()
		if err != nil {
			return err
		}
	}

	log.Infof("Initializing ovsdriver")

	// Init switch DB
	d.switchDb = make(map[string]*OvsSwitch)

	// Create Vxlan switch
	d.switchDb["vxlan"], err = NewOvsSwitch(vxlanBridgeName, "vxlan", info.VtepIP,
		info.FwdMode, nil, info.HostPvtNW, info.VxlanUDPPort)
	if err != nil {
		log.Fatalf("Error creating vlan switch. Err: %v", err)
	}
	// Create Vlan switch
	d.switchDb["vlan"], err = NewOvsSwitch(vlanBridgeName, "vlan", info.VtepIP,
		info.FwdMode, info.UplinkIntf, info.HostPvtNW, info.VxlanUDPPort)
	if err != nil {
		log.Fatalf("Error creating vlan switch. Err: %v", err)
	}

	// Add name server
	d.nameServer = new(nameserver.NetpluginNameServer)
	d.nameServer.Init(info.StateDriver)
	d.switchDb["vxlan"].AddNameServer(d.nameServer)
	d.switchDb["vlan"].AddNameServer(d.nameServer)
	log.Infof("initialized nameserver")

	// Add uplink to VLAN switch
	if len(info.UplinkIntf) != 0 {
		err = d.switchDb["vlan"].AddUplink("uplinkPort", info.UplinkIntf)
		if err != nil {
			log.Errorf("Could not add uplink %v to vlan OVS. Err: %v", info.UplinkIntf, err)
		}
	}

	if maxPortNum > 0xfffe {
		log.Fatalf("Host bridge logic assumes maxPortNum <= 0xfffe")
	}

	// Add host port.
	_, err = d.switchDb["vxlan"].AddHostPort(hostPortName, maxPortNum, info.HostPvtNW, true)
	if err != nil {
		log.Errorf("Could not add host port %s to OVS. Err: %v", hostPortName, err)
	}

	// Add a masquerade rule to ip tables.
	netmask, _ := netutils.PortToHostIPMAC(0, info.HostPvtNW)
	netutils.SetIPMasquerade(hostPortName, netmask)

	// Initialize the node proxy
	d.HostProxy, err = NewNodeProxy()

	return err
}
1058580
func (na *cnmNetworkAllocator) resolveDriver(n *api.Network) (*networkDriver, error) {
	dName := DefaultDriver
	if n.Spec.DriverConfig != nil && n.Spec.DriverConfig.Name != "" {
		dName = n.Spec.DriverConfig.Name
	}

	d, drvcap := na.drvRegistry.Driver(dName)
	if d == nil {
		err := na.loadDriver(dName)
		if err != nil {
			return nil, err
		}

		d, drvcap = na.drvRegistry.Driver(dName)
		if d == nil {
			return nil, fmt.Errorf("could not resolve network driver %s", dName)
		}
	}

	return &networkDriver{driver: d, capability: drvcap, name: dName}, nil
}
644309
func (k *KubeBoot) Init(volumesProvider Volumes) {
	k.volumeMounter = newVolumeMountController(volumesProvider)
	k.etcdControllers = make(map[string]*EtcdController)
}
1145929
func Init(root string, options []string) (volume.Driver, error) {
	driver := &DeviceMapperDriver{
		root:    root,
		options: options,
	}

	if err := driver.ensureInitialized(); err != nil {
		return nil, err
	}

	driver.cleanUpSnapshots()

	return driver, nil
}