Add decorator for adding the name of called method to the string self.result['waypoints'].
This commit is contained in:
@@ -29,6 +29,7 @@ Requirements:
|
||||
"""
|
||||
|
||||
import json
|
||||
from typing import Callable
|
||||
import jwt
|
||||
import netaddr
|
||||
import time
|
||||
@@ -216,6 +217,17 @@ class DecortController(object):
|
||||
# self.run_phase = "Initializing DecortController instance complete."
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def waypoint(orig_f: Callable) -> Callable:
|
||||
"""
|
||||
A decorator for adding the name of called method to the string
|
||||
`self.result['waypoints']`.
|
||||
"""
|
||||
def new_f(self, *args, **kwargs):
|
||||
self.result['waypoints'] += f' -> {orig_f.__name__}'
|
||||
return orig_f(self, *args, **kwargs)
|
||||
return new_f
|
||||
|
||||
@staticmethod
|
||||
def sec_to_dt_str(sec: int, str_format: str = '%Y-%m-%d_%H-%M-%S') -> str:
|
||||
if sec:
|
||||
@@ -2096,10 +2108,9 @@ class DecortController(object):
|
||||
|
||||
return account_details['id'], account_details
|
||||
|
||||
@waypoint
|
||||
def account_resource_consumption(self, account_id: int,
|
||||
fail_if_not_found=False) -> None | dict:
|
||||
self.result['waypoints'] += f' -> account_resource_consumption'
|
||||
|
||||
api_resp = self.decort_api_call(
|
||||
arg_req_function=requests.post,
|
||||
arg_api_name='/restmachine/cloudapi/account/getResourceConsumption',
|
||||
@@ -2115,6 +2126,7 @@ class DecortController(object):
|
||||
" account specified.")
|
||||
self.amodule.fail_json(**self.result)
|
||||
|
||||
@waypoint
|
||||
def account_resource_groups(
|
||||
self,
|
||||
account_id: int,
|
||||
@@ -2128,8 +2140,6 @@ class DecortController(object):
|
||||
vins_id: None | int = None,
|
||||
vm_id: None | int = None,
|
||||
) -> list[dict]:
|
||||
self.result['waypoints'] += f' -> account_resource_groups'
|
||||
|
||||
if rg_status and not rg_status in self.RESOURCE_GROUP_STATUSES:
|
||||
self.result['msg'] = (
|
||||
f'{rg_status} is not valid RG status for filtering'
|
||||
@@ -2176,6 +2186,7 @@ class DecortController(object):
|
||||
|
||||
return resource_groups
|
||||
|
||||
@waypoint
|
||||
def account_computes(
|
||||
self,
|
||||
account_id: int,
|
||||
@@ -2192,8 +2203,6 @@ class DecortController(object):
|
||||
sort_by_asc=True,
|
||||
sort_by_field: None | str = None,
|
||||
) -> list[dict]:
|
||||
self.result['waypoints'] += f' -> account_computes'
|
||||
|
||||
if compute_tech_status and (
|
||||
not compute_tech_status in self.COMPUTE_TECH_STATUSES
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user