Example #1
0
File: subnets.go Project: bac/juju
// ListSubnets lists all the available subnets or only those matching
// all given optional filters.
func (api *subnetsAPI) ListSubnets(args params.SubnetsFilters) (results params.ListSubnetsResults, err error) {
	if err := api.checkCanRead(); err != nil {
		return params.ListSubnetsResults{}, err
	}

	return networkingcommon.ListSubnets(api.backing, args)
}
Example #2
0
func (s *SubnetsSuite) TestListSubnetsAndFiltering(c *gc.C) {
	expected := []params.Subnet{{
		CIDR:       "10.10.0.0/24",
		ProviderId: "sn-zadf00d",
		VLANTag:    0,
		Life:       "",
		SpaceTag:   "space-private",
		Zones:      []string{"zone1"},
		Status:     "",
	}, {
		CIDR:       "2001:db8::/32",
		ProviderId: "sn-ipv6",
		VLANTag:    0,
		Life:       "",
		SpaceTag:   "space-dmz",
		Zones:      []string{"zone1", "zone3"},
		Status:     "",
	}}
	// No filtering.
	args := params.SubnetsFilters{}
	subnets, err := networkingcommon.ListSubnets(apiservertesting.BackingInstance, args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(subnets.Results, jc.DeepEquals, expected)

	// Filter by space only.
	args.SpaceTag = "space-dmz"
	subnets, err = networkingcommon.ListSubnets(apiservertesting.BackingInstance, args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(subnets.Results, jc.DeepEquals, expected[1:])

	// Filter by zone only.
	args.SpaceTag = ""
	args.Zone = "zone3"
	subnets, err = networkingcommon.ListSubnets(apiservertesting.BackingInstance, args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(subnets.Results, jc.DeepEquals, expected[1:])

	// Filter by both space and zone.
	args.SpaceTag = "space-private"
	args.Zone = "zone1"
	subnets, err = networkingcommon.ListSubnets(apiservertesting.BackingInstance, args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(subnets.Results, jc.DeepEquals, expected[:1])
}
Example #3
0
// ListSubnets lists all the available subnets or only those matching
// all given optional filters.
func (api *DiscoverSpacesAPI) ListSubnets(args params.SubnetsFilters) (results params.ListSubnetsResults, err error) {
	return networkingcommon.ListSubnets(api.st, args)
}
Example #4
0
// ListSubnets lists all the available subnets or only those matching
// all given optional filters.
func (api *subnetsAPI) ListSubnets(args params.SubnetsFilters) (results params.ListSubnetsResults, err error) {
	return networkingcommon.ListSubnets(api.backing, args)
}
Example #5
0
func (s *SubnetsSuite) TestListSubnetsAllSubnetError(c *gc.C) {
	boom := errors.New("no subnets for you")
	apiservertesting.BackingInstance.SetErrors(boom)
	_, err := networkingcommon.ListSubnets(apiservertesting.BackingInstance, params.SubnetsFilters{})
	c.Assert(err, gc.ErrorMatches, "no subnets for you")
}
Example #6
0
func (s *SubnetsSuite) TestListSubnetsInvalidSpaceTag(c *gc.C) {
	args := params.SubnetsFilters{SpaceTag: "invalid"}
	_, err := networkingcommon.ListSubnets(apiservertesting.BackingInstance, args)
	c.Assert(err, gc.ErrorMatches, `"invalid" is not a valid tag`)
}