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

Golang executor.Context类代码示例

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

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



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

示例1: Execute

func (cv CreateVeth) Execute(context executor.Context) error {
	err := context.LinkFactory().CreateVeth(cv.Name, cv.PeerName, cv.MTU)
	if err != nil {
		return fmt.Errorf("create veth: %s", err)
	}
	return nil
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:7,代码来源:create_veth.go


示例2: Execute

func (cv CreateDummy) Execute(context executor.Context) error {
	err := context.LinkFactory().CreateDummy(cv.Name)
	if err != nil {
		return fmt.Errorf("create dummy: %s", err)
	}

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


示例3: Execute

func (cb CreateBridge) Execute(context executor.Context) error {
	err := context.LinkFactory().CreateBridge(cb.Name)
	if err != nil {
		return fmt.Errorf("create bridge: %s", err)
	}

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


示例4: Execute

func (c DeleteLink) Execute(context executor.Context) error {
	err := context.LinkFactory().DeleteLinkByName(c.LinkName)
	if err != nil {
		return fmt.Errorf("delete link: %s", err)
	}

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


示例5: Execute

func (slm SetLinkMaster) Execute(context executor.Context) error {
	err := context.LinkFactory().SetMaster(slm.Slave, slm.Master)
	if err != nil {
		return fmt.Errorf("set link master: %s", err)
	}

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


示例6: Execute

func (s SetLinkUp) Execute(context executor.Context) error {
	err := context.LinkFactory().SetUp(s.LinkName)
	if err != nil {
		return fmt.Errorf("set link up: %s", err)
	}

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


示例7: Execute

func (aa AddAddress) Execute(context executor.Context) error {
	err := context.AddressManager().AddAddress(aa.InterfaceName, &aa.Address)
	if err != nil {
		return fmt.Errorf("add address: %s", err)
	}

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


示例8: Execute

func (ad AddRoute) Execute(context executor.Context) error {
	err := context.RouteManager().AddRoute(ad.Interface, &ad.Destination, ad.Gateway)
	if err != nil {
		return fmt.Errorf("add route: %s", err)
	}

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


示例9: Execute

func (cv CreateVxlan) Execute(context executor.Context) error {
	err := context.LinkFactory().CreateVxlan(cv.Name, cv.VNI)
	if err != nil {
		return fmt.Errorf("create vxlan: %s", err)
	}

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


示例10: Execute

func (cmd *GetHardwareAddress) Execute(context executor.Context) error {
	hwAddr, err := context.LinkFactory().HardwareAddress(cmd.LinkName)
	if err != nil {
		return fmt.Errorf("get hardware address: %s", err)
	}

	cmd.Result = hwAddr

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


示例11: Execute

func (cn CreateSandbox) Execute(context executor.Context) error {
	logger := context.Logger().WithData(lager.Data{"sandbox-name": cn.Name})
	logger.Info("create-sandbox")
	defer logger.Info("create-sandbox-complete")

	_, err := context.SandboxRepository().Create(cn.Name)
	if err != nil {
		return fmt.Errorf("create sandbox: %s", err)
	}

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


示例12: Execute

func (s MoveLink) Execute(context executor.Context) error {
	sbox, err := context.SandboxRepository().Get(s.SandboxName)
	if err != nil {
		return fmt.Errorf("get sandbox: %s", err)
	}

	err = context.LinkFactory().SetNamespace(s.Name, sbox.Namespace().Fd())
	if err != nil {
		return fmt.Errorf("move link: %s", err)
	}

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


示例13: Execute

func (sm StartMonitor) Execute(context executor.Context) error {
	ns, err := context.SandboxNamespaceRepository().Get(sm.SandboxName)
	if err != nil {
		return fmt.Errorf("getting sandbox namespace: %s", err)
	}

	return sm.HostNamespace.Execute(func(_ *os.File) error {
		err = sm.Watcher.StartMonitor(ns, sm.VxlanLinkName)
		if err != nil {
			return fmt.Errorf("watcher start monitor: %s", err)
		}
		return nil
	})
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:14,代码来源:start_monitor.go


示例14: Execute

func (c CleanupSandbox) Execute(context executor.Context) error {
	logger := context.Logger().Session("cleanup-sandbox", lager.Data{"sandbox-name": c.SandboxName})
	logger.Info("start")
	defer logger.Info("complete")

	sandboxRepo := context.SandboxRepository()
	sbox, err := sandboxRepo.Get(c.SandboxName)
	if err != nil {
		if err == sandbox.NotFoundError {
			return nil
		}

		logger.Error("get-sandbox-failed", err)
		return fmt.Errorf("get sandbox: %s", err)
	}

	// TODO: move into sandbox
	sbox.Lock()
	defer sbox.Unlock()

	vethLinkCount, err := sbox.VethDeviceCount()
	if err != nil {
		return fmt.Errorf("counting veth devices: %s", err)
	}

	logger.Info("veth-links-remaining", lager.Data{"count": vethLinkCount})

	if vethLinkCount == 0 {
		err = sbox.Namespace().Execute(func(*os.File) error {
			err := context.LinkFactory().DeleteLinkByName(c.VxlanDeviceName)
			if err != nil {
				if context.LinkFactory().Exists(c.VxlanDeviceName) {
					return fmt.Errorf("destroying vxlan %s: %s", c.VxlanDeviceName, err)
				}
			}
			return nil
		})
		if err != nil {
			return fmt.Errorf("in namespace %s: %s", c.SandboxName, err)
		}

		err = sandboxRepo.Destroy(c.SandboxName)
		switch err {
		case nil:
		case sandbox.AlreadyDestroyedError:
		case sandbox.NotFoundError:
		default:
			return fmt.Errorf("sandbox destroy: %s", err)
		}
	}

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


示例15: Satisfied

func (l LinkExists) Satisfied(context executor.Context) (bool, error) {
	return context.LinkFactory().Exists(l.Name), nil
}
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:3,代码来源:link_exists.go


示例16: Execute

func (sd StartDNSServer) Execute(context executor.Context) error {
	listenerFactory := context.ListenerFactory()

	listenAddress, err := net.ResolveUDPAddr("udp", sd.ListenAddress)
	if err != nil {
		return fmt.Errorf("resolve udp address: %s", err)
	}

	sbox, err := context.SandboxRepository().Get(sd.SandboxName)
	if err != nil {
		return fmt.Errorf("get sandbox: %s", err)
	}

	sbox.Lock()
	defer sbox.Unlock()

	namespace := sbox.Namespace()

	var conn *net.UDPConn
	err = namespace.Execute(func(*os.File) error {
		linkFactory := context.LinkFactory()
		err := linkFactory.CreateDummy(DNS_INTERFACE_NAME)
		if err != nil {
			return fmt.Errorf("create dummy: %s", err)
		}

		dnsAddress := &net.IPNet{
			IP:   listenAddress.IP,
			Mask: net.CIDRMask(32, 32),
		}

		err = context.AddressManager().AddAddress(DNS_INTERFACE_NAME, dnsAddress)
		if err != nil {
			return fmt.Errorf("add address: %s", err)
		}

		err = linkFactory.SetUp(DNS_INTERFACE_NAME)
		if err != nil {
			return fmt.Errorf("set up: %s", err)
		}

		conn, err = listenerFactory.ListenUDP("udp", listenAddress)
		if err != nil {
			return fmt.Errorf("listen udp: %s", err)
		}

		return nil
	})
	if err != nil {
		return fmt.Errorf("namespace execute: %s", err)
	}

	dnsServerRunner := context.DNSServerFactory().New(conn, namespace)

	err = sbox.LaunchDNS(dnsServerRunner)
	if err != nil {
		return fmt.Errorf("sandbox launch dns: %s", err)
	}

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


示例17:

			sandboxNamespaceRepository,
			sandboxRepository,
			listenerFactory,
			dnsServerFactory,
		)
	})

	It("executes a command with a context", func() {
		err := ex.Execute(command)
		Expect(err).NotTo(HaveOccurred())

		Expect(command.ExecuteCallCount()).To(Equal(1))
	})

	Describe("Context", func() {
		var context executor.Context

		BeforeEach(func() {
			ex.Execute(command)

			Expect(command.ExecuteCallCount()).To(Equal(1))
			context = command.ExecuteArgsForCall(0)
		})

		Describe("AddressManager", func() {
			It("returns the address manager", func() {
				Expect(context.AddressManager()).To(Equal(addressManager))
			})
		})

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang fakes.Context类代码示例发布时间:2022-05-23
下一篇:
Golang ifrit.Process类代码示例发布时间: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