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


Golang names.NewSubnetTag函數代碼示例

本文整理匯總了Golang中github.com/juju/names.NewSubnetTag函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewSubnetTag函數的具體用法?Golang NewSubnetTag怎麽用?Golang NewSubnetTag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: TestNewSubnetTag

func (s *subnetSuite) TestNewSubnetTag(c *gc.C) {
	cidr := "10.20.0.0/16"
	tag := names.NewSubnetTag(cidr)
	parsed, err := names.ParseSubnetTag(tag.String())
	c.Assert(err, gc.IsNil)
	c.Assert(parsed.Kind(), gc.Equals, names.SubnetTagKind)
	c.Assert(parsed.Id(), gc.Equals, cidr)
	c.Assert(parsed.String(), gc.Equals, names.SubnetTagKind+"-"+cidr)

	f := func() {
		tag = names.NewSubnetTag("foo")
	}
	c.Assert(f, gc.PanicMatches, "foo is not a valid subnet CIDR")
}
開發者ID:juju,項目名稱:names,代碼行數:14,代碼來源:subnet_test.go

示例2: makeCreateSubnetsArgs

func makeCreateSubnetsArgs(cidr, space string, zones []string, isPublic bool) apitesting.CheckArgs {
	spaceTag := names.NewSpaceTag(space).String()
	subnetTag := names.NewSubnetTag(cidr).String()

	expectArgs := params.CreateSubnetsParams{
		Subnets: []params.CreateSubnetParams{{
			SpaceTag:  spaceTag,
			SubnetTag: subnetTag,
			Zones:     zones,
			IsPublic:  isPublic,
		}}}

	expectResults := params.ErrorResults{
		Results: []params.ErrorResult{{}},
	}

	args := apitesting.CheckArgs{
		Facade:  "Subnets",
		Method:  "CreateSubnets",
		Args:    expectArgs,
		Results: expectResults,
	}

	return args
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:25,代碼來源:subnets_test.go

示例3: makeArgs

func makeArgs(name string, subnets []string) (string, []string, apitesting.CheckArgs) {
	spaceTag := names.NewSpaceTag(name).String()
	subnetTags := []string{}

	for _, s := range subnets {
		subnetTags = append(subnetTags, names.NewSubnetTag(s).String())
	}

	expectArgs := params.CreateSpacesParams{
		Spaces: []params.CreateSpaceParams{
			params.CreateSpaceParams{
				SpaceTag:   spaceTag,
				SubnetTags: subnetTags,
				Public:     true,
			}}}

	expectResults := params.ErrorResults{
		Results: []params.ErrorResult{{}},
	}

	args := apitesting.CheckArgs{
		Facade:  "Spaces",
		Method:  "CreateSpaces",
		Args:    expectArgs,
		Results: expectResults,
	}

	return name, subnets, args
}
開發者ID:imoapps,項目名稱:juju,代碼行數:29,代碼來源:spaces_test.go

示例4: TestGetMachineActiveSubnets

func (s *firewallerSuite) TestGetMachineActiveSubnets(c *gc.C) {
	s.openPorts(c)

	subnetTag := names.NewSubnetTag("10.20.30.0/24").String()
	args := addFakeEntities(params.Entities{Entities: []params.Entity{
		{Tag: s.machines[0].Tag().String()},
		{Tag: s.machines[1].Tag().String()},
		{Tag: s.machines[2].Tag().String()},
		{Tag: s.service.Tag().String()},
		{Tag: s.units[0].Tag().String()},
	}})
	expectResultsMachine0 := []string{subnetTag, ""}
	expectResultsMachine2 := []string{""}
	result, err := s.firewaller.GetMachineActiveSubnets(args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.StringsResults{
		Results: []params.StringsResult{
			{Result: expectResultsMachine0},
			{Result: nil, Error: nil},
			{Result: expectResultsMachine2},
			{Error: apiservertesting.ServerError(`"service-wordpress" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"unit-wordpress-0" is not a valid machine tag`)},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ServerError(`"unit-foo-0" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"service-bar" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"user-foo" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"foo-bar" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"" is not a valid tag`)},
		},
	})
}
開發者ID:makyo,項目名稱:juju,代碼行數:31,代碼來源:firewaller_test.go

示例5: makeAddSubnetsArgs

