From c69d8084c17c5d94240bda9447ed9546159608a5 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 13 Jan 2011 14:29:16 -0500 Subject: Add API version and have server reject incompatible clients. This patch contains 2 parts. The first part is a small utility to create and validate the current API. To do this it needs to load ipalib which on a fresh system introduces a few problems, namely that it relies on a python plugin to set the default encoding to utf8. For our purposes we can skip that. It is also important that any optional plugins be loadable so the API can be examined. The second part is a version exchange between the client and server. The version has a major and a minor version. The major verion is updated whenever existing API changes. The minor version is updated when new API is added. A request will be rejected if either the major versions don't match or if the client major version is higher than then server major version (though by implication new API would return a command not found if allowed to proceed). To determine the API version of the server from a client use the ping command. ticket 584 --- ipalib/cli.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ipalib/cli.py') diff --git a/ipalib/cli.py b/ipalib/cli.py index c5fea8f2..c634d490 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -32,7 +32,14 @@ import fcntl import termios import struct import base64 -import default_encoding_utf8 +try: + import default_encoding_utf8 +except ImportError: + # This is a chicken-and-egg problem. The api can't be imported unless + # this is already installed and since it is installed with IPA therein + # lies the problem. Skip it for now so ipalib can be imported in-tree + # even in cases that IPA isn't installed on the dev machine. + pass import frontend import backend @@ -42,6 +49,7 @@ from errors import PublicError, CommandError, HelpError, InternalError, NoSuchNa from constants import CLI_TAB from parameters import Password, Bytes, File from text import _ +from ipapython.version import API_VERSION def to_cli(name): @@ -884,6 +892,7 @@ class cli(backend.Executioner): if not isinstance(cmd, frontend.Local): self.create_context() kw = self.parse(cmd, argv) + kw['version'] = API_VERSION if self.env.interactive: self.prompt_interactively(cmd, kw) self.load_files(cmd, kw) @@ -931,6 +940,8 @@ class cli(backend.Executioner): dest=option.name, help=unicode(option.doc), ) + if 'no_option' in option.flags: + continue if option.password and self.env.interactive: kw['action'] = 'store_true' elif option.type is bool and option.autofill: -- cgit