def is_api_enabled(self, project_id):
"""Checks if the Compute API is enabled for the specified project.
Args:
project_id (str): The project id.
Returns:
bool: True if the API is enabled, else False.
"""
try:
result = self.repository.projects.get(project_id, fields='name')
return bool('name' in result) # True if name, otherwise False.
except (errors.HttpError, HttpLib2Error) as e:
api_not_enabled, _ = _api_not_enabled(e)
if api_not_enabled:
return False
raise api_errors.ApiExecutionError(project_id, e)
评论列表
文章目录