func makeAddSubnetsArgs(cidr, providerId, space string, zones []string) apitesting.CheckArgs {
	spaceTag := names.NewSpaceTag(space).String()
	subnetTag := names.NewSubnetTag(cidr).String()
	if providerId != "" {
		subnetTag = ""
	}

	expectArgs := params.AddSubnetsParams{
		Subnets: []params.AddSubnetParams{{
			SpaceTag:         spaceTag,
			SubnetTag:        subnetTag,
			SubnetProviderId: providerId,
			Zones:            zones,
		}}}

	expectResults := params.ErrorResults{
		Results: []params.ErrorResult{{}},
	}

	args := apitesting.CheckArgs{
		Facade:  "Subnets",
		Method:  "AddSubnets",
		Args:    expectArgs,
		Results: expectResults,
	}

	return args
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:28,代碼來源:subnets_test.go

示例6: TestRunWithIPv6CIDRSucceeds

func (s *RemoveSuite) TestRunWithIPv6CIDRSucceeds(c *gc.C) {
	s.AssertRunSucceeds(c,
		`marked subnet "2001:db8::/32" for removal\n`,
		"", // empty stdout.
		"2001:db8::/32",
	)

	s.api.CheckCallNames(c, "RemoveSubnet", "Close")
	s.api.CheckCall(c, 0, "RemoveSubnet", names.NewSubnetTag("2001:db8::/32"))
}
開發者ID:imoapps,項目名稱:juju,代碼行數:10,代碼來源:remove_test.go

示例7: TestRunWithIPv4CIDRSucceeds

func (s *RemoveSuite) TestRunWithIPv4CIDRSucceeds(c *gc.C) {
	s.AssertRunSucceeds(c,
		`marked subnet "10.20.0.0/16" for removal\n`,
		"", // empty stdout.
		"10.20.0.0/16",
	)

	s.api.CheckCallNames(c, "RemoveSubnet", "Close")
	s.api.CheckCall(c, 0, "RemoveSubnet", names.NewSubnetTag("10.20.0.0/16"))
}
開發者ID:imoapps,項目名稱:juju,代碼行數:10,代碼來源:remove_test.go

示例8: TestRunWithSubnetInUseFails

func (s *RemoveSuite) TestRunWithSubnetInUseFails(c *gc.C) {
	s.api.SetErrors(errors.Errorf("subnet %q is still in use", "10.10.0.0/24"))

	s.AssertRunFails(c,
		`cannot remove subnet "10.10.0.0/24": subnet "10.10.0.0/24" is still in use`,
		"10.10.0.0/24",
	)

	s.api.CheckCallNames(c, "RemoveSubnet", "Close")
	s.api.CheckCall(c, 0, "RemoveSubnet", names.NewSubnetTag("10.10.0.0/24"))
}
開發者ID:imoapps,項目名稱:juju,代碼行數:11,代碼來源:remove_test.go

示例9: TestRunOneZoneSucceeds

func (s *CreateSuite) TestRunOneZoneSucceeds(c *gc.C) {
	s.AssertRunSucceeds(c,
		`created a private subnet "10.20.0.0/24" in space "myspace" with zones zone1\n`,
		"", // empty stdout.
		"10.20.0.0/24", "myspace", "zone1",
	)

	s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
	s.api.CheckCall(c, 1, "CreateSubnet",
		names.NewSubnetTag("10.20.0.0/24"), names.NewSpaceTag("myspace"), s.Strings("zone1"), false,
	)
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:12,代碼來源:create_test.go

示例10: TestRunWithPublicAndIPv6CIDRSucceeds

func (s *CreateSuite) TestRunWithPublicAndIPv6CIDRSucceeds(c *gc.C) {
	s.AssertRunSucceeds(c,
		`created a public subnet "2001:db8::/32" in space "space" with zones zone1\n`,
		"", // empty stdout.
		"2001:db8::/32", "space", "zone1", "--public",
	)

	s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
	s.api.CheckCall(c, 1, "CreateSubnet",
		names.NewSubnetTag("2001:db8::/32"), names.NewSpaceTag("space"), s.Strings("zone1"), true,
	)
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:12,代碼來源:create_test.go

示例11: TestRunWithNonExistingSubnetFails

func (s *RemoveSuite) TestRunWithNonExistingSubnetFails(c *gc.C) {
	s.api.SetErrors(errors.NotFoundf("subnet %q", "10.10.0.0/24"))

	err := s.AssertRunFails(c,
		`cannot remove subnet "10.10.0.0/24": subnet "10.10.0.0/24" not found`,
		"10.10.0.0/24",
	)
	c.Assert(err, jc.Satisfies, errors.IsNotFound)

	s.api.CheckCallNames(c, "RemoveSubnet", "Close")
	s.api.CheckCall(c, 0, "RemoveSubnet", names.NewSubnetTag("10.10.0.0/24"))
}
開發者ID:imoapps,項目名稱:juju,代碼行數:12,代碼來源:remove_test.go

示例12: ValidateCIDR

// ValidateCIDR parses given and returns an error if it's not valid.
// If the CIDR is incorrectly specified (e.g. 10.10.10.0/16 instead of
// 10.10.0.0/16) and strict is false, the correctly parsed CIDR in the
// expected format is returned instead without an error. Otherwise,
// when strict is true and given is incorrectly formatted, an error
// will be returned.
func (s *SubnetCommandBase) ValidateCIDR(given string, strict bool) (names.SubnetTag, error) {
	_, ipNet, err := net.ParseCIDR(given)
	if err != nil {
		logger.Debugf("cannot parse CIDR %q: %v", given, err)
		return names.SubnetTag{}, errors.Errorf("%q is not a valid CIDR", given)
	}
	if strict && given != ipNet.String() {
		expected := ipNet.String()
		return names.SubnetTag{}, errors.Errorf("%q is not correctly specified, expected %q", given, expected)
	}
	// Already validated, so shouldn't error here.
	return names.NewSubnetTag(ipNet.String()), nil
}
開發者ID:ktsakalozos,項目名稱:juju,代碼行數:19,代碼來源:subnet.go

示例13: TestRunWithNonExistingSpaceFails

func (s *CreateSuite) TestRunWithNonExistingSpaceFails(c *gc.C) {
	s.api.SetErrors(nil, errors.NotFoundf("space %q", "space"))

	err := s.AssertRunFails(c,
		`cannot create subnet "10.10.0.0/24": space "space" not found`,
		"10.10.0.0/24", "space", "zone1",
	)
	c.Assert(err, jc.Satisfies, errors.IsNotFound)

	s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
	s.api.CheckCall(c, 1, "CreateSubnet",
		names.NewSubnetTag("10.10.0.0/24"), names.NewSpaceTag("space"), s.Strings("zone1"), false,
	)
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:14,代碼來源:create_test.go

示例14: TestRunWithMultipleZonesSucceeds

func (s *CreateSuite) TestRunWithMultipleZonesSucceeds(c *gc.C) {
	s.AssertRunSucceeds(c,
		// The list of zones is sorted both when displayed and passed
		// to CreateSubnet.
		`created a private subnet "10.20.0.0/24" in space "foo" with zones zone1, zone2\n`,
		"",                                      // empty stdout.
		"10.20.0.0/24", "foo", "zone2", "zone1", // unsorted zones
	)

	s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
	s.api.CheckCall(c, 1, "CreateSubnet",
		names.NewSubnetTag("10.20.0.0/24"), names.NewSpaceTag("foo"), s.Strings("zone1", "zone2"), false,
	)
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:14,代碼來源:create_test.go

示例15: TestRunWithExistingSubnetFails

func (s *CreateSuite) TestRunWithExistingSubnetFails(c *gc.C) {
	s.api.SetErrors(nil, errors.AlreadyExistsf("subnet %q", "10.10.0.0/24"))

	err := s.AssertRunFails(c,
		`cannot create subnet "10.10.0.0/24": subnet "10.10.0.0/24" already exists`,
		"10.10.0.0/24", "space", "zone1",
	)
	c.Assert(err, jc.Satisfies, errors.IsAlreadyExists)

	s.api.CheckCallNames(c, "AllZones", "CreateSubnet", "Close")
	s.api.CheckCall(c, 1, "CreateSubnet",
		names.NewSubnetTag("10.10.0.0/24"), names.NewSpaceTag("space"), s.Strings("zone1"), false,
	)
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:14,代碼來源:create_test.go


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