Ejemplo n.º 1
0
Archivo: spaces.go Proyecto: OSBI/juju
// ListSpaces lists all the available spaces and their associated subnets.
func (api *spacesAPI) ListSpaces() (results params.ListSpacesResults, err error) {
	err = networkingcommon.SupportsSpaces(api.backing)
	if err != nil {
		return results, common.ServerError(errors.Trace(err))
	}

	spaces, err := api.backing.AllSpaces()
	if err != nil {
		return results, errors.Trace(err)
	}

	results.Results = make([]params.Space, len(spaces))
	for i, space := range spaces {
		result := params.Space{}
		result.Name = space.Name()

		subnets, err := space.Subnets()
		if err != nil {
			err = errors.Annotatef(err, "fetching subnets")
			result.Error = common.ServerError(err)
			results.Results[i] = result
			continue
		}

		result.Subnets = make([]params.Subnet, len(subnets))
		for i, subnet := range subnets {
			result.Subnets[i] = networkingcommon.BackingSubnetToParamsSubnet(subnet)
		}
		results.Results[i] = result
	}
	return results, nil
}
Ejemplo n.º 2
0
func (s *SpacesSuite) TestSuppportsSpacesModelConfigError(c *gc.C) {
	apiservertesting.SharedStub.SetErrors(
		errors.New("boom"), // Backing.ModelConfig()
	)

	err := networkingcommon.SupportsSpaces(apiservertesting.BackingInstance)
	c.Assert(err, gc.ErrorMatches, "getting environ: boom")
}
Ejemplo n.º 3
0
func (s *SpacesSuite) TestSuppportsSpacesEnvironNewError(c *gc.C) {
	apiservertesting.SharedStub.SetErrors(
		nil,                // Backing.ModelConfig()
		errors.New("boom"), // environs.New()
	)

	err := networkingcommon.SupportsSpaces(apiservertesting.BackingInstance)
	c.Assert(err, gc.ErrorMatches, "validating model config: boom")
}
Ejemplo n.º 4
0
func (s *SpacesSuite) TestSuppportsSpacesWithoutNetworking(c *gc.C) {
	apiservertesting.BackingInstance.SetUp(
		c,
		apiservertesting.StubEnvironName,
		apiservertesting.WithoutZones,
		apiservertesting.WithoutSpaces,
		apiservertesting.WithoutSubnets)

	err := networkingcommon.SupportsSpaces(apiservertesting.BackingInstance)
	c.Assert(err, jc.Satisfies, errors.IsNotSupported)
}
Ejemplo n.º 5
0
Archivo: worker.go Proyecto: makyo/juju
// New returns a new worker that maintains the mongo replica set
// with respect to the given state.
func New(st *state.State) (worker.Worker, error) {
	cfg, err := st.ModelConfig()
	if err != nil {
		return nil, err
	}
	shim := &stateShim{
		State:     st,
		mongoPort: cfg.StatePort(),
		apiPort:   cfg.APIPort(),
	}
	supportsSpaces := networkingcommon.SupportsSpaces(shim) == nil
	return newWorker(shim, newPublisher(st, cfg.PreferIPv6()), supportsSpaces)
}
Ejemplo n.º 6
0
func (s *SpacesSuite) TestSuppportsSpacesWithoutSpaces(c *gc.C) {
	apiservertesting.BackingInstance.SetUp(
		c,
		apiservertesting.StubNetworkingEnvironName,
		apiservertesting.WithoutZones,
		apiservertesting.WithoutSpaces,
		apiservertesting.WithoutSubnets)

	apiservertesting.SharedStub.SetErrors(
		nil,                // Backing.ModelConfig()
		nil,                // environs.New()
		errors.New("boom"), // Backing.SupportsSpaces()
	)

	err := networkingcommon.SupportsSpaces(apiservertesting.BackingInstance)
	c.Assert(err, jc.Satisfies, errors.IsNotSupported)
}
Ejemplo n.º 7
0
Archivo: spaces.go Proyecto: bac/juju
// ListSpaces lists all the available spaces and their associated subnets.
func (api *spacesAPI) ListSpaces() (results params.ListSpacesResults, err error) {
	canRead, err := api.authorizer.HasPermission(permission.ReadAccess, api.backing.ModelTag())
	if err != nil && !errors.IsNotFound(err) {
		return results, errors.Trace(err)
	}
	if !canRead {
		return results, common.ServerError(common.ErrPerm)
	}

	err = networkingcommon.SupportsSpaces(api.backing)
	if err != nil {
		return results, common.ServerError(errors.Trace(err))
	}

	spaces, err := api.backing.AllSpaces()
	if err != nil {
		return results, errors.Trace(err)
	}

	results.Results = make([]params.Space, len(spaces))
	for i, space := range spaces {
		result := params.Space{}
		result.Name = space.Name()

		subnets, err := space.Subnets()
		if err != nil {
			err = errors.Annotatef(err, "fetching subnets")
			result.Error = common.ServerError(err)
			results.Results[i] = result
			continue
		}

		result.Subnets = make([]params.Subnet, len(subnets))
		for i, subnet := range subnets {
			result.Subnets[i] = networkingcommon.BackingSubnetToParamsSubnet(subnet)
		}
		results.Results[i] = result
	}
	return results, nil
}
Ejemplo n.º 8
0
func (s *SpacesSuite) TestSuppportsSpaces(c *gc.C) {
	err := networkingcommon.SupportsSpaces(apiservertesting.BackingInstance)
	c.Assert(err, jc.ErrorIsNil)
}