@ -41,6 +41,27 @@ class DecortController(object):
based on the requested authentication type .
"""
FIELDS_FOR_SORTING_ACCOUNT_COMPUTE_LIST = [
' cpus ' ,
' createdBy ' ,
' createdTime ' ,
' deletedBy ' ,
' deletedTime ' ,
' id ' ,
' name ' ,
' ram ' ,
' registered ' ,
' rgId ' ,
' rgName ' ,
' status ' ,
' techStatus ' ,
' totalDisksSize ' ,
' updatedBy ' ,
' updatedTime ' ,
' userManaged ' ,
' vinsConnected ' ,
]
FIELDS_FOR_SORTING_ACCOUNT_RG_LIST = [
' createdBy ' ,
' createdTime ' ,
@ -55,6 +76,20 @@ class DecortController(object):
' vinses ' ,
]
COMPUTE_TECH_STATUSES = [
' BACKUP_RUNNING ' ,
' BACKUP_STOPPED ' ,
' DOWN ' ,
' MIGRATING ' ,
' PAUSED ' ,
' PAUSING ' ,
' SCHEDULED ' ,
' STARTED ' ,
' STARTING ' ,
' STOPPED ' ,
' STOPPING ' ,
]
RESOURCE_GROUP_STATUSES = [
' CREATED ' ,
' DELETED ' ,
@ -1960,6 +1995,7 @@ class DecortController(object):
def account_find ( self , account_name , account_id = 0 ,
resource_consumption = False ,
resource_groups_params : None | dict = None ,
computes_params : None | dict = None ,
fail_if_not_found = False ) :
""" Find cloud account specified by the name and return facts about the account. Knowing account is
required for certain cloud resource management tasks ( e . g . creating new RG ) .
@ -2019,6 +2055,8 @@ class DecortController(object):
self . amodule . fail_json ( * * self . result )
return 0 , None
account_details [ ' computes_amount ' ] = account_details . pop ( ' computes ' )
account_details [ ' createdTime_readable ' ] = self . sec_to_dt_str (
account_details [ ' createdTime ' ]
)
@ -2049,6 +2087,13 @@ class DecortController(object):
* * resource_groups_params
)
if computes_params is not None :
account_details [ ' computes ' ] = \
self . account_computes (
account_id = account_details [ ' id ' ] ,
* * computes_params
)
return account_details [ ' id ' ] , account_details
def account_resource_consumption ( self , account_id : int ,
@ -2131,6 +2176,75 @@ class DecortController(object):
return resource_groups
def account_computes (
self ,
account_id : int ,
compute_id : None | int = None ,
compute_ip : None | str = None ,
compute_name : None | str = None ,
compute_tech_status : None | str = None ,
ext_net_id : None | int = None ,
ext_net_name : None | str = None ,
page_number : int = 1 ,
page_size : None | int = None ,
rg_id : None | int = None ,
rg_name : None | str = None ,
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
) :
self . result [ ' msg ' ] = (
f ' { compute_tech_status } is not valid compute tech status '
f ' for filtering account computes list. '
)
self . amodule . fail_json ( * * self . result )
sort_by = None
if sort_by_field :
if not sort_by_field in self . FIELDS_FOR_SORTING_ACCOUNT_COMPUTE_LIST :
self . result [ ' msg ' ] = (
f ' { sort_by_field } is not valid field for sorting '
f ' account computes list. '
)
self . amodule . fail_json ( * * self . result )
sort_by_prefix = ' + ' if sort_by_asc else ' - '
sort_by = f ' { sort_by_prefix } { sort_by_field } '
api_params = {
' accountId ' : account_id ,
' computeId ' : compute_id ,
' extNetId ' : ext_net_id ,
' extNetName ' : ext_net_name ,
' ipAddress ' : compute_ip ,
' name ' : compute_name ,
' page ' : page_number if page_size else None ,
' rgId ' : rg_id ,
' rgName ' : rg_name ,
' size ' : page_size ,
' sortBy ' : sort_by ,
' techStatus ' : compute_tech_status ,
}
api_resp = self . decort_api_call (
arg_req_function = requests . post ,
arg_api_name = ' /restmachine/cloudapi/account/listComputes ' ,
arg_params = api_params ,
)
computes = api_resp . json ( ) [ ' data ' ]
for c in computes :
c [ ' createdTime_readable ' ] = self . sec_to_dt_str ( c [ ' createdTime ' ] )
c [ ' deletedTime_readable ' ] = self . sec_to_dt_str ( c [ ' deletedTime ' ] )
c [ ' updatedTime_readable ' ] = self . sec_to_dt_str ( c [ ' updatedTime ' ] )
return computes
###################################
# GPU resource manipulation methods
###################################