当前位置: 首页>>代码示例>>Golang>>正文


Golang Namespace.Execute方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4:

			ContainerNamespace: containerNamespace.Name(),
			ContainerID:        containerID,
		}

		By("adding the container to a network")
		_, err = daemonClient.ContainerUp(upSpec)
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		By("removing the container from the network")
		Expect(daemonClient.ContainerDown(downSpec)).To(Succeed())

		session.Interrupt()
		Eventually(session, DEFAULT_TIMEOUT).Should(gexec.Exit(0))
		Expect(containerRepo.Destroy(containerNamespace)).To(Succeed())
	})

	It("catches L3 misses", func() {
		time.Sleep(2 * time.Second)
		err := containerNamespace.Execute(func(_ *os.File) error {
			_, err := net.DialTimeout("tcp", "192.168.1.100:1234", 1*time.Second)
			Expect(err).To(HaveOccurred())
			return nil
		})
		Expect(err).NotTo(HaveOccurred())

		Eventually(session.Out, "5s").Should(gbytes.Say("ducatid.sandbox-miss.*dest_ip.*192.168.1.100.*sandbox.*vni-%d", vni))
	})
})
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:30,代码来源:watcher_test.go

示例5:

			By("removing the container from the network")
			Expect(daemonClient.ContainerDown(downSpec)).To(Succeed())

			By("checking that containers have been removed")
			containers, err := daemonClient.ListNetworkContainers(networkID)
			Expect(err).NotTo(HaveOccurred())
			Expect(containers).To(HaveLen(0))

			By("checking that the sandbox has been cleaned up")
			_, err = sandboxRepo.Get(sandboxName)
			Expect(err).To(MatchError(ContainSubstring("no such file or directory")))

			By("checking that the veth device is no longer in the container")
			err = containerNamespace.Execute(func(_ *os.File) error {
				_, err := netlink.LinkByName("vx-eth0")
				Expect(err).To(MatchError(ContainSubstring("Link not found")))
				return nil
			})
			Expect(err).NotTo(HaveOccurred())
		})

		It("makes container metadata available on the list network containers endpoint", func() {
			containers, err := daemonClient.ListNetworkContainers(networkID)
			Expect(err).NotTo(HaveOccurred())

			Expect(containers).To(HaveLen(1))
			Expect(containers[0].HostIP).To(Equal(hostAddress))
		})

		It("makes container metadata available on the /containers endpoint", func() {
			containers, err := daemonClient.ListContainers()
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:31,代码来源:networks_test.go


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