Beispiel #1
0
// Networker returns an object that provides access to the
// Networker API facade. The id argument is reserved for future use
// and currently needs to be empty.
func (r *srvRoot) Networker(id string) (*networker.NetworkerAPI, error) {
	if id != "" {
		// Safeguard id for possible future use.
		return nil, common.ErrBadId
	}
	return networker.NewNetworkerAPI(r.srv.state, r.resources, r)
}
Beispiel #2
0
func (s *networkerSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)

	s.setUpNetworks(c)
	s.setUpMachine(c)
	s.setUpContainers(c)

	// Create a FakeAuthorizer so we can check permissions,
	// set up assuming we logged in as a machine agent.
	s.authorizer = apiservertesting.FakeAuthorizer{
		LoggedIn:     true,
		MachineAgent: true,
		Tag:          s.machine.Tag(),
	}

	// Create the resource registry separately to track invocations to
	// Register.
	s.resources = common.NewResources()

	// Create a networker API for the machine.
	var err error
	s.networker, err = networker.NewNetworkerAPI(
		s.State,
		s.resources,
		s.authorizer,
	)
	c.Assert(err, gc.IsNil)
}
Beispiel #3
0
func (s *networkerSuite) TestNetworkerNonMachineAgent(c *gc.C) {
	// Fails with not a machine agent
	anAuthorizer := s.authorizer
	anAuthorizer.MachineAgent = false
	aNetworker, err := networker.NewNetworkerAPI(s.State, s.resources, anAuthorizer)
	c.Assert(err, gc.ErrorMatches, "permission denied")
	c.Assert(aNetworker, gc.IsNil)
}
Beispiel #4
0
func (s *networkerSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)

	s.setUpNetworks(c)
	s.setUpMachine(c)
	s.setUpContainers(c)

	// Create a FakeAuthorizer so we can check permissions,
	// set up assuming we logged in as a machine agent.
	s.authorizer = apiservertesting.FakeAuthorizer{
		LoggedIn:     true,
		MachineAgent: true,
		Tag:          s.machine.Tag(),
	}

	// Create a networker API for the machine.
	var err error
	s.networker, err = networker.NewNetworkerAPI(
		s.State,
		nil,
		s.authorizer,
	)
	c.Assert(err, gc.IsNil)
}