// 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 }
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") }
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") }
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) }
// 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) }
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) }
// 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 }
func (s *SpacesSuite) TestSuppportsSpaces(c *gc.C) { err := networkingcommon.SupportsSpaces(apiservertesting.BackingInstance) c.Assert(err, jc.ErrorIsNil) }