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


Golang Context.SandboxRepository方法代码示例

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


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

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

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

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

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

示例5:

		Describe("RouteManager", func() {
			It("returns the route manager", func() {
				Expect(context.RouteManager()).To(Equal(routeManager))
			})
		})

		Describe("SandboxNamespaceRepository", func() {
			It("returns the SandboxNamespaceRepository", func() {
				Expect(context.SandboxNamespaceRepository()).To(Equal(sandboxNamespaceRepository))
			})
		})

		Describe("SandboxRepository", func() {
			It("returns the SandboxRepository", func() {
				Expect(context.SandboxRepository()).To(Equal(sandboxRepository))
			})
		})

		Describe("ListenerFactory", func() {
			It("returns the ListenerFactory", func() {
				Expect(context.ListenerFactory()).To(Equal(listenerFactory))
			})
		})

		Describe("DNSServerFactory", func() {
			It("returns the DNSServerFactory", func() {
				Expect(context.DNSServerFactory()).To(Equal(dnsServerFactory))
			})
		})
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:29,代码来源:executor_test.go


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