當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Container.NetOut方法代碼示例

本文整理匯總了Golang中code/cloudfoundry/org/garden.Container.NetOut方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.NetOut方法的具體用法?Golang Container.NetOut怎麽用?Golang Container.NetOut使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在code/cloudfoundry/org/garden.Container的用法示例。


在下文中一共展示了Container.NetOut方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

				fakeConnection.NetInReturns(0, 0, disaster)
			})

			It("returns the error", func() {
				_, _, err := container.NetIn(123, 456)
				Ω(err).Should(Equal(disaster))
			})
		})
	})

	Describe("NetOut", func() {
		It("sends NetOut requests over the connection", func() {
			Ω(container.NetOut(garden.NetOutRule{
				Networks: []garden.IPRange{garden.IPRangeFromIP(net.ParseIP("1.2.3.4"))},
				Ports: []garden.PortRange{
					{Start: 12, End: 24},
				},
				Log: true,
			})).Should(Succeed())

			h, rule := fakeConnection.NetOutArgsForCall(0)
			Ω(h).Should(Equal("some-handle"))

			Ω(rule.Networks).Should(HaveLen(1))
			Ω(rule.Networks[0]).Should(Equal(garden.IPRange{Start: net.ParseIP("1.2.3.4"), End: net.ParseIP("1.2.3.4")}))

			Ω(rule.Ports).Should(HaveLen(1))
			Ω(rule.Ports[0]).Should(Equal(garden.PortRange{Start: 12, End: 24}))

			Ω(rule.Log).Should(Equal(true))
		})
開發者ID:stefanschneider,項目名稱:garden,代碼行數:31,代碼來源:container_test.go

示例2:

			restartArgs = []string{}
			gracefulShutdown = true
		})

		JustBeforeEach(func() {
			var err error
			container, err = client.Create(containerSpec)
			Expect(err).NotTo(HaveOccurred())

			hostNetInPort, _, err = container.NetIn(hostNetInPort, 8080)
			Expect(err).NotTo(HaveOccurred())

			container.NetOut(garden.NetOutRule{
				Networks: []garden.IPRange{
					garden.IPRangeFromIP(net.ParseIP("8.8.8.8")),
				},
			})

			info, err := container.Info()
			Expect(err).NotTo(HaveOccurred())
			externalIP = info.ExternalIP
			interfacePrefix = info.Properties["kawasaki.iptable-prefix"]

			out := gbytes.NewBuffer()
			existingProc, err = container.Run(
				garden.ProcessSpec{
					Path: "/bin/sh",
					Args: []string{"-c", "while true; do echo hello; sleep 1; done;"},
				},
				garden.ProcessIO{
開發者ID:cloudfoundry,項目名稱:guardian,代碼行數:30,代碼來源:restart_test.go

示例3:

				Networks: []garden.IPRange{garden.IPRangeFromIP(net.ParseIP("8.8.8.8"))},
				Ports:    []garden.PortRange{garden.PortRangeFromPort(53)},
			}
		})

		Context("when an IP within the denied network range is permitted", func() {
			BeforeEach(func() {
				args = append(args, "--deny-network", "0.0.0.0/0")
			})

			JustBeforeEach(func() {
				Expect(checkConnection(container, "8.8.8.8", 53)).To(MatchError("Request failed. Process exited with code 1"))
			})

			It("should access internet", func() {
				Expect(container.NetOut(rule)).To(Succeed())
				Expect(checkConnection(container, "8.8.8.8", 53)).To(Succeed())
			})

			Context("when the dropped packets should get logged", func() {
				BeforeEach(func() {
					rule.Log = true
				})

				It("should access internet", func() {
					Expect(container.NetOut(rule)).To(Succeed())
					Expect(checkConnection(container, "8.8.8.8", 53)).To(Succeed())
				})
			})
		})
	})
開發者ID:cloudfoundry,項目名稱:guardian,代碼行數:31,代碼來源:net_test.go


注:本文中的code/cloudfoundry/org/garden.Container.NetOut方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。