Repository URL to install this package:
|
Version:
4.1.94.1 ▾
|
python3-workloadmgrclient
/
usr
/
lib
/
python3
/
dist-packages
/
workloadmgrclient
/
v1
/
allowed_quota.py
|
|---|
import six
from cliff import show, lister
from osc_lib import exceptions
from osc_lib import utils as osc_utils
from workloadmgrclient import utils
from workloadmgrclient.v1.workload import WorkloadCommand
class AllowedQuotaCommand(WorkloadCommand):
resource = "allowed_quotas"
class ListAllowedQuota(AllowedQuotaCommand, lister.Lister):
"""List all the allowed quotas of current project."""
@staticmethod
def _add_arguments(parser):
parser.add_argument(
"project_id", metavar="<project_id>",
help="Project id of allowed_quota."
)
def take_action(self, parsed_args):
client = self.get_client()
quota_type_objs = client.list(parsed_args.project_id) or []
headers = ["ID", "QuotaTypeID", "QuotaTypeName"]
columns = ["id", "quota_type_id", "quota_type_name"]
return (
headers,
(osc_utils.get_item_properties(s, columns) for s in quota_type_objs),
)
class ShowAllowedQuota(AllowedQuotaCommand, show.ShowOne):
"""Show details about a allowed_quota for current project."""
@staticmethod
def _add_arguments(parser):
parser.add_argument(
"allowed_quota_id",
metavar="<allowed_quota_id>",
help="ID of the allowed_quota.",
)
def take_action(self, parsed_args):
"""Show details about a allowed_quota_id."""
client = self.get_client()
allowed_quota_obj = utils.find_resource(
client, parsed_args.allowed_quota_id
)
if not allowed_quota_obj._info:
raise exceptions.CommandError(
"No project allowed quota is present for provided id"
)
info = {}
info.update(allowed_quota_obj._info)
return zip(*sorted(six.iteritems(info)))
class CreateAllowedQuota(AllowedQuotaCommand, show.ShowOne):
"""Create a allowed_quota."""
@staticmethod
def _add_arguments(parser):
parser.add_argument(
"--quota-type-id",
metavar="quota_type_id",
required=True,
help="ID of the quota_type.",
)
parser.add_argument(
"--allowed-value",
metavar="allowed_value",
required=True,
help="Allowed (numeric) value for the quota.",
)
parser.add_argument(
"--high-watermark",
metavar="high_watermark",
required=True,
help="High watermark (numeric) value for the quota for warning.",
)
parser.add_argument(
"--project-id",
metavar="project_id",
required=True,
help="project_id to set a quota for",
)
def take_action(self, parsed_args):
client = self.get_client()
res = client.create(
parsed_args.quota_type_id,
parsed_args.project_id,
parsed_args.allowed_value,
parsed_args.high_watermark,
)
info = {}
if res._info and isinstance(res._info, list):
info.update(res._info[0])
return zip(*sorted(six.iteritems(info)))
else:
raise Exception("Allowed quota creation did go as expected, verification is needed")
class ModifyAllowedQuota(AllowedQuotaCommand, show.ShowOne):
"""Modify a allowed_quota."""
@staticmethod
def _add_arguments(parser):
parser.add_argument(
"allowed_quota_id",
metavar="<allowed_quota_id>",
help="ID of the allowed_quota.",
)
parser.add_argument(
"--allowed-value",
metavar="allowed_value",
help="Allowed (numeric) value for the quota.",
)
parser.add_argument(
"--high-watermark",
metavar="high_watermark",
help="High watermark (numeric) value for the quota for warning.",
)
parser.add_argument(
"--project-id", metavar="project_id",
help="project_id to set a quota for"
)
def take_action(self, parsed_args):
client = self.get_client()
allowed_quota_obj = utils.find_resource(
client, parsed_args.allowed_quota_id
)
res = allowed_quota_obj.update(
parsed_args.allowed_quota_id,
parsed_args.project_id,
parsed_args.allowed_value,
parsed_args.high_watermark,
)
if res.get('allowed_quotas', None) and isinstance(res['allowed_quotas'], list):
return zip(*sorted(six.iteritems(res['allowed_quotas'][0])))
else:
raise Exception("Allowed quota modification did go as expected, verification is needed")
class DeleteAllowedQuota(AllowedQuotaCommand):
"""Remove a allowed_quota."""
@staticmethod
def _add_arguments(parser):
parser.add_argument(
"allowed_quota_id",
metavar="<allowed_quota_id>",
help="ID of the allowed_quota to delete.",
)
def take_action(self, parsed_args):
client = self.get_client()
allowed_quota = utils.find_resource(
client, parsed_args.allowed_quota_id
)
allowed_quota.delete(parsed_args.allowed_quota_id)
return