summaryrefslogtreecommitdiffstats
path: root/ipalib/frontend.py
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2016-03-02 12:44:15 +0100
committerMartin Basti <mbasti@redhat.com>2016-03-03 10:06:18 +0100
commit3c57c305add17b95d4fb962efd9e5dfc9bd35efe (patch)
treeaf56f2669b8a0d1dbaf991f88a4852df1c47a022 /ipalib/frontend.py
parente5520dc3479f2b1fad947dfd3d52426aef546a37 (diff)
downloadfreeipa-3c57c305add17b95d4fb962efd9e5dfc9bd35efe.tar.gz
freeipa-3c57c305add17b95d4fb962efd9e5dfc9bd35efe.tar.xz
freeipa-3c57c305add17b95d4fb962efd9e5dfc9bd35efe.zip
ipalib: add convenient Command method for adding messages
Call the add_message() method of Command from anywhere in the implementation of a command to add a message to the result of the command. Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipalib/frontend.py')
-rw-r--r--ipalib/frontend.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index e91660d1d..ba830f2dd 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -434,13 +434,17 @@ class Command(HasParam):
return self.__do_call(*args, **options)
def __do_call(self, *args, **options):
- version_provided = 'version' in options
- if version_provided:
+ self.context.__messages = []
+ if 'version' in options:
self.verify_client_version(unicode(options['version']))
elif self.api.env.skip_version_check and not self.api.env.in_server:
options['version'] = u'2.0'
else:
options['version'] = API_VERSION
+ if self.api.env.in_server:
+ # add message only on server side
+ self.add_message(
+ messages.VersionMissing(server_version=API_VERSION))
params = self.args_options_2_params(*args, **options)
self.debug(
'raw: %s(%s)', self.name, ', '.join(self._repr_iter(**params))
@@ -454,12 +458,9 @@ class Command(HasParam):
self.validate(**params)
(args, options) = self.params_2_args_options(**params)
ret = self.run(*args, **options)
- if (not version_provided and isinstance(ret, dict) and
- self.api.env.in_server):
- # add message only on server side
- messages.add_message(
- API_VERSION, ret,
- messages.VersionMissing(server_version=API_VERSION))
+ if isinstance(ret, dict):
+ for message in self.context.__messages:
+ messages.add_message(options['version'], ret, message)
if (
isinstance(ret, dict)
and 'summary' in self.output
@@ -470,6 +471,9 @@ class Command(HasParam):
self.validate_output(ret, options['version'])
return ret
+ def add_message(self, message):
+ self.context.__messages.append(message)
+
def soft_validate(self, values):
errors = dict()
for p in self.params():