[svn] commit: r831 - in /branches/jelte-configuration/src: bin/bind10/bind10.py.in bin/bind10/bob.spec bin/bindctl/bindcmd.py lib/config/python/isc/config/ccsession.py lib/config/python/isc/config/config_data.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Feb 16 09:50:04 UTC 2010
Author: jelte
Date: Tue Feb 16 09:50:03 2010
New Revision: 831
Log:
type checking on client side
implemented sample print_settings command
Modified:
branches/jelte-configuration/src/bin/bind10/bind10.py.in
branches/jelte-configuration/src/bin/bind10/bob.spec
branches/jelte-configuration/src/bin/bindctl/bindcmd.py
branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py
branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py
Modified: branches/jelte-configuration/src/bin/bind10/bind10.py.in
==============================================================================
--- branches/jelte-configuration/src/bin/bind10/bind10.py.in (original)
+++ branches/jelte-configuration/src/bin/bind10/bind10.py.in Tue Feb 16 09:50:03 2010
@@ -148,8 +148,10 @@
print(command[1]["message"])
answer = isc.config.ccsession.create_answer(0)
elif cmd == "print_settings":
- print("Config:")
- print(self.ccs.get_config())
+ print("Full Config:")
+ full_config = self.ccs.get_full_config()
+ for item in full_config:
+ print(item + ": " + str(full_config[item]))
answer = isc.config.ccsession.create_answer(0)
else:
answer = isc.config.ccsession.create_answer(1, "Unknown command")
Modified: branches/jelte-configuration/src/bin/bind10/bob.spec
==============================================================================
--- branches/jelte-configuration/src/bin/bind10/bob.spec (original)
+++ branches/jelte-configuration/src/bin/bind10/bob.spec Tue Feb 16 09:50:03 2010
@@ -29,12 +29,7 @@
{
"command_name": "print_settings",
"command_description": "Print some_string and some_int to stdout",
- "command_args": [ {
- "item_name": "message",
- "item_type": "string",
- "item_optional": True,
- "item_default": ""
- } ]
+ "command_args": []
},
{
"command_name": "shutdown",
Modified: branches/jelte-configuration/src/bin/bindctl/bindcmd.py
==============================================================================
--- branches/jelte-configuration/src/bin/bindctl/bindcmd.py (original)
+++ branches/jelte-configuration/src/bin/bindctl/bindcmd.py Tue Feb 16 09:50:03 2010
@@ -446,13 +446,16 @@
elif cmd.command == "remove":
self.config_data.remove_value(identifier, cmd.params['value'])
elif cmd.command == "set":
- parsed_value = None
- try:
- parsed_value = ast.literal_eval(cmd.params['value'])
- except Exception as exc:
- # ok could be an unquoted string, interpret as such
- parsed_value = cmd.params['value']
- self.config_data.set_value(identifier, parsed_value)
+ if 'identifier' not in cmd.params:
+ print("Error: missing identifier or value")
+ else:
+ parsed_value = None
+ try:
+ parsed_value = ast.literal_eval(cmd.params['value'])
+ except Exception as exc:
+ # ok could be an unquoted string, interpret as such
+ parsed_value = cmd.params['value']
+ self.config_data.set_value(identifier, parsed_value)
elif cmd.command == "unset":
self.config_data.unset(identifier)
elif cmd.command == "revert":
Modified: branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py
==============================================================================
--- branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py (original)
+++ branches/jelte-configuration/src/lib/config/python/isc/config/ccsession.py Tue Feb 16 09:50:03 2010
@@ -117,6 +117,10 @@
"""Returns the current or non-default configuration"""
return self._config_data.get_local_config()
+ def get_full_config(self):
+ """Returns the current or non-default configuration"""
+ return self._config_data.get_full_config()
+
def get_config_data(self):
"""Returns the config_data part of the specification"""
return self._config_data
Modified: branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py
==============================================================================
--- branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py (original)
+++ branches/jelte-configuration/src/lib/config/python/isc/config/config_data.py Tue Feb 16 09:50:03 2010
@@ -25,36 +25,31 @@
class ConfigDataError(Exception): pass
-#
-# hmm, these are more relevant for datadefition
-# should we (re)move them?
-#
def check_type(specification, value):
"""Returns true if the value is of the correct type given the
- specification"""
+ specification part relevant for the value"""
if type(specification) == list:
data_type = "list"
else:
data_type = specification['item_type']
if data_type == "integer" and type(value) != int:
- raise DataTypeError(str(value) + " should be an integer")
+ raise isc.cc.data.DataTypeError(str(value) + " is not an integer")
elif data_type == "real" and type(value) != double:
- raise DataTypeError(str(value) + " should be a real")
+ raise isc.cc.data.DataTypeError(str(value) + " is not a real")
elif data_type == "boolean" and type(value) != boolean:
- raise DataTypeError(str(value) + " should be a boolean")
+ raise isc.cc.data.DataTypeError(str(value) + " is not a boolean")
elif data_type == "string" and type(value) != str:
- raise DataTypeError(str(value) + " should be a string")
+ raise isc.cc.data.DataTypeError(str(value) + " is not a string")
elif data_type == "list":
if type(value) != list:
- raise DataTypeError(str(value) + " should be a list, not a " + str(value.__class__.__name__))
+ raise isc.cc.data.DataTypeError(str(value) + " is not a list")
else:
- # todo: check subtypes etc
for element in value:
check_type(specification['list_item_spec'], element)
elif data_type == "map" and type(value) != dict:
- # todo: check subtypes etc
- raise DataTypeError(str(value) + " should be a map")
+ # todo: check types of map contents too
+ raise isc.cc.data.DataTypeError(str(value) + " is not a map")
def find_spec(element, identifier):
"""find the data definition for the given identifier
@@ -119,20 +114,20 @@
self.specification = specification
self.data = {}
- def get_item_list(self, identifier = None):
+ def get_item_list(self, identifier = None, recurse = False):
if identifier:
- spec = find_spec(self.specification, identifier)
+ spec = find_spec(self.specification.get_config_spec(), identifier, recurse)
return spec_name_list(spec, identifier + "/")
- return spec_name_list(self.specification)
+ return spec_name_list(self.specification.get_config_spec(), "", recurse)
def get_value(self, identifier):
"""Returns a tuple where the first item is the value at the
given identifier, and the second item is a bool which is
true if the value is an unset default"""
- value = find_no_exc(self.data, identifier)
+ value = isc.cc.data.find_no_exc(self.data, identifier)
if value:
return value, False
- spec = find_spec(self.specification, identifier)
+ spec = find_spec(self.specification.get_config_data(), identifier)
if spec and 'item_default' in spec:
return spec['item_default'], True
return None, False
@@ -148,7 +143,15 @@
def get_local_config(self):
"""Returns the non-default config values in a dict"""
- return self.config();
+ return self.data;
+
+ def get_full_config(self):
+ items = self.get_item_list(None, True)
+ result = []
+ for item in items:
+ value, default = self.get_value(item)
+ result.append(item + ": " + str(value))
+ return result
#def get_identifiers(self):
# Returns a list containing all identifiers
@@ -271,7 +274,6 @@
module, sep, id = identifier.partition('/')
spec = self.get_specification(module)
if spec:
- print("[XX] getpartspec")
spec_part = find_spec(spec.get_config_data(), id)
print(spec_part)
if type(spec_part) == list:
@@ -279,7 +281,6 @@
entry = {}
entry['name'] = item['item_name']
entry['type'] = item['item_type']
- print("[XX] getvalue")
value, status = self.get_value("/" + identifier + "/" + item['item_name'])
entry['value'] = value
if status == self.LOCAL:
@@ -295,8 +296,6 @@
item = spec_part
if item['item_type'] == 'list':
li_spec = item['list_item_spec']
- print("[XX] item:")
- print(item)
l, status = self.get_value("/" + identifier)
if l:
for value in l:
@@ -328,8 +327,9 @@
def set_value(self, identifier, value):
"""Set the local value at the given identifier to value"""
- # todo: validate
- isc.cc.data.set(self._local_changes, identifier, value)
+ spec_part = self.find_spec_part(identifier)
+ if check_type(spec_part, value):
+ isc.cc.data.set(self._local_changes, identifier, value)
def get_config_item_list(self, identifier = None):
"""Returns a list of strings containing the item_names of
@@ -354,7 +354,6 @@
self.request_specifications()
self.request_current_config()
a,b = self._data.get_value("/Boss/some_string")
- print("[XX] a,b: " + str(a) + ", " + str(b))
def request_specifications(self):
# this step should be unnecessary but is the current way cmdctl returns stuff
@@ -403,9 +402,9 @@
raise DataTypeError(identifier + " is not a list")
value = parse_value_str(value_str)
check_type(data_spec, [value])
- cur_list = find_no_exc(self.config_changes, identifier)
- if not cur_list:
- cur_list = find_no_exc(self.config.data, identifier)
+ cur_list = isc.cc.data.find_no_exc(self.config_changes, identifier)
+ if not cur_list:
+ cur_list = isc.cc.data.find_no_exc(self.config.data, identifier)
if not cur_list:
cur_list = []
if value in cur_list:
@@ -459,8 +458,6 @@
def get_data_specifications(self, conn):
specs = {}
allspecs = conn.send_GET('/config_spec')
- print("[XX] allspecs:")
- print(allspecs)
def set(self, identifier, value):
@@ -517,8 +514,6 @@
default: true if the value has been changed
Throws DataNotFoundError if the identifier is bad
"""
- print("[XX] config:")
- print(self.config)
spec = find_spec(self.config, identifier)
result = []
if type(spec) == dict:
@@ -561,9 +556,9 @@
raise DataTypeError(identifier + " is not a list")
value = parse_value_str(value_str)
check_type(data_spec, [value])
- cur_list = find_no_exc(self.config_changes, identifier)
- if not cur_list:
- cur_list = find_no_exc(self.config.data, identifier)
+ cur_list = isc.cc.data.find_no_exc(self.config_changes, identifier)
+ if not cur_list:
+ cur_list = isc.cc.data.find_no_exc(self.config.data, identifier)
if not cur_list:
cur_list = []
if value not in cur_list:
@@ -576,9 +571,9 @@
raise DataTypeError(identifier + " is not a list")
value = parse_value_str(value_str)
check_type(data_spec, [value])
- cur_list = find_no_exc(self.config_changes, identifier)
- if not cur_list:
- cur_list = find_no_exc(self.config.data, identifier)
+ cur_list = isc.cc.data.find_no_exc(self.config_changes, identifier)
+ if not cur_list:
+ cur_list = isc.cc.data.find_no_exc(self.config.data, identifier)
if not cur_list:
cur_list = []
if value in cur_list:
More information about the bind10-changes
mailing list