Prepare compatibility with OSC
This change prepares a compatibility layer to be able to use the Gnocchi cli command with OSC cli. Change-Id: Ia8b21d0269def10d7861e1436e05085a92c2130c
This commit is contained in:
parent
1dbe4e2cde
commit
368e6c8d11
|
@ -207,3 +207,9 @@ def encode_resource_id(value):
|
|||
'transformable resource id >255 max allowed characters')
|
||||
except Exception as e:
|
||||
raise ValueError(e)
|
||||
|
||||
|
||||
def get_client(obj):
|
||||
# TODO(sileht): return the location of Gnocchi client when the app is the
|
||||
# OSC one instead of the Gnocchi one
|
||||
return obj.app.client
|
||||
|
|
|
@ -25,7 +25,7 @@ class CliArchivePolicyList(lister.Lister):
|
|||
'back_window', 'definition', 'aggregation_methods')
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
policies = self.app.client.archive_policy.list()
|
||||
policies = utils.get_client(self).archive_policy.list()
|
||||
for ap in policies:
|
||||
utils.format_archive_policy(ap)
|
||||
return utils.list2cols(self.COLS, policies)
|
||||
|
@ -41,7 +41,7 @@ class CliArchivePolicyShow(show.ShowOne):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
ap = self.app.client.archive_policy.get(
|
||||
ap = utils.get_client(self).archive_policy.get(
|
||||
name=parsed_args.name)
|
||||
utils.format_archive_policy(ap)
|
||||
return self.dict2columns(ap)
|
||||
|
@ -86,7 +86,7 @@ class CliArchivePolicyCreate(show.ShowOne):
|
|||
archive_policy = utils.dict_from_parsed_args(
|
||||
parsed_args, ['name', 'back_window', 'aggregation_methods',
|
||||
'definition'])
|
||||
ap = self.app.client.archive_policy.create(
|
||||
ap = utils.get_client(self).archive_policy.create(
|
||||
archive_policy=archive_policy)
|
||||
utils.format_archive_policy(ap)
|
||||
return self.dict2columns(ap)
|
||||
|
@ -102,4 +102,4 @@ class CliArchivePolicyDelete(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client.archive_policy.delete(name=parsed_args.name)
|
||||
utils.get_client(self).archive_policy.delete(name=parsed_args.name)
|
||||
|
|
|
@ -24,7 +24,7 @@ class CliArchivePolicyRuleList(lister.Lister):
|
|||
COLS = ('name', 'archive_policy_name', 'metric_pattern')
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
ap_rules = self.app.client.archive_policy_rule.list()
|
||||
ap_rules = utils.get_client(self).archive_policy_rule.list()
|
||||
return utils.list2cols(self.COLS, ap_rules)
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ class CliArchivePolicyRuleShow(show.ShowOne):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
ap_rule = self.app.client.archive_policy_rule.get(
|
||||
ap_rule = utils.get_client(self).archive_policy_rule.get(
|
||||
name=parsed_args.name)
|
||||
return self.dict2columns(ap_rule)
|
||||
|
||||
|
@ -62,7 +62,7 @@ class CliArchivePolicyRuleCreate(show.ShowOne):
|
|||
def take_action(self, parsed_args):
|
||||
rule = utils.dict_from_parsed_args(
|
||||
parsed_args, ["name", "metric_pattern", "archive_policy_name"])
|
||||
policy = self.app.client.archive_policy_rule.create(rule)
|
||||
policy = utils.get_client(self).archive_policy_rule.create(rule)
|
||||
return self.dict2columns(policy)
|
||||
|
||||
|
||||
|
@ -76,4 +76,4 @@ class CliArchivePolicyRuleDelete(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client.archive_policy_rule.delete(parsed_args.name)
|
||||
utils.get_client(self).archive_policy_rule.delete(parsed_args.name)
|
||||
|
|
|
@ -13,10 +13,12 @@
|
|||
|
||||
from cliff import show
|
||||
|
||||
from gnocchiclient import utils
|
||||
|
||||
|
||||
class CliCapabilitiesList(show.ShowOne):
|
||||
"""List capabilities"""
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
caps = self.app.client.capabilities.list()
|
||||
caps = utils.get_client(self).capabilities.list()
|
||||
return self.dict2columns(caps)
|
||||
|
|
|
@ -35,7 +35,7 @@ class CliMetricList(lister.Lister):
|
|||
COLS = ('id', 'archive_policy/name', 'name', 'resource_id')
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
metrics = self.app.client.metric.list()
|
||||
metrics = utils.get_client(self).metric.list()
|
||||
for metric in metrics:
|
||||
utils.format_archive_policy(metric["archive_policy"])
|
||||
utils.format_move_dict_to_root(metric, "archive_policy")
|
||||
|
@ -52,7 +52,7 @@ class CliMetricShow(CliMetricWithResourceID, show.ShowOne):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
metric = self.app.client.metric.get(
|
||||
metric = utils.get_client(self).metric.get(
|
||||
metric=parsed_args.metric,
|
||||
resource_id=parsed_args.resource_id)
|
||||
utils.format_archive_policy(metric["archive_policy"])
|
||||
|
@ -89,7 +89,7 @@ class CliMetricCreate(CliMetricCreateBase):
|
|||
def _take_action(self, metric, parsed_args):
|
||||
if parsed_args.name:
|
||||
metric['name'] = parsed_args.name
|
||||
metric = self.app.client.metric.create(metric)
|
||||
metric = utils.get_client(self).metric.create(metric)
|
||||
utils.format_archive_policy(metric["archive_policy"])
|
||||
utils.format_move_dict_to_root(metric, "archive_policy")
|
||||
utils.format_resource_for_metric(metric)
|
||||
|
@ -107,8 +107,8 @@ class CliMetricDelete(CliMetricWithResourceID):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
for metric in parsed_args.metric:
|
||||
self.app.client.metric.delete(metric=metric,
|
||||
resource_id=parsed_args.resource_id)
|
||||
utils.get_client(self).metric.delete(
|
||||
metric=metric, resource_id=parsed_args.resource_id)
|
||||
|
||||
|
||||
class CliMeasuresShow(CliMetricWithResourceID, lister.Lister):
|
||||
|
@ -131,7 +131,7 @@ class CliMeasuresShow(CliMetricWithResourceID, lister.Lister):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
measures = self.app.client.metric.get_measures(
|
||||
measures = utils.get_client(self).metric.get_measures(
|
||||
metric=parsed_args.metric,
|
||||
resource_id=parsed_args.resource_id,
|
||||
aggregation=parsed_args.aggregation,
|
||||
|
@ -165,7 +165,7 @@ class CliMeasuresAdd(CliMeasuresAddBase):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client.metric.add_measures(
|
||||
utils.get_client(self).metric.add_measures(
|
||||
metric=parsed_args.metric,
|
||||
resource_id=parsed_args.resource_id,
|
||||
measures=parsed_args.measure,
|
||||
|
@ -191,13 +191,13 @@ class CliMeasuresBatch(command.Command):
|
|||
class CliMetricsMeasuresBatch(CliMeasuresBatch):
|
||||
def take_action(self, parsed_args):
|
||||
with parsed_args.file as f:
|
||||
self.app.client.metric.batch_metrics_measures(json.load(f))
|
||||
utils.get_client(self).metric.batch_metrics_measures(json.load(f))
|
||||
|
||||
|
||||
class CliResourcesMetricsMeasuresBatch(CliMeasuresBatch):
|
||||
def take_action(self, parsed_args):
|
||||
with parsed_args.file as f:
|
||||
self.app.client.metric.batch_resources_metrics_measures(
|
||||
utils.get_client(self).metric.batch_resources_metrics_measures(
|
||||
json.load(f))
|
||||
|
||||
|
||||
|
@ -233,7 +233,7 @@ class CliMeasuresAggregation(lister.Lister):
|
|||
if len(parsed_args.metric) != 1:
|
||||
raise ValueError("One metric is required if query is provided")
|
||||
metrics = parsed_args.metric[0]
|
||||
measures = self.app.client.metric.aggregation(
|
||||
measures = utils.get_client(self).metric.aggregation(
|
||||
metrics=metrics,
|
||||
query=parsed_args.query,
|
||||
aggregation=parsed_args.aggregation,
|
||||
|
|
|
@ -48,7 +48,7 @@ class CliResourceList(lister.Lister):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resources = self.app.client.resource.list(
|
||||
resources = utils.get_client(self).resource.list(
|
||||
resource_type=parsed_args.resource_type,
|
||||
**self._get_pagination_options(parsed_args))
|
||||
return utils.list2cols(self.COLS, resources)
|
||||
|
@ -77,7 +77,7 @@ class CliResourceHistory(CliResourceList):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resources = self.app.client.resource.history(
|
||||
resources = utils.get_client(self).resource.history(
|
||||
resource_type=parsed_args.resource_type,
|
||||
resource_id=parsed_args.resource_id,
|
||||
**self._get_pagination_options(parsed_args))
|
||||
|
@ -93,7 +93,7 @@ class CliResourceSearch(CliResourceList):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resources = self.app.client.resource.search(
|
||||
resources = utils.get_client(self).resource.search(
|
||||
resource_type=parsed_args.resource_type,
|
||||
query=parsed_args.query,
|
||||
**self._get_pagination_options(parsed_args))
|
||||
|
@ -118,7 +118,7 @@ class CliResourceShow(show.ShowOne):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
res = self.app.client.resource.get(
|
||||
res = utils.get_client(self).resource.get(
|
||||
resource_type=parsed_args.resource_type,
|
||||
resource_id=parsed_args.resource_id)
|
||||
normalize_metrics(res)
|
||||
|
@ -158,8 +158,9 @@ class CliResourceCreate(show.ShowOne):
|
|||
or parsed_args.create_metric
|
||||
or (update and parsed_args.delete_metric)):
|
||||
if update:
|
||||
r = self.app.client.resource.get(parsed_args.resource_type,
|
||||
parsed_args.resource_id)
|
||||
r = utils.get_client(self).resource.get(
|
||||
parsed_args.resource_type,
|
||||
parsed_args.resource_id)
|
||||
default = r['metrics']
|
||||
for metric_name in parsed_args.delete_metric:
|
||||
try:
|
||||
|
@ -184,7 +185,7 @@ class CliResourceCreate(show.ShowOne):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
resource = self._resource_from_args(parsed_args)
|
||||
res = self.app.client.resource.create(
|
||||
res = utils.get_client(self).resource.create(
|
||||
resource_type=parsed_args.resource_type, resource=resource)
|
||||
normalize_metrics(res)
|
||||
return self.dict2columns(res)
|
||||
|
@ -202,7 +203,7 @@ class CliResourceUpdate(CliResourceCreate):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
resource = self._resource_from_args(parsed_args, update=True)
|
||||
res = self.app.client.resource.update(
|
||||
res = utils.get_client(self).resource.update(
|
||||
resource_type=parsed_args.resource_type,
|
||||
resource_id=parsed_args.resource_id,
|
||||
resource=resource)
|
||||
|
@ -220,7 +221,7 @@ class CliResourceDelete(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client.resource.delete(parsed_args.resource_id)
|
||||
utils.get_client(self).resource.delete(parsed_args.resource_id)
|
||||
|
||||
|
||||
class CliResourceTypeList(lister.Lister):
|
||||
|
@ -230,5 +231,5 @@ class CliResourceTypeList(lister.Lister):
|
|||
'resource_controller_url')
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resources = self.app.client.resource.list_types()
|
||||
resources = utils.get_client(self).resource.list_types()
|
||||
return self.COLS, list(resources.items())
|
||||
|
|
|
@ -24,7 +24,7 @@ class CliResourceTypeList(lister.Lister):
|
|||
COLS = ('name', 'attributes')
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
resource_types = self.app.client.resource_type.list()
|
||||
resource_types = utils.get_client(self).resource_type.list()
|
||||
for resource_type in resource_types:
|
||||
resource_type['attributes'] = utils.format_dict_dict(
|
||||
resource_type['attributes'])
|
||||
|
@ -75,7 +75,8 @@ class CliResourceTypeCreate(show.ShowOne):
|
|||
resource_type = {'name': parsed_args.name}
|
||||
if parsed_args.attribute:
|
||||
resource_type['attributes'] = dict(parsed_args.attribute)
|
||||
res = self.app.client.resource_type.create(resource_type=resource_type)
|
||||
res = utils.get_client(self).resource_type.create(
|
||||
resource_type=resource_type)
|
||||
utils.format_resource_type(res)
|
||||
return self.dict2columns(res)
|
||||
|
||||
|
@ -89,7 +90,7 @@ class CliResourceTypeShow(show.ShowOne):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
res = self.app.client.resource_type.get(name=parsed_args.name)
|
||||
res = utils.get_client(self).resource_type.get(name=parsed_args.name)
|
||||
utils.format_resource_type(res)
|
||||
return self.dict2columns(res)
|
||||
|
||||
|
@ -103,4 +104,4 @@ class CliResourceTypeDelete(command.Command):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client.resource_type.delete(parsed_args.name)
|
||||
utils.get_client(self).resource_type.delete(parsed_args.name)
|
||||
|
|
|
@ -13,12 +13,14 @@
|
|||
|
||||
from cliff import show
|
||||
|
||||
from gnocchiclient import utils
|
||||
|
||||
|
||||
class CliStatusShow(show.ShowOne):
|
||||
"""Show the status of measurements processing"""
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
status = self.app.client.status.get()
|
||||
status = utils.get_client(self).status.get()
|
||||
|
||||
return self.dict2columns({
|
||||
"storage/total number of measures to process":
|
||||
|
|
Loading…
Reference in New Issue