|
@@ -375,7 +375,15 @@ class BindCmdInterpreter(Cmd):
|
|
if cmd.command == "help" or ("help" in cmd.params.keys()):
|
|
if cmd.command == "help" or ("help" in cmd.params.keys()):
|
|
self._handle_help(cmd)
|
|
self._handle_help(cmd)
|
|
elif cmd.module == CONFIG_MODULE_NAME:
|
|
elif cmd.module == CONFIG_MODULE_NAME:
|
|
- self.apply_config_cmd(cmd)
|
|
|
|
|
|
+ try:
|
|
|
|
+ self.apply_config_cmd(cmd)
|
|
|
|
+ except isc.cc.data.DataTypeError as dte:
|
|
|
|
+ print("Error: " + str(dte))
|
|
|
|
+ except isc.cc.data.DataNotFoundError as dnfe:
|
|
|
|
+ print("Error: " + str(dnfe))
|
|
|
|
+ except KeyError as ke:
|
|
|
|
+ print("Error: missing " + str(ke))
|
|
|
|
+ raise ke
|
|
else:
|
|
else:
|
|
self.apply_cmd(cmd)
|
|
self.apply_cmd(cmd)
|
|
|
|
|
|
@@ -398,17 +406,22 @@ class BindCmdInterpreter(Cmd):
|
|
print(CONST_BINDCTL_HELP)
|
|
print(CONST_BINDCTL_HELP)
|
|
for k in self.modules.values():
|
|
for k in self.modules.values():
|
|
n = k.get_name()
|
|
n = k.get_name()
|
|
- if len(n) >= 8:
|
|
|
|
- print("\t%s" % n)
|
|
|
|
|
|
+ if len(n) >= CONST_BINDCTL_HELP_INDENT_WIDTH:
|
|
|
|
+ print(" %s" % n)
|
|
print(textwrap.fill(k.get_desc(),
|
|
print(textwrap.fill(k.get_desc(),
|
|
- initial_indent="\t\t",
|
|
|
|
- subsequent_indent="\t\t",
|
|
|
|
|
|
+ initial_indent=" ",
|
|
|
|
+ subsequent_indent=" " +
|
|
|
|
+ " " * CONST_BINDCTL_HELP_INDENT_WIDTH,
|
|
width=70))
|
|
width=70))
|
|
else:
|
|
else:
|
|
- print(textwrap.fill("%s\t%s" % (k.get_name(), k.get_desc()),
|
|
|
|
- initial_indent="\t",
|
|
|
|
- subsequent_indent="\t\t",
|
|
|
|
- width=70))
|
|
|
|
|
|
+ print(textwrap.fill("%s%s%s" %
|
|
|
|
+ (k.get_name(),
|
|
|
|
+ " "*(CONST_BINDCTL_HELP_INDENT_WIDTH - len(k.get_name())),
|
|
|
|
+ k.get_desc()),
|
|
|
|
+ initial_indent=" ",
|
|
|
|
+ subsequent_indent=" " +
|
|
|
|
+ " " * CONST_BINDCTL_HELP_INDENT_WIDTH,
|
|
|
|
+ width=70))
|
|
|
|
|
|
def onecmd(self, line):
|
|
def onecmd(self, line):
|
|
if line == 'EOF' or line.lower() == "quit":
|
|
if line == 'EOF' or line.lower() == "quit":
|
|
@@ -551,102 +564,94 @@ class BindCmdInterpreter(Cmd):
|
|
Raises a KeyError if the command was not complete
|
|
Raises a KeyError if the command was not complete
|
|
'''
|
|
'''
|
|
identifier = self.location
|
|
identifier = self.location
|
|
- try:
|
|
|
|
- if 'identifier' in cmd.params:
|
|
|
|
- if not identifier.endswith("/"):
|
|
|
|
- identifier += "/"
|
|
|
|
- if cmd.params['identifier'].startswith("/"):
|
|
|
|
- identifier = cmd.params['identifier']
|
|
|
|
- else:
|
|
|
|
- if cmd.params['identifier'].startswith('['):
|
|
|
|
- identifier = identifier[:-1]
|
|
|
|
- identifier += cmd.params['identifier']
|
|
|
|
-
|
|
|
|
- # Check if the module is known; for unknown modules
|
|
|
|
- # we currently deny setting preferences, as we have
|
|
|
|
- # no way yet to determine if they are ok.
|
|
|
|
- module_name = identifier.split('/')[1]
|
|
|
|
- if module_name != "" and (self.config_data is None or \
|
|
|
|
- not self.config_data.have_specification(module_name)):
|
|
|
|
- print("Error: Module '" + module_name + "' unknown or not running")
|
|
|
|
- return
|
|
|
|
|
|
+ if 'identifier' in cmd.params:
|
|
|
|
+ if not identifier.endswith("/"):
|
|
|
|
+ identifier += "/"
|
|
|
|
+ if cmd.params['identifier'].startswith("/"):
|
|
|
|
+ identifier = cmd.params['identifier']
|
|
|
|
+ else:
|
|
|
|
+ if cmd.params['identifier'].startswith('['):
|
|
|
|
+ identifier = identifier[:-1]
|
|
|
|
+ identifier += cmd.params['identifier']
|
|
|
|
+
|
|
|
|
+ # Check if the module is known; for unknown modules
|
|
|
|
+ # we currently deny setting preferences, as we have
|
|
|
|
+ # no way yet to determine if they are ok.
|
|
|
|
+ module_name = identifier.split('/')[1]
|
|
|
|
+ if module_name != "" and (self.config_data is None or \
|
|
|
|
+ not self.config_data.have_specification(module_name)):
|
|
|
|
+ print("Error: Module '" + module_name + "' unknown or not running")
|
|
|
|
+ return
|
|
|
|
|
|
- if cmd.command == "show":
|
|
|
|
- # check if we have the 'all' argument
|
|
|
|
- show_all = False
|
|
|
|
- if 'argument' in cmd.params:
|
|
|
|
- if cmd.params['argument'] == 'all':
|
|
|
|
- show_all = True
|
|
|
|
- elif 'identifier' not in cmd.params:
|
|
|
|
- # no 'all', no identifier, assume this is the
|
|
|
|
- #identifier
|
|
|
|
- identifier += cmd.params['argument']
|
|
|
|
- else:
|
|
|
|
- print("Error: unknown argument " + cmd.params['argument'] + ", or multiple identifiers given")
|
|
|
|
- return
|
|
|
|
- values = self.config_data.get_value_maps(identifier, show_all)
|
|
|
|
- for value_map in values:
|
|
|
|
- line = value_map['name']
|
|
|
|
- if value_map['type'] in [ 'module', 'map' ]:
|
|
|
|
- line += "/"
|
|
|
|
- elif len(value_map) > 1 and value_map['type'] == 'list' \
|
|
|
|
- and (value_map['value'] != []):
|
|
|
|
- # do not print content of non-empty lists if
|
|
|
|
- # we have more data to show
|
|
|
|
- line += "/"
|
|
|
|
- else:
|
|
|
|
- line += "\t" + json.dumps(value_map['value'])
|
|
|
|
- line += "\t" + value_map['type']
|
|
|
|
- line += "\t"
|
|
|
|
- if value_map['default']:
|
|
|
|
- line += "(default)"
|
|
|
|
- if value_map['modified']:
|
|
|
|
- line += "(modified)"
|
|
|
|
- print(line)
|
|
|
|
- elif cmd.command == "show_json":
|
|
|
|
- if identifier == "":
|
|
|
|
- print("Need at least the module to show the configuration in JSON format")
|
|
|
|
|
|
+ if cmd.command == "show":
|
|
|
|
+ # check if we have the 'all' argument
|
|
|
|
+ show_all = False
|
|
|
|
+ if 'argument' in cmd.params:
|
|
|
|
+ if cmd.params['argument'] == 'all':
|
|
|
|
+ show_all = True
|
|
|
|
+ elif 'identifier' not in cmd.params:
|
|
|
|
+ # no 'all', no identifier, assume this is the
|
|
|
|
+ #identifier
|
|
|
|
+ identifier += cmd.params['argument']
|
|
else:
|
|
else:
|
|
- data, default = self.config_data.get_value(identifier)
|
|
|
|
- print(json.dumps(data))
|
|
|
|
- elif cmd.command == "add":
|
|
|
|
- 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'])
|
|
|
|
- else:
|
|
|
|
- self.config_data.remove_value(identifier, None)
|
|
|
|
- elif cmd.command == "set":
|
|
|
|
- if 'identifier' not in cmd.params:
|
|
|
|
- print("Error: missing identifier or value")
|
|
|
|
|
|
+ print("Error: unknown argument " + cmd.params['argument'] + ", or multiple identifiers given")
|
|
|
|
+ return
|
|
|
|
+ values = self.config_data.get_value_maps(identifier, show_all)
|
|
|
|
+ for value_map in values:
|
|
|
|
+ line = value_map['name']
|
|
|
|
+ if value_map['type'] in [ 'module', 'map' ]:
|
|
|
|
+ line += "/"
|
|
|
|
+ elif len(value_map) > 1 and value_map['type'] == 'list' \
|
|
|
|
+ and (value_map['value'] != []):
|
|
|
|
+ # do not print content of non-empty lists if
|
|
|
|
+ # we have more data to show
|
|
|
|
+ line += "/"
|
|
else:
|
|
else:
|
|
- parsed_value = None
|
|
|
|
- try:
|
|
|
|
- parsed_value = json.loads(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":
|
|
|
|
- self.config_data.clear_local_changes()
|
|
|
|
- elif cmd.command == "commit":
|
|
|
|
- self.config_data.commit()
|
|
|
|
- elif cmd.command == "diff":
|
|
|
|
- print(self.config_data.get_local_changes());
|
|
|
|
- elif cmd.command == "go":
|
|
|
|
- self.go(identifier)
|
|
|
|
- except isc.cc.data.DataTypeError as dte:
|
|
|
|
- print("Error: " + str(dte))
|
|
|
|
- except isc.cc.data.DataNotFoundError as dnfe:
|
|
|
|
- print("Error: " + str(dnfe))
|
|
|
|
- except KeyError as ke:
|
|
|
|
- print("Error: missing " + str(ke))
|
|
|
|
- raise ke
|
|
|
|
|
|
+ line += "\t" + json.dumps(value_map['value'])
|
|
|
|
+ line += "\t" + value_map['type']
|
|
|
|
+ line += "\t"
|
|
|
|
+ if value_map['default']:
|
|
|
|
+ line += "(default)"
|
|
|
|
+ if value_map['modified']:
|
|
|
|
+ line += "(modified)"
|
|
|
|
+ print(line)
|
|
|
|
+ elif cmd.command == "show_json":
|
|
|
|
+ if identifier == "":
|
|
|
|
+ print("Need at least the module to show the configuration in JSON format")
|
|
|
|
+ else:
|
|
|
|
+ data, default = self.config_data.get_value(identifier)
|
|
|
|
+ print(json.dumps(data))
|
|
|
|
+ elif cmd.command == "add":
|
|
|
|
+ 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'])
|
|
|
|
+ else:
|
|
|
|
+ self.config_data.remove_value(identifier, None)
|
|
|
|
+ elif cmd.command == "set":
|
|
|
|
+ if 'identifier' not in cmd.params:
|
|
|
|
+ print("Error: missing identifier or value")
|
|
|
|
+ else:
|
|
|
|
+ parsed_value = None
|
|
|
|
+ try:
|
|
|
|
+ parsed_value = json.loads(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":
|
|
|
|
+ self.config_data.clear_local_changes()
|
|
|
|
+ elif cmd.command == "commit":
|
|
|
|
+ self.config_data.commit()
|
|
|
|
+ elif cmd.command == "diff":
|
|
|
|
+ print(self.config_data.get_local_changes());
|
|
|
|
+ elif cmd.command == "go":
|
|
|
|
+ self.go(identifier)
|
|
|
|
|
|
def go(self, identifier):
|
|
def go(self, identifier):
|
|
'''Handles the config go command, change the 'current' location
|
|
'''Handles the config go command, change the 'current' location
|