当前位置: 首页>>代码示例>>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;未经允许,请勿转载。