Board Action.

New board-action command.

Change-Id: I2adb06ed15cd49c9b9e95e688b5c5442c802c63b
changes/87/656487/1
Fabio Verboso 3 years ago
parent 6b8018ccf1
commit 3e8ed1db87
  1. 7
      iotronicclient/v1/board.py
  2. 30
      iotronicclient/v1/board_shell.py

@ -103,3 +103,10 @@ class BoardManager(base.CreateManager):
def update(self, board_id, patch, http_method='PATCH'):
return self._update(resource_id=board_id, patch=patch,
method=http_method)
def board_action(self, board_ident, action, params={}):
path = "%(board)s/action" % {'board': board_ident}
body = {"action": action,
"parameters": params
}
return self._update(path, body, method='POST')

@ -15,6 +15,7 @@ from iotronicclient.common import cliutils
from iotronicclient.common.i18n import _
from iotronicclient.common import utils
from iotronicclient.v1 import resource_fields as res_fields
import json
def _print_board_show(board, fields=None, json=False):
@ -225,3 +226,32 @@ def do_board_update(cc, args):
board = cc.board.update(args.board, patch)
_print_board_show(board, json=args.json)
@cliutils.arg('board',
metavar='<board>',
help="Name or UUID of the board.")
@cliutils.arg('action',
metavar='<action>',
help="action of the plugin.")
@cliutils.arg(
'--params',
metavar='<parameter=value>',
nargs='+',
action='append',
default=[],
help="Parameters of the action")
@cliutils.arg(
'--params-file',
metavar='<params_file>',
help="Json file of parameters")
def do_board_action(cc, args):
"""Execute an action on the board."""
params = {}
if args.params_file:
with open(args.params_file, 'r') as fil:
params = json.load(fil)
elif args.params:
params = {k: v for k, v in (x.split('=') for x in args.params[0])}
result = cc.board.board_action(args.board, args.action, params)
print(_('%s') % result)

Loading…
Cancel
Save