Add decorator for adding the name of called method to the string `self.result['waypoints']`.

main
Dmitriy Smirnov 7 months ago
parent f230325968
commit 3b2be18346

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

Loading…
Cancel
Save