Browse Source

make value optional for 'config add <list>'; add the default value that is specified in the spec file in that case
always show map contents for 'config show <map>', not just the map name


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac384@4123 e5f2f494-b856-4b98-b285-d166d9295462

Jelte Jansen 14 years ago
parent
commit
c31de72c76

+ 4 - 1
src/bin/bindctl/bindcmd.py

@@ -590,7 +590,10 @@ class BindCmdInterpreter(Cmd):
                     data, default = self.config_data.get_value(identifier)
                     print(json.dumps(data))
             elif cmd.command == "add":
-                self.config_data.add_value(identifier, cmd.params['value'])
+                if 'value' in cmd.params:
+                    self.config_data.add_value(identifier, cmd.params['value'])
+                else:
+                    self.config_data.add_value(identifier)
             elif cmd.command == "remove":
                 if 'value' in cmd.params:
                     self.config_data.remove_value(identifier, cmd.params['value'])

+ 2 - 2
src/bin/bindctl/bindctl-source.py.in

@@ -48,10 +48,10 @@ def prepare_config_commands(tool):
     cmd.add_param(param)
     module.add_command(cmd)
 
-    cmd = CommandInfo(name = "add", desc = "Add entry to configuration list")
+    cmd = CommandInfo(name = "add", desc = "Add an entry to configuration list. If no value is given, a default value is added.")
     param = ParamInfo(name = "identifier", type = "string", optional=True)
     cmd.add_param(param)
-    param = ParamInfo(name = "value", type = "string", optional=False)
+    param = ParamInfo(name = "value", type = "string", optional=True)
     cmd.add_param(param)
     module.add_command(cmd)
 

+ 18 - 3
src/lib/python/isc/config/ccsession.py

@@ -374,19 +374,34 @@ class UIModuleCCSession(MultiConfigData):
         self._set_current_config(config)
 
 
-    def add_value(self, identifier, value_str):
+    def add_value(self, identifier, value_str = None):
         """Add a value to a configuration list. Raises a DataTypeError
            if the value does not conform to the list_item_spec field
-           of the module config data specification"""
+           of the module config data specification. If value_str is
+           not given, we add the default as specified by the .spec
+           file."""
         module_spec = self.find_spec_part(identifier)
         if (type(module_spec) != dict or "list_item_spec" not in module_spec):
             raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list")
-        value = isc.cc.data.parse_value_str(value_str)
+
         cur_list, status = self.get_value(identifier)
         if not cur_list:
             cur_list = []
+
+        # Hmm. Do we need to check for duplicates?
+        value = None
+        if value_str is not None:
+            value = isc.cc.data.parse_value_str(value_str)
+        else:
+            if "item_default" in module_spec["list_item_spec"]:
+                value = module_spec["list_item_spec"]["item_default"]
+
+        if value is None:
+            raise isc.cc.data.DataNotFoundError("No value given and no default for " + str(identifier))
+            
         if value not in cur_list:
             cur_list.append(value)
+
         self.set_value(identifier, cur_list)
 
     def remove_value(self, identifier, value_str):

+ 4 - 12
src/lib/python/isc/config/config_data.py

@@ -432,7 +432,7 @@ class MultiConfigData:
                 spec_part_list = spec_part['list_item_spec']
                 list_value, status = self.get_value(identifier)
                 if list_value is None:
-                    print("Error: %s not found" % identifier)
+                    print("Error: identifier '%s' not found" % identifier)
                     return
                 if type(list_value) != list:
                     # the identifier specified a single element
@@ -448,18 +448,10 @@ class MultiConfigData:
                         for i in range(len(list_value)):
                             self._append_value_item(result, spec_part_list, "%s[%d]" % (identifier, i), all)
             elif item_type == "map":
+                # just show the specific contents of a map, we are
+                # almost never interested in just its name
                 spec_part_map = spec_part['map_item_spec']
-                value, status = self.get_value(identifier)
-                # if there are no contents, simply add the value
-                # as one empty element, otherwise append them
-                # individually
-                if value != {}:
-                    self._append_value_item(result, spec_part_map, identifier, all)
-                else:
-                    entry = _create_value_map_entry(identifier,
-                                                    item_type,
-                                                    {}, status)
-                    result.append(entry)
+                self._append_value_item(result, spec_part_map, identifier, all)
             else:
                 value, status = self.get_value(identifier)
                 entry = _create_value_map_entry(identifier,