github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/action/action.go (about) 1 // Copyright 2014, 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package action 5 6 import ( 7 "io" 8 9 "github.com/juju/errors" 10 11 "github.com/juju/juju/api/action" 12 "github.com/juju/juju/apiserver/params" 13 "github.com/juju/juju/cmd/modelcmd" 14 ) 15 16 // type APIClient represents the action API functionality. 17 type APIClient interface { 18 io.Closer 19 20 // BestAPIVersion returns the API version that we were able to 21 // determine is supported by both the client and the API Server 22 BestAPIVersion() int 23 24 // Enqueue takes a list of Actions and queues them up to be executed by 25 // the designated ActionReceiver, returning the params.Action for each 26 // queued Action, or an error if there was a problem queueing up the 27 // Action. 28 Enqueue(params.Actions) (params.ActionResults, error) 29 30 // ListAll takes a list of Tags representing ActionReceivers and returns 31 // all of the Actions that have been queued or run by each of those 32 // Entities. 33 ListAll(params.Entities) (params.ActionsByReceivers, error) 34 35 // ListPending takes a list of Tags representing ActionReceivers 36 // and returns all of the Actions that are queued for each of those 37 // Entities. 38 ListPending(params.Entities) (params.ActionsByReceivers, error) 39 40 // ListCompleted takes a list of Tags representing ActionReceivers 41 // and returns all of the Actions that have been run on each of those 42 // Entities. 43 ListCompleted(params.Entities) (params.ActionsByReceivers, error) 44 45 // Cancel attempts to cancel a queued up Action from running. 46 Cancel(params.Entities) (params.ActionResults, error) 47 48 // ApplicationCharmActions is a single query which uses ApplicationsCharmsActions to 49 // get the charm.Actions for a single application by tag. 50 ApplicationCharmActions(params.Entity) (map[string]params.ActionSpec, error) 51 52 // Actions fetches actions by tag. These Actions can be used to get 53 // the ActionReceiver if necessary. 54 Actions(params.Entities) (params.ActionResults, error) 55 56 // FindActionTagsByPrefix takes a list of string prefixes and finds 57 // corresponding ActionTags that match that prefix. 58 FindActionTagsByPrefix(params.FindTags) (params.FindTagsResults, error) 59 60 // FindActionsByNames takes a list of names and finds a corresponding list of 61 // Actions for every name. 62 FindActionsByNames(params.FindActionsByNames) (params.ActionsByNames, error) 63 } 64 65 // ActionCommandBase is the base type for action sub-commands. 66 type ActionCommandBase struct { 67 modelcmd.ModelCommandBase 68 modelcmd.IAASOnlyCommand 69 } 70 71 // NewActionAPIClient returns a client for the action api endpoint. 72 func (c *ActionCommandBase) NewActionAPIClient() (APIClient, error) { 73 return newAPIClient(c) 74 } 75 76 var newAPIClient = func(c *ActionCommandBase) (APIClient, error) { 77 root, err := c.NewAPIRoot() 78 if err != nil { 79 return nil, errors.Trace(err) 80 } 81 return action.NewClient(root), nil 82 }