github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/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/cmd" 10 "github.com/juju/errors" 11 "gopkg.in/juju/charm.v5" 12 13 "github.com/juju/juju/api/action" 14 "github.com/juju/juju/apiserver/params" 15 "github.com/juju/juju/cmd/envcmd" 16 ) 17 18 var actionDoc = ` 19 "juju action" executes and manages actions on units; it queues up new actions, 20 monitors the status of running actions, and retrieves the results of completed 21 actions. 22 ` 23 24 var actionPurpose = "execute, manage, monitor, and retrieve results of actions" 25 26 // NewSuperCommand returns a new action super-command. 27 func NewSuperCommand() cmd.Command { 28 actionCmd := cmd.NewSuperCommand( 29 cmd.SuperCommandParams{ 30 Name: "action", 31 Doc: actionDoc, 32 UsagePrefix: "juju", 33 Purpose: actionPurpose, 34 }) 35 actionCmd.Register(envcmd.Wrap(&DefinedCommand{})) 36 actionCmd.Register(envcmd.Wrap(&DoCommand{})) 37 actionCmd.Register(envcmd.Wrap(&FetchCommand{})) 38 actionCmd.Register(envcmd.Wrap(&StatusCommand{})) 39 return actionCmd 40 } 41 42 // type APIClient represents the action API functionality. 43 type APIClient interface { 44 io.Closer 45 46 // Enqueue takes a list of Actions and queues them up to be executed by 47 // the designated ActionReceiver, returning the params.Action for each 48 // queued Action, or an error if there was a problem queueing up the 49 // Action. 50 Enqueue(params.Actions) (params.ActionResults, error) 51 52 // ListAll takes a list of Tags representing ActionReceivers and returns 53 // all of the Actions that have been queued or run by each of those 54 // Entities. 55 ListAll(params.Entities) (params.ActionsByReceivers, error) 56 57 // ListPending takes a list of Tags representing ActionReceivers 58 // and returns all of the Actions that are queued for each of those 59 // Entities. 60 ListPending(params.Entities) (params.ActionsByReceivers, error) 61 62 // ListCompleted takes a list of Tags representing ActionReceivers 63 // and returns all of the Actions that have been run on each of those 64 // Entities. 65 ListCompleted(params.Entities) (params.ActionsByReceivers, error) 66 67 // Cancel attempts to cancel a queued up Action from running. 68 Cancel(params.Actions) (params.ActionResults, error) 69 70 // ServiceCharmActions is a single query which uses ServicesCharmActions to 71 // get the charm.Actions for a single Service by tag. 72 ServiceCharmActions(params.Entity) (*charm.Actions, error) 73 74 // Actions fetches actions by tag. These Actions can be used to get 75 // the ActionReceiver if necessary. 76 Actions(params.Entities) (params.ActionResults, error) 77 78 // FindActionTagsByPrefix takes a list of string prefixes and finds 79 // corresponding ActionTags that match that prefix. 80 FindActionTagsByPrefix(params.FindTags) (params.FindTagsResults, error) 81 } 82 83 // ActionCommandBase is the base type for action sub-commands. 84 type ActionCommandBase struct { 85 envcmd.EnvCommandBase 86 } 87 88 // NewActionAPIClient returns a client for the action api endpoint. 89 func (c *ActionCommandBase) NewActionAPIClient() (APIClient, error) { 90 return newAPIClient(c) 91 } 92 93 var newAPIClient = func(c *ActionCommandBase) (APIClient, error) { 94 root, err := c.NewAPIRoot() 95 if err != nil { 96 return nil, errors.Trace(err) 97 } 98 return action.NewClient(root), nil 99 }