func newResourceResult(c *gc.C, applicationID string, names ...string) ([]resource.Resource, api.ResourcesResult) { var resources []resource.Resource var apiResult api.ResourcesResult for _, name := range names { data := name + "...spamspamspam" res, apiRes := newResource(c, name, "a-user", data) resources = append(resources, res) apiResult.Resources = append(apiResult.Resources, apiRes) } return resources, apiResult }
// ListResources returns the list of resources for the given service. func (f Facade) ListResources(args api.ListResourcesArgs) (api.ResourcesResults, error) { var r api.ResourcesResults r.Results = make([]api.ResourcesResult, len(args.Entities)) for i, e := range args.Entities { logger.Tracef("Listing resources for %q", e.Tag) tag, apierr := parseServiceTag(e.Tag) if apierr != nil { r.Results[i] = api.ResourcesResult{ ErrorResult: params.ErrorResult{ Error: apierr, }, } continue } svcRes, err := f.store.ListResources(tag.Id()) if err != nil { r.Results[i] = errorResult(err) continue } var result api.ResourcesResult for _, res := range svcRes.Resources { result.Resources = append(result.Resources, api.Resource2API(res)) } for _, unitRes := range svcRes.UnitResources { unit := api.UnitResources{ Entity: params.Entity{Tag: unitRes.Tag.String()}, } for _, res := range unitRes.Resources { unit.Resources = append(unit.Resources, api.Resource2API(res)) } result.UnitResources = append(result.UnitResources, unit) } r.Results[i] = result } return r, nil }