示例#1
0
// FullStatus gives the information needed for juju status over the api
func (c *Client) FullStatus(args params.StatusParams) (api.Status, error) {
	conn, err := juju.NewConnFromState(c.api.state)
	if err != nil {
		return api.Status{}, err
	}
	var noStatus api.Status
	var context statusContext
	unitMatcher, err := NewUnitMatcher(args.Patterns)
	if err != nil {
		return noStatus, err
	}
	if context.services,
		context.units, context.latestCharms, err = fetchAllServicesAndUnits(conn.State, unitMatcher); err != nil {
		return noStatus, err
	}

	// Filter machines by units in scope.
	var machineIds *set.Strings
	if !unitMatcher.matchesAny() {
		machineIds, err = fetchUnitMachineIds(context.units)
		if err != nil {
			return noStatus, err
		}
	}
	if context.machines, err = fetchMachines(conn.State, machineIds); err != nil {
		return noStatus, err
	}
	if context.relations, err = fetchRelations(conn.State); err != nil {
		return noStatus, err
	}
	if context.networks, err = fetchNetworks(conn.State); err != nil {
		return noStatus, err
	}

	return api.Status{
		EnvironmentName: conn.Environ.Name(),
		Machines:        context.processMachines(),
		Services:        context.processServices(),
		Networks:        context.processNetworks(),
		Relations:       context.processRelations(),
	}, nil
}
示例#2
0
func (s *ConnSuite) TestNewConnFromState(c *gc.C) {
	conn, err := juju.NewConnFromState(s.conn.State)
	c.Assert(err, gc.IsNil)
	c.Assert(conn.Environ.Name(), gc.Equals, dummy.SampleConfig()["name"])
}