本文整理匯總了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)
}
示例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)
}
}
}
示例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
}
示例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))
})
})
示例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()