Browse Source

[trac926] add basic handling and some temp config spec

Jelte Jansen 14 years ago
parent
commit
84a16612dd
3 changed files with 69 additions and 16 deletions
  1. 3 2
      src/bin/bindctl/bindcmd.py
  2. 32 0
      src/bin/xfrin/xfrin.spec
  3. 34 14
      src/lib/python/isc/config/ccsession.py

+ 3 - 2
src/bin/bindctl/bindcmd.py

@@ -398,8 +398,9 @@ class BindCmdInterpreter(Cmd):
                 print("Error: " + str(dte))
             except isc.cc.data.DataNotFoundError as dnfe:
                 print("Error: " + str(dnfe))
-            except KeyError as ke:
-                print("Error: missing " + str(ke))
+            # [XX] TODO: add back
+            #except KeyError as ke:
+            #    print("Error: missing " + str(ke))
         else:
             self.apply_cmd(cmd)
 

+ 32 - 0
src/bin/xfrin/xfrin.spec

@@ -46,6 +46,38 @@
           }
           ]
         }
+      },
+      { "item_name": "new_zones",
+        "item_type": "named_map",
+        "item_optional": false,
+        "item_default": {},
+        "named_map_item_spec": {
+          "item_name": "zone",
+          "item_type": "map",
+          "item_default": {},
+          "map_item_spec": [
+          { "item_name": "class",
+            "item_type": "string",
+            "item_optional": false,
+            "item_default": "IN"
+          },
+          {
+            "item_name": "master_addr",
+            "item_type": "string",
+            "item_optional": false,
+            "item_default": ""
+          },
+          { "item_name": "master_port",
+            "item_type": "integer",
+            "item_optional": false,
+            "item_default": 53
+          },
+          { "item_name": "tsig_key",
+            "item_type": "string",
+            "item_optional": true
+          }
+          ]
+        }
       }
     ],
     "commands": [

+ 34 - 14
src/lib/python/isc/config/ccsession.py

@@ -426,6 +426,31 @@ class UIModuleCCSession(MultiConfigData):
             raise ModuleCCSessionError("Bad config version")
         self._set_current_config(config)
 
+    def _add_value_to_list(self, identifier, value):
+        cur_list, status = self.get_value(identifier)
+        if not cur_list:
+            cur_list = []
+
+        if value is None:
+            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 _add_value_to_named_map(self, identifier, value):
+        if value is None:
+            raise isc.cc.data.DataNotFoundError("Need a name to add a new item to named_map " + str(identifier))
+
+        cur_map, status = self.get_value(identifier)
+        if not cur_map:
+            cur_map = {}
+        cur_map[value] = {}
+        self.set_value(identifier, cur_map)
 
     def add_value(self, identifier, value_str = None):
         """Add a value to a configuration list. Raises a DataTypeError
@@ -434,27 +459,22 @@ class UIModuleCCSession(MultiConfigData):
            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")
-
-        cur_list, status = self.get_value(identifier)
-        if not cur_list:
-            cur_list = []
+        if module_spec is None:
+            raise isc.cc.data.DataNotFoundError("Unknown item " + str(identifier))
 
         # 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)
+
+        # the specified element must be a list or a named_map
+        if 'list_item_spec' in module_spec:
+            self._add_value_to_list(identifier, value)
+        elif 'named_map_item_spec' in module_spec:
+            self._add_value_to_named_map(identifier, value)
         else:
-            if "item_default" in module_spec["list_item_spec"]:
-                value = module_spec["list_item_spec"]["item_default"]
+            raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named map")
 
-        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):
         """Remove a value from a configuration list. The value string