Budget
Smarter API Budget Manifest handler.
A Budget is managed by superusers: only they may apply or delete one. Anyone may get and describe the budgets that are attached to a resource that they may see.
- class smarter.apps.account.manifest.brokers.budget.SAMBudgetBroker(*args, **kwargs)[source]
Bases:
AbstractBrokerBroker for
SAMBudget manifests.The broker converts between Budget manifests and the
BudgetDjango ORM model and itsResourceConstraintattachments, and implements thesmarterCLI commands for Budgets:apply,describe,get,deleteandexample_manifest.spec.resourcesis declarative: applying a manifest attaches the budget to the resources that it lists, and detaches it from the others.- property ORMMetaModelClass: Type[Budget]
Return the Django ORM meta model class for the broker.
- Returns:
The Django ORM meta model class definition for the broker.
- Return type:
- property ORMModelClass: Type[Budget]
Return the Django ORM model class for the broker.
- Returns:
The Django ORM model class definition for the broker.
- Return type:
- property SerializerClass: Type[ModelSerializer]
The Django ORM model serializer class for the Budget.
- apply(request, *args, **kwargs)[source]
Create or update the Budget from the manifest, then attach it to spec.resources, and detach it from the others.
Only superusers may apply a Budget.
- Return type:
- property budget: Budget | None
The Budget with the broker’s name, if it exists.
It is never created here:
apply()does that.
- delete(request, *args, **kwargs)[source]
Delete the Budget, which detaches it from its resources and removes their locks.
Superusers only.
- Return type:
- deploy(request, *args, **kwargs)[source]
Deploy a resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the deploy operation.
- Return type:
- describe(request, *args, **kwargs)[source]
Return the Budget as a manifest, with the budget versus the actual spending of each resource.
- Return type:
- example_manifest(request, *args, **kwargs)[source]
Return an example Budget manifest: a monthly allowance for a student.
- Return type:
- get(request, *args, **kwargs)[source]
Return the Budgets that the user may see, optionally filtered by name.
- Return type:
- is_visible_budget(budget)[source]
Superusers see every budget.
Others see those attached to a resource that they may see.
- Return type:
- logs(request, *args, **kwargs)[source]
Get logs for a resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the logs for the resource.
- Return type:
- property manifest: SAMBudget | None
The Budget manifest, as a Pydantic model, from the manifest loader.
- property orm_instance: Budget | None
Return the Django ORM model instance for the broker.
There are multiple strategies to retrieve the ORM instance:
If the instance is already cached in self._orm_instance, return it.
If the broker is not ready or the name is not set, log a warning and return None.
Attempt to retrieve the ORM instance using the user_profile and name. If not found, attempt to retrieve using the admin user_profile for the account. If still not found, attempt to retrieve using the Smarter platform admin user_profile.
Cache the retrieved instance for future access.
- Returns:
The Django ORM model instance for the broker.
- Return type:
Optional[MetaDataWithOwnershipModel]
- property orm_meta_instance: Budget | None
The Budget.
Budgets are not owned, so the base class’s lookup by owner does not apply.
- prompt(request, *args, **kwargs)[source]
Invoke a prompt operation.
This abstract method should be implemented by subclasses to provide prompt-based interactions with the broker resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the prompt response.
- Return type:
- status_for(budget)[source]
The budget versus the actual spending of each resource that the user may see.
- undeploy(request, *args, **kwargs)[source]
Undeploy a resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the undeploy operation.
- Return type: