@@ -466,6 +466,35 @@ def update_encryption_key(self, kms_id: str) -> bool:
466466
467467 return True
468468
469+ def check_licenses (self ) -> Dict [str , Any ]:
470+ """Check licenses for all available instances in a given project."""
471+ response_dict : Dict [str , Any ] = {}
472+ print (
473+ f"Checking CloudEndure Licenses - Name: ({ self .project_name } )"
474+ )
475+
476+ now : datetime = datetime .datetime .now (datetime .timezone .utc )
477+ expirationday : timedelta = datetime .timedelta (days = 90 )
478+ expirationwarn : timedelta = datetime .timedelta (days = 60 )
479+ machine_data_dict : Dict [str , Any ] = {}
480+ machines_response : Response = self .api .api_call (
481+ f"projects/{ self .project_id } /machines"
482+ )
483+ for machine in json .loads (machines_response .text ).get ("items" , []):
484+ source_props : Dict [str , Any ] = machine .get ("sourceProperties" , {})
485+ machine_id : str = machine .get ("id" )
486+ machine_name : str = source_props .get ("name" )
487+ license_data : Dict [str , Any ] = machine .get ("license" , {})
488+ license_use : str = license_data .get ("startOfUseDateTime" )
489+ license_date : datetime = datetime .datetime .strptime (license_use , '%Y-%m-%dT%H:%M:%S.%f%z' )
490+ delta : timedelta = now - license_date
491+ if (expirationday < delta ):
492+ response_dict [machine_name ] = { "machine_id" : machine_id , "status" : "expired" , "delta_days" : delta .days }
493+ elif (expirationwarn < delta ):
494+ response_dict [machine_name ] = { "machine_id" : machine_id , "status" : "warn" , "delta_days" : delta .days }
495+
496+ return response_dict
497+
469498 def update_blueprint (self ) -> bool :
470499 """Update the blueprint associated with the specified machines."""
471500 print (
0 commit comments