ap rule: Use named attributes
This commit is contained in:
6 changed files with 42 additions and 32 deletions
@@ -54,7 +54,8 @@ def gen_ref(ver, title, names):
"signs": "=" * len(name),
"pkg": pkg, "name": name})
gen_ref("v1", "Version 1 API", ["client", "resource", "archivepolicy"])
gen_ref("v1", "Version 1 API", ["client", "resource", "archivepolicy",
"archivepolicyrule"])
# -- General configuration ----------------------------------------------------
@@ -17,9 +17,9 @@ class ArchivePolicyRuleClientTest(base.ClientTestBase):
def test_archive_policy_rule_scenario(self):
# CREATE
result = self.gnocchi(
u'archivepolicyrule', params=u"create -a name:test"
u" -a archive_policy_name:high"
u" -a metric_pattern:disk.io.*")
u'archivepolicyrule', params=u"create test"
u" --archive-policyhigh"
u" --metric-pattern'disk.io.*'")
policy_rule = self.details_multiple(result)[0]
self.assertEqual('test', policy_rule["name"])
@@ -99,3 +99,12 @@ def format_dict_list(objs, field):
"- " + ", ".join("%s: %s" % (k, v)
for k, v in elem.items())
for elem in objs[field])
def dict_from_parsed_args(parsed_args, attrs):
d = {}
for attr in attrs:
value = getattr(parsed_args, attr)
if value is not None:
d[attr] = value
return d
@@ -84,12 +84,9 @@ class CliArchivePolicyCreate(show.ShowOne):
return parser
def take_action(self, parsed_args):
archive_policy = {}
for attr in ['name', 'back_window', 'aggregation_methods']:
value = getattr(parsed_args, attr)
if value is not None:
archive_policy[attr] = value
archive_policy["definition"] = list(parsed_args.definition)
archive_policy = utils.dict_from_parsed_args(
parsed_args, ['name', 'back_window', 'aggregation_methods',
'definition'])
policy = self.app.client.archivepolicy.create(
archive_policy=archive_policy)
return self.dict2columns(policy)
@@ -19,37 +19,37 @@ from gnocchiclient.v1 import base
class ArchivePolicyRuleManager(base.Manager):
def list(self):
"""List archive policies
"""List archive policy rules
"""
url = self.client._build_url("archive_policy_rule")
return self.client.api.get(url).json()
def get(self, policy_rule_name):
"""Get a archive_policy
def get(self, name):
"""Get an archivepolicy rules
:param policy_name: Name of the archive_policy
:param policy_name: Name of the archivepolicy rule
:type policy_name: str
"""
url = self.client._build_url("archive_policy_rule/%s"
% policy_rule_name)
% name)
return self.client.api.get(url).json()
def create(self, data):
"""Create a archive_policy
def create(self, archive_policy_rule):
"""Create an archivepolicy rule
"""
url = self.client._build_url("archive_policy_rule/")
return self.client.api.post(
url, headers={'Content-Type': "application/json"},
data=jsonutils.dumps(data)).json()
data=jsonutils.dumps(archive_policy_rule)).json()
def delete(self, policy_rule_name):
"""Delete a archive_policy
def delete(self, name):
"""Delete an archivepolicy rule
:param policy_name: ID of the archive_policy
:param policy_name: Name of the archivepolicy rule
:type policy_name: str
"""
url = self.client._build_url("archive_policy_rule/%s"
% policy_rule_name)
% name)
self.client.api.delete(url)
@@ -39,25 +39,28 @@ class CliArchivePolicyRuleShow(show.ShowOne):
def take_action(self, parsed_args):
ap_rule = self.app.client.archivepolicyrule.get(
policy_rule_name=parsed_args.name)
name=parsed_args.name)
return self.dict2columns(ap_rule)
class CliArchivePolicyRuleCreate(show.ShowOne):
def get_parser(self, prog_name):
parser = super(CliArchivePolicyRuleCreate, self).get_parser(prog_name)
parser.add_argument("-a", "--attribute", action='append',
help=("name and value of a attribute "
"separated with a ':'"))
parser.add_argument("name",
help=("Rule name"))
parser.add_argument("-a", "--archive-policy-name",
dest="archive_policy_name",
required=True,
help=("Archive policy name"))
parser.add_argument("-m", "--metric-pattern",
dest="metric_pattern", required=True,
help=("Wildcard of metric name to match"))
return parser
def take_action(self, parsed_args):
data = {}
if parsed_args.attribute:
for attr in parsed_args.attribute:
attr, __, value = attr.partition(":")
data[attr] = value
policy = self.app.client.archivepolicyrule.create(data=data)
rule = utils.dict_from_parsed_args(
parsed_args, ["name", "metric_pattern", "archive_policy_name"])
policy = self.app.client.archivepolicyrule.create(rule)
return self.dict2columns(policy)
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.