• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang namespace.Namespace类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cloudfoundry-incubator/ducati-daemon/lib/namespace.Namespace的典型用法代码示例。如果您正苦于以下问题:Golang Namespace类的具体用法?Golang Namespace怎么用?Golang Namespace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Namespace类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Callback

func (r *Reloader) Callback(ns namespace.Namespace) error {

	nsName := ns.Name()

	vxlanName, err := getVxlanName(nsName)
	if err != nil {
		return fmt.Errorf("get vxlan name: %s", err)
	}

	err = r.Watcher.StartMonitor(ns, vxlanName)
	if err != nil {
		return fmt.Errorf("start monitor: %s", err)
	}

	return nil
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:16,代码来源:reloader.go


示例2: HandleResolvedNeighbors

func (a *ARPInserter) HandleResolvedNeighbors(ready chan error, ns namespace.Namespace, vxlanDeviceName string, resolvedChan <-chan watcher.Neighbor) {

	var vxlanLink netlink.Link
	err := ns.Execute(func(f *os.File) error {
		var err error
		vxlanLink, err = a.Netlinker.LinkByName(vxlanDeviceName)
		if err != nil {
			return fmt.Errorf("find link %q: %s", vxlanDeviceName, err)
		}
		return nil
	})
	if err != nil {
		ready <- fmt.Errorf("namespace execute failed: %s", err)
		close(ready)
		return
	}

	close(ready)

	a.addNeighbors(vxlanLink.Attrs().Index, ns, resolvedChan)
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:21,代码来源:arp_inserter.go


示例3: addNeighbors

func (a *ARPInserter) addNeighbors(vxlanLinkIndex int, ns namespace.Namespace, resolvedChan <-chan watcher.Neighbor) {
	for msg := range resolvedChan {
		neigh := reverseConvert(msg.Neigh)
		neigh.State = netlink.NUD_REACHABLE

		fdb := &netlink.Neigh{
			LinkIndex:    vxlanLinkIndex,
			HardwareAddr: neigh.HardwareAddr,
			IP:           msg.VTEP,
			Family:       syscall.AF_BRIDGE,
			Flags:        netlink.NTF_SELF,
			State:        netlink.NUD_REACHABLE,
		}

		a.Logger.Info("adding-neigbor", lager.Data{
			"neigh":   neigh.String(),
			"fdb":     fdb,
			"hw_addr": neigh.HardwareAddr.String(),
		})

		err := ns.Execute(func(*os.File) error {
			err := a.Netlinker.SetNeigh(neigh)
			if err != nil {
				return fmt.Errorf("set L3 neighbor failed: %s", err)
			}

			err = a.Netlinker.SetNeigh(fdb)
			if err != nil {
				return fmt.Errorf("set L2 forward failed: %s", err)
			}

			return nil
		})
		if err != nil {
			a.Logger.Error("add-neighbor-failed", err)
		}
	}
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:38,代码来源:arp_inserter.go


示例4: New

func New(
	logger lager.Logger,
	namespace namespace.Namespace,
	invoker Invoker,
	linkFactory LinkFactory,
	watcher watcher.MissWatcher,
) Sandbox {
	logger = logger.Session("network-sandbox", lager.Data{"namespace": namespace.Name()})

	return &NetworkSandbox{
		logger:      logger,
		namespace:   namespace,
		invoker:     invoker,
		linkFactory: linkFactory,
		watcher:     watcher,
	}
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:17,代码来源:sandbox.go


示例5: StopMonitor

func (w *missWatcher) StopMonitor(ns namespace.Namespace) error {
	w.Locker.Lock()
	defer w.Locker.Unlock()

	logger := w.Logger.Session("stop-monitor", lager.Data{"namespace": ns})
	logger.Info("called")
	defer logger.Info("complete")

	doneChan, ok := w.DoneChans[ns.Name()]
	if !ok {
		err := fmt.Errorf("namespace %s not monitored", ns.Name())
		logger.Error("done-channel-missing", err)
		return err
	}

	delete(w.DoneChans, ns.Name())
	close(doneChan)

	return nil
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:20,代码来源:watcher.go


示例6: StartMonitor

func (w *missWatcher) StartMonitor(ns namespace.Namespace, vxlanName string) error {
	logger := w.Logger.Session("start-monitor", lager.Data{"namespace": ns})
	logger.Info("called")
	defer logger.Info("complete")

	subChan := make(chan *Neigh)
	unresolvedMisses := make(chan Neighbor)
	resolvedNeighbors := make(chan Neighbor)

	doneChan := make(chan struct{})

	w.Locker.Lock()
	w.DoneChans[ns.Name()] = doneChan
	w.Locker.Unlock()

	err := w.startARPInserter(ns, vxlanName, resolvedNeighbors)
	if err != nil {
		return fmt.Errorf("arp inserter failed: %s", err)
	}

	err = w.Subscriber.Subscribe(ns, subChan, doneChan)
	if err != nil {
		return fmt.Errorf("subscribe in %s: %s", ns.Name(), err)
	}

	go func() {
		logger := logger.Session("forward-neighbor-messages")
		logger.Info("starting")
		for neigh := range subChan {
			unresolvedMisses <- Neighbor{
				SandboxName: ns.Name(),
				Neigh:       *neigh,
			}
		}
		logger.Info("complete")
	}()

	go w.Resolver.ResolveMisses(unresolvedMisses, resolvedNeighbors)

	return nil
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:41,代码来源:watcher.go


示例7:

	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("Sandbox Consistency", func() {
	var (
		session        *gexec.Session
		ducatiCmd      *exec.Cmd
		address        string
		containerID    string
		vni            int
		sandboxName    string
		sandboxRepoDir string
		spaceID        string
		appID          string
		networkID      string

		logger *lagertest.TestLogger
		// sandboxRepo        namespace.Repository
		containerRepo      namespace.Repository
		containerNamespace namespace.Namespace

		configFilePath string
	)

	BeforeEach(func() {
		var err error
		address = fmt.Sprintf("127.0.0.1:%d", 4001+GinkgoParallelNode())
		sandboxRepoDir, err = ioutil.TempDir("", "sandbox")
		Expect(err).NotTo(HaveOccurred())
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:31,代码来源:sandbox_namespace_consistency_test.go


示例8:

	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
	"github.com/pivotal-golang/lager/lagertest"
)

var _ = Describe("Networks", func() {
	var (
		session     *gexec.Session
		address     string
		containerID string
		vni         int
		spaceID     string
		networkID   string
		appID       string

		logger *lagertest.TestLogger

		sandboxRepo        namespace.Repository
		containerRepo      namespace.Repository
		containerNamespace namespace.Namespace

		upSpec       models.CNIAddPayload
		downSpec     models.CNIDelPayload
		daemonClient *client.DaemonClient
	)

	BeforeEach(func() {
		address = fmt.Sprintf("127.0.0.1:%d", 4001+GinkgoParallelNode())
		sandboxRepoDir, err := ioutil.TempDir("", "sandbox")
		Expect(err).NotTo(HaveOccurred())
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:30,代码来源:watcher_test.go


示例9:

				ns = &fakes.Namespace{}
			})

			It("returns an error", func() {
				err := repo.Destroy(ns)
				Expect(err).To(MatchError("namespace is not a Netns"))
			})

			It("logs the failure", func() {
				repo.Destroy(ns)
				Expect(logger).To(gbytes.Say("destroy.not-a-netns"))
			})
		})

		Context("when the namespace file is not a bind mount", func() {
			var ns namespace.Namespace

			BeforeEach(func() {
				var err error
				ns, err = repo.Create("already-destroyed")
				Expect(err).NotTo(HaveOccurred())

				err = repo.Destroy(ns)
				Expect(err).NotTo(HaveOccurred())

				f, err := os.Create(ns.Name())
				Expect(err).NotTo(HaveOccurred())
				f.Close()
			})

			AfterEach(func() {
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:31,代码来源:repository_test.go


示例10: Subscribe

func (s *Subscriber) Subscribe(
	sandboxNS namespace.Namespace,
	neighChan chan<- *watcher.Neigh,
	doneChan <-chan struct{},
) error {
	logger := s.Logger.Session("subscribe")
	logger.Info("called")
	defer logger.Info("complete")

	var sock nl.NLSocket
	err := sandboxNS.Execute(func(*os.File) error {
		var err error
		sock, err = s.Netlinker.Subscribe(syscall.NETLINK_ROUTE, syscall.RTNLGRP_NEIGH)
		if err != nil {
			logger.Error("netlink-subscribe-failed", err)
			return fmt.Errorf("failed to acquire netlink socket: %s", err)
		}
		return nil
	})
	if err != nil {
		return fmt.Errorf("namespace execute: %s", err)
	}

	go func() {
		<-doneChan
		logger.Info("closing-netlink-socket")
		sock.Close()
		logger.Info("closed-netlink-socket")
	}()

	go func() {
		defer func() {
			logger.Info("closing-neigh-chan")
			close(neighChan)
			logger.Info("closed-neigh-chan")
		}()

		for {
			msgs, err := sock.Receive()
			logger.Info("receive-message-count", lager.Data{"message-count": len(msgs)})
			if err != nil {
				s.Logger.Error("socket-receive", err)
				return
			}

			for _, m := range msgs {
				n, err := s.Netlinker.NeighDeserialize(m.Data)
				if err != nil {
					s.Logger.Error("neighbor-deserialize", err)
					return
				}

				if n.IP == nil || (n.HardwareAddr != nil && n.State != netlink.NUD_STALE) {
					continue
				}

				neigh := convertNeigh(n)

				neighChan <- neigh
			}
		}
	}()

	return nil
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:65,代码来源:subscriber.go


示例11:

	daemonConfig.Marshal(configFile)
	Expect(configFile.Close()).To(Succeed())

	return configFile.Name()
}

var _ = Describe("Networks", func() {
	var (
		session     *gexec.Session
		address     string
		containerID string
		vni         int
		sandboxName string
		hostAddress string
		spaceID     string
		appID       string
		networkID   string

		logger             *lagertest.TestLogger
		sandboxRepo        namespace.Repository
		containerRepo      namespace.Repository
		containerNamespace namespace.Namespace
	)

	BeforeEach(func() {
		address = fmt.Sprintf("127.0.0.1:%d", 4001+GinkgoParallelNode())
		sandboxRepoDir, err := ioutil.TempDir("", "sandbox")
		Expect(err).NotTo(HaveOccurred())

		logger = lagertest.NewTestLogger("test")
		threadLocker := &ossupport.OSLocker{}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:31,代码来源:networks_test.go



注:本文中的github.com/cloudfoundry-incubator/ducati-daemon/lib/namespace.Namespace类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang executor.Container类代码示例发布时间:2022-05-23
下一篇:
Golang fakes.Namespace类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap