Refactor watcher API for Action Plan Start

Currently the REST API to start action plan in watcher
is which is same as for update action plan.

PATCH /v1/action_plans

https://docs.openstack.org/watcher/latest/api/v1.html

we need to make it easy to understand like :

POST /v1/action_plans/{action_plan_uuid}/start

the action should be start in above case.
Change-Id: I5353e4aa58d1675d8afb94bea35d9b953514129a
Closes-Bug: #1756274
This commit is contained in:
deepak_mourya
2018-04-10 10:58:02 +05:30
committed by Deepak Mourya
parent 921584ac4b
commit ff57eb73f9
5 changed files with 103 additions and 4 deletions

View File

@@ -337,7 +337,8 @@ class ActionPlansController(rest.RestController):
from the top-level resource ActionPlan."""
_custom_actions = {
'detail': ['GET'],
'start': ['POST'],
'detail': ['GET']
}
def _get_action_plans_collection(self, marker, limit,
@@ -540,7 +541,7 @@ class ActionPlansController(rest.RestController):
if action_plan_to_update[field] != patch_val:
action_plan_to_update[field] = patch_val
if (field == 'state'and
if (field == 'state' and
patch_val == objects.action_plan.State.PENDING):
launch_action_plan = True
@@ -565,3 +566,33 @@ class ActionPlansController(rest.RestController):
pecan.request.context,
action_plan_uuid)
return ActionPlan.convert_with_links(action_plan_to_update)
@wsme_pecan.wsexpose(ActionPlan, types.uuid)
def start(self, action_plan_uuid, **kwargs):
"""Start an action_plan
:param action_plan_uuid: UUID of an action_plan.
"""
action_plan_to_start = api_utils.get_resource(
'ActionPlan', action_plan_uuid, eager=True)
context = pecan.request.context
policy.enforce(context, 'action_plan:start', action_plan_to_start,
action='action_plan:start')
if action_plan_to_start['state'] != \
objects.action_plan.State.RECOMMENDED:
raise Exception.StartError(
state=action_plan_to_start.state)
action_plan_to_start['state'] = objects.action_plan.State.PENDING
action_plan_to_start.save()
applier_client = rpcapi.ApplierAPI()
applier_client.launch_action_plan(pecan.request.context,
action_plan_uuid)
action_plan_to_start = objects.ActionPlan.get_by_uuid(
pecan.request.context, action_plan_uuid)
return ActionPlan.convert_with_links(action_plan_to_start)