1
// Copyright 2014, 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
11
"github.com/juju/juju/api/action"
12
"github.com/juju/juju/apiserver/params"
13
"github.com/juju/juju/cmd/modelcmd"
16
// type APIClient represents the action API functionality.
17
type APIClient interface {
20
// Enqueue takes a list of Actions and queues them up to be executed by
21
// the designated ActionReceiver, returning the params.Action for each
22
// queued Action, or an error if there was a problem queueing up the
24
Enqueue(params.Actions) (params.ActionResults, error)
26
// ListAll takes a list of Tags representing ActionReceivers and returns
27
// all of the Actions that have been queued or run by each of those
29
ListAll(params.Entities) (params.ActionsByReceivers, error)
31
// ListPending takes a list of Tags representing ActionReceivers
32
// and returns all of the Actions that are queued for each of those
34
ListPending(params.Entities) (params.ActionsByReceivers, error)
36
// ListCompleted takes a list of Tags representing ActionReceivers
37
// and returns all of the Actions that have been run on each of those
39
ListCompleted(params.Entities) (params.ActionsByReceivers, error)
41
// Cancel attempts to cancel a queued up Action from running.
42
Cancel(params.Actions) (params.ActionResults, error)
44
// ApplicationCharmActions is a single query which uses ApplicationsCharmsActions to
45
// get the charm.Actions for a single Service by tag.
46
ApplicationCharmActions(params.Entity) (map[string]params.ActionSpec, error)
48
// Actions fetches actions by tag. These Actions can be used to get
49
// the ActionReceiver if necessary.
50
Actions(params.Entities) (params.ActionResults, error)
52
// FindActionTagsByPrefix takes a list of string prefixes and finds
53
// corresponding ActionTags that match that prefix.
54
FindActionTagsByPrefix(params.FindTags) (params.FindTagsResults, error)
56
// FindActionsByNames takes a list of names and finds a corresponding list of
57
// Actions for every name.
58
FindActionsByNames(params.FindActionsByNames) (params.ActionsByNames, error)
61
// ActionCommandBase is the base type for action sub-commands.
62
type ActionCommandBase struct {
63
modelcmd.ModelCommandBase
66
// NewActionAPIClient returns a client for the action api endpoint.
67
func (c *ActionCommandBase) NewActionAPIClient() (APIClient, error) {
68
return newAPIClient(c)
71
var newAPIClient = func(c *ActionCommandBase) (APIClient, error) {
72
root, err := c.NewAPIRoot()
74
return nil, errors.Trace(err)
76
return action.NewClient(root), nil