Repository URL to install this package:
|
Version:
4.1.94 ▾
|
# Copyright (c) 2020 TrilioData, Inc.
# All Rights Reserved.
""" ProjectQuotaType Interface """
import six
from workloadmgrclient import base
class AllowedQuota(base.Resource):
"""A AllowedQuota describes a grouping of one or more VMs"""
def __repr__(self):
return "<AllowedQuota: %s>" % self.id
def delete(self, allowed_quota_id):
"""Delete this AllowedQuota."""
return self.manager.delete(allowed_quota_id)
def update(
self, quota_type_id, project_id,
allowed_value=None, high_watermark=None
):
"""Update the AllowedQuota"""
return self.manager.update(
quota_type_id, project_id, allowed_value, high_watermark
)
def _add_details(self, info):
if isinstance(info, dict):
for (k, v) in six.iteritems(info):
try:
setattr(self, k, v)
except AttributeError:
pass
class AllowedQuotaManager(base.ManagerWithFind):
"""Manage :class:`AllowedQuota` resources."""
resource_class = AllowedQuota
def list(self, project_id):
"""Get a list of all ProjectQuotaType.
:rtype: list of :class:`ProjectQuotaType`
"""
return self._list(
"/project_allowed_quotas/{}".format(project_id),
"allowed_quotas"
)
def get(self, allowed_quota_id, query_string=None):
"""Show details of a AllowedQuota.
:rtype: an obj of :class:`AllowedQuota`
"""
return self._get(
"/project_allowed_quota/{}".format(allowed_quota_id),
"allowed_quotas"
)
def update(
self, allowed_quota_id, project_id,
allowed_value=None, high_watermark=None
):
"""Update a AllowedQuota.
:rtype: an obj of :class:`AllowedQuota`
"""
body = {"allowed_quotas": {"project_id": project_id}}
if allowed_value:
body["allowed_quotas"].update({"allowed_value": allowed_value})
if high_watermark:
body["allowed_quotas"].update({"high_watermark": high_watermark})
return self._update(
"/update_allowed_quota/{}".format(allowed_quota_id), body
)
def upsert_all(self, project_id, quotas):
"""Upsert a AllowedQuotas.
"""
return self._post(
"/upsert_allowed_quotas/{}".format(project_id), quotas
)
def create(self, quota_type_id, project_id,
allowed_value, high_watermark):
"""Update a AllowedQuota.
:rtype: an obj of :class:`AllowedQuota`
"""
body = {
"allowed_quotas": [
{
"quota_type_id": quota_type_id,
"project_id": project_id,
"allowed_value": allowed_value,
"high_watermark": high_watermark,
}
]
}
return self._create(
"/project_allowed_quotas/{}".format(project_id),
body, "allowed_quotas"
)
def delete(self, allowed_quota_id):
"""Delete a AllowedQuota.
:param allowed_quota_id: The :class:`AllowedQuota` to delete.
"""
self._delete(
"/project_allowed_quotas/{}".format(base.getid(allowed_quota_id))
)