ccsession.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. # Copyright (C) 2009 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. #
  16. # Client-side functionality for configuration and commands
  17. #
  18. # It keeps a cc-channel session with the configuration manager daemon,
  19. # and handles configuration updates and direct commands
  20. # modeled after ccsession.h/cc 'protocol' changes here need to be
  21. # made there as well
  22. """Classes and functions for handling configuration and commands
  23. This module provides the ModuleCCSession and UIModuleCCSession
  24. classes, as well as a set of utility functions to create and parse
  25. messages related to commands and configuration
  26. Modules should use the ModuleCCSession class to connect to the
  27. configuration manager, and receive updates and commands from
  28. other modules.
  29. Configuration user interfaces should use the UIModuleCCSession
  30. to connect to b10-cmdctl, and receive and send configuration and
  31. commands through that to the configuration manager.
  32. """
  33. from isc.cc import Session
  34. from isc.config.config_data import ConfigData, MultiConfigData, BIND10_CONFIG_DATA_VERSION
  35. import isc
  36. from isc.util.file import path_search
  37. import bind10_config
  38. from isc.log import log_config_update
  39. import json
  40. from isc.log_messages.config_messages import *
  41. logger = isc.log.Logger("config")
  42. class ModuleCCSessionError(Exception): pass
  43. def parse_answer(msg):
  44. """Returns a tuple (rcode, value), where value depends on the
  45. command that was called. If rcode != 0, value is a string
  46. containing an error message"""
  47. if type(msg) != dict:
  48. raise ModuleCCSessionError("Answer message is not a dict: " + str(msg))
  49. if 'result' not in msg:
  50. raise ModuleCCSessionError("answer message does not contain 'result' element")
  51. elif type(msg['result']) != list:
  52. raise ModuleCCSessionError("wrong result type in answer message")
  53. elif len(msg['result']) < 1:
  54. raise ModuleCCSessionError("empty result list in answer message")
  55. elif type(msg['result'][0]) != int:
  56. raise ModuleCCSessionError("wrong rcode type in answer message")
  57. else:
  58. if len(msg['result']) > 1:
  59. if (msg['result'][0] != 0 and type(msg['result'][1]) != str):
  60. raise ModuleCCSessionError("rcode in answer message is non-zero, value is not a string")
  61. return msg['result'][0], msg['result'][1]
  62. else:
  63. return msg['result'][0], None
  64. def create_answer(rcode, arg = None):
  65. """Creates an answer packet for config&commands. rcode must be an
  66. integer. If rcode == 0, arg is an optional value that depends
  67. on what the command or option was. If rcode != 0, arg must be
  68. a string containing an error message"""
  69. if type(rcode) != int:
  70. raise ModuleCCSessionError("rcode in create_answer() must be an integer")
  71. if rcode != 0 and type(arg) != str:
  72. raise ModuleCCSessionError("arg in create_answer for rcode != 0 must be a string describing the error")
  73. if arg != None:
  74. return { 'result': [ rcode, arg ] }
  75. else:
  76. return { 'result': [ rcode ] }
  77. # 'fixed' commands
  78. """Fixed names for command and configuration messages"""
  79. COMMAND_CONFIG_UPDATE = "config_update"
  80. COMMAND_MODULE_SPECIFICATION_UPDATE = "module_specification_update"
  81. COMMAND_GET_COMMANDS_SPEC = "get_commands_spec"
  82. COMMAND_GET_STATISTICS_SPEC = "get_statistics_spec"
  83. COMMAND_GET_CONFIG = "get_config"
  84. COMMAND_SET_CONFIG = "set_config"
  85. COMMAND_GET_MODULE_SPEC = "get_module_spec"
  86. COMMAND_MODULE_SPEC = "module_spec"
  87. COMMAND_SHUTDOWN = "shutdown"
  88. def parse_command(msg):
  89. """Parses what may be a command message. If it looks like one,
  90. the function returns (command, value) where command is a
  91. string. If it is not, this function returns None, None"""
  92. if type(msg) == dict and len(msg.items()) == 1:
  93. cmd, value = msg.popitem()
  94. if cmd == "command" and type(value) == list:
  95. if len(value) == 1 and type(value[0]) == str:
  96. return value[0], None
  97. elif len(value) > 1 and type(value[0]) == str:
  98. return value[0], value[1]
  99. return None, None
  100. def create_command(command_name, params = None):
  101. """Creates a module command message with the given command name (as
  102. specified in the module's specification, and an optional params
  103. object"""
  104. # TODO: validate_command with spec
  105. if type(command_name) != str:
  106. raise ModuleCCSessionError("command in create_command() not a string")
  107. cmd = [ command_name ]
  108. if params:
  109. cmd.append(params)
  110. msg = { 'command': cmd }
  111. return msg
  112. def default_logconfig_handler(new_config, config_data):
  113. errors = []
  114. if config_data.get_module_spec().validate_config(False, new_config, errors):
  115. isc.log.log_config_update(json.dumps(new_config),
  116. json.dumps(config_data.get_module_spec().get_full_spec()))
  117. else:
  118. logger.error(CONFIG_LOG_CONFIG_ERRORS, errors)
  119. class ModuleCCSession(ConfigData):
  120. """This class maintains a connection to the command channel, as
  121. well as configuration options for modules. The module provides
  122. a specification file that contains the module name, configuration
  123. options, and commands. It also gives the ModuleCCSession two callback
  124. functions, one to call when there is a direct command to the
  125. module, and one to update the configuration run-time. These
  126. callbacks are called when 'check_command' is called on the
  127. ModuleCCSession"""
  128. def __init__(self, spec_file_name, config_handler, command_handler,
  129. cc_session=None, handle_logging_config=True,
  130. socket_file = None):
  131. """Initialize a ModuleCCSession. This does *NOT* send the
  132. specification and request the configuration yet. Use start()
  133. for that once the ModuleCCSession has been initialized.
  134. specfile_name is the path to the specification file.
  135. config_handler and command_handler are callback functions,
  136. see set_config_handler and set_command_handler for more
  137. information on their signatures.
  138. cc_session can be used to pass in an existing CCSession,
  139. if it is None, one will be set up. This is mainly intended
  140. for testing purposes.
  141. handle_logging_config: if True, the module session will
  142. automatically handle logging configuration for the module;
  143. it will read the system-wide Logging configuration and call
  144. the logger manager to apply it. It will also inform the
  145. logger manager when the logging configuration gets updated.
  146. The module does not need to do anything except intializing
  147. its loggers, and provide log messages. Defaults to true.
  148. socket_file: If cc_session was none, this optional argument
  149. specifies which socket file to use to connect to msgq. It
  150. will be overridden by the environment variable
  151. MSGQ_SOCKET_FILE. If none, and no environment variable is
  152. set, it will use the system default.
  153. """
  154. module_spec = isc.config.module_spec_from_file(spec_file_name)
  155. ConfigData.__init__(self, module_spec)
  156. self._module_name = module_spec.get_module_name()
  157. self.set_config_handler(config_handler)
  158. self.set_command_handler(command_handler)
  159. if not cc_session:
  160. self._session = Session(socket_file)
  161. else:
  162. self._session = cc_session
  163. self._session.group_subscribe(self._module_name, "*")
  164. self._remote_module_configs = {}
  165. self._remote_module_callbacks = {}
  166. if handle_logging_config:
  167. self.add_remote_config(path_search('logging.spec', bind10_config.PLUGIN_PATHS),
  168. default_logconfig_handler)
  169. def __del__(self):
  170. # If the CC Session obejct has been closed, it returns
  171. # immediately.
  172. if self._session._closed: return
  173. self._session.group_unsubscribe(self._module_name, "*")
  174. for module_name in self._remote_module_configs:
  175. self._session.group_unsubscribe(module_name)
  176. def start(self):
  177. """Send the specification for this module to the configuration
  178. manager, and request the current non-default configuration.
  179. The config_handler will be called with that configuration"""
  180. self.__send_spec()
  181. self.__request_config()
  182. def get_socket(self):
  183. """Returns the socket from the command channel session. This
  184. should *only* be used for select() loops to see if there
  185. is anything on the channel. If that loop is not completely
  186. time-critical, it is strongly recommended to only use
  187. check_command(), and not look at the socket at all."""
  188. return self._session._socket
  189. def close(self):
  190. """Close the session to the command channel"""
  191. self._session.close()
  192. def check_command(self, nonblock=True):
  193. """Check whether there is a command or configuration update on
  194. the channel. This function does a read on the cc session, and
  195. returns nothing.
  196. It calls check_command_without_recvmsg()
  197. to parse the received message.
  198. If nonblock is True, it just checks if there's a command
  199. and does nothing if there isn't. If nonblock is False, it
  200. waits until it arrives. It temporarily sets timeout to infinity,
  201. because commands may not come in arbitrary long time."""
  202. timeout_orig = self._session.get_timeout()
  203. self._session.set_timeout(0)
  204. try:
  205. msg, env = self._session.group_recvmsg(nonblock)
  206. finally:
  207. self._session.set_timeout(timeout_orig)
  208. self.check_command_without_recvmsg(msg, env)
  209. def check_command_without_recvmsg(self, msg, env):
  210. """Parse the given message to see if there is a command or a
  211. configuration update. Calls the corresponding handler
  212. functions if present. Responds on the channel if the
  213. handler returns a message."""
  214. # should we default to an answer? success-by-default? unhandled error?
  215. if msg is not None and not 'result' in msg:
  216. answer = None
  217. try:
  218. module_name = env['group']
  219. cmd, arg = isc.config.ccsession.parse_command(msg)
  220. if cmd == COMMAND_CONFIG_UPDATE:
  221. new_config = arg
  222. # If the target channel was not this module
  223. # it might be in the remote_module_configs
  224. if module_name != self._module_name:
  225. if module_name in self._remote_module_configs:
  226. # no checking for validity, that's up to the
  227. # module itself.
  228. newc = self._remote_module_configs[module_name].get_local_config()
  229. isc.cc.data.merge(newc, new_config)
  230. self._remote_module_configs[module_name].set_local_config(newc)
  231. if self._remote_module_callbacks[module_name] != None:
  232. self._remote_module_callbacks[module_name](new_config,
  233. self._remote_module_configs[module_name])
  234. # For other modules, we're not supposed to answer
  235. return
  236. # ok, so apparently this update is for us.
  237. errors = []
  238. if not self._config_handler:
  239. answer = create_answer(2, self._module_name + " has no config handler")
  240. elif not self.get_module_spec().validate_config(False, new_config, errors):
  241. answer = create_answer(1, ", ".join(errors))
  242. else:
  243. isc.cc.data.remove_identical(new_config, self.get_local_config())
  244. answer = self._config_handler(new_config)
  245. rcode, val = parse_answer(answer)
  246. if rcode == 0:
  247. newc = self.get_local_config()
  248. isc.cc.data.merge(newc, new_config)
  249. self.set_local_config(newc)
  250. else:
  251. # ignore commands for 'remote' modules
  252. if module_name == self._module_name:
  253. if self._command_handler:
  254. answer = self._command_handler(cmd, arg)
  255. else:
  256. answer = create_answer(2, self._module_name + " has no command handler")
  257. except Exception as exc:
  258. answer = create_answer(1, str(exc))
  259. if answer:
  260. self._session.group_reply(env, answer)
  261. def set_config_handler(self, config_handler):
  262. """Set the config handler for this module. The handler is a
  263. function that takes the full configuration and handles it.
  264. It should return an answer created with create_answer()"""
  265. self._config_handler = config_handler
  266. # should we run this right now since we've changed the handler?
  267. def set_command_handler(self, command_handler):
  268. """Set the command handler for this module. The handler is a
  269. function that takes a command as defined in the .spec file
  270. and return an answer created with create_answer()"""
  271. self._command_handler = command_handler
  272. def add_remote_config(self, spec_file_name, config_update_callback = None):
  273. """Gives access to the configuration of a different module.
  274. These remote module options can at this moment only be
  275. accessed through get_remote_config_value(). This function
  276. also subscribes to the channel of the remote module name
  277. to receive the relevant updates. It is not possible to
  278. specify your own handler for this right now.
  279. start() must have been called on this CCSession
  280. prior to the call to this method.
  281. Returns the name of the module."""
  282. module_spec = isc.config.module_spec_from_file(spec_file_name)
  283. module_cfg = ConfigData(module_spec)
  284. module_name = module_spec.get_module_name()
  285. self._session.group_subscribe(module_name)
  286. # Get the current config for that module now
  287. seq = self._session.group_sendmsg(create_command(COMMAND_GET_CONFIG, { "module_name": module_name }), "ConfigManager")
  288. try:
  289. answer, env = self._session.group_recvmsg(False, seq)
  290. except isc.cc.SessionTimeout:
  291. raise ModuleCCSessionError("No answer from ConfigManager when "
  292. "asking about Remote module " +
  293. module_name)
  294. if answer:
  295. rcode, value = parse_answer(answer)
  296. if rcode == 0:
  297. if value != None and module_spec.validate_config(False, value):
  298. module_cfg.set_local_config(value)
  299. if config_update_callback is not None:
  300. config_update_callback(value, module_cfg)
  301. # all done, add it
  302. self._remote_module_configs[module_name] = module_cfg
  303. self._remote_module_callbacks[module_name] = config_update_callback
  304. return module_name
  305. def remove_remote_config(self, module_name):
  306. """Removes the remote configuration access for this module"""
  307. if module_name in self._remote_module_configs:
  308. self._session.group_unsubscribe(module_name)
  309. del self._remote_module_configs[module_name]
  310. del self._remote_module_callbacks[module_name]
  311. def get_remote_config_value(self, module_name, identifier):
  312. """Returns the current setting for the given identifier at the
  313. given module. If the module has not been added with
  314. add_remote_config, a ModuleCCSessionError is raised"""
  315. if module_name in self._remote_module_configs:
  316. return self._remote_module_configs[module_name].get_value(identifier)
  317. else:
  318. raise ModuleCCSessionError("Remote module " + module_name +
  319. " not found")
  320. def __send_spec(self):
  321. """Sends the data specification to the configuration manager"""
  322. msg = create_command(COMMAND_MODULE_SPEC, self.get_module_spec().get_full_spec())
  323. seq = self._session.group_sendmsg(msg, "ConfigManager")
  324. try:
  325. answer, env = self._session.group_recvmsg(False, seq)
  326. except isc.cc.SessionTimeout:
  327. # TODO: log an error?
  328. pass
  329. def __request_config(self):
  330. """Asks the configuration manager for the current configuration, and call the config handler if set.
  331. Raises a ModuleCCSessionError if there is no answer from the configuration manager"""
  332. seq = self._session.group_sendmsg(create_command(COMMAND_GET_CONFIG, { "module_name": self._module_name }), "ConfigManager")
  333. try:
  334. answer, env = self._session.group_recvmsg(False, seq)
  335. if answer:
  336. rcode, value = parse_answer(answer)
  337. if rcode == 0:
  338. errors = []
  339. if value != None:
  340. if self.get_module_spec().validate_config(False,
  341. value,
  342. errors):
  343. self.set_local_config(value)
  344. if self._config_handler:
  345. self._config_handler(value)
  346. else:
  347. raise ModuleCCSessionError(
  348. "Wrong data in configuration: " +
  349. " ".join(errors))
  350. else:
  351. logger.error(CONFIG_GET_FAILED, value)
  352. else:
  353. raise ModuleCCSessionError("No answer from configuration manager")
  354. except isc.cc.SessionTimeout:
  355. raise ModuleCCSessionError("CC Session timeout waiting for configuration manager")
  356. class UIModuleCCSession(MultiConfigData):
  357. """This class is used in a configuration user interface. It contains
  358. specific functions for getting, displaying, and sending
  359. configuration settings through the b10-cmdctl module."""
  360. def __init__(self, conn):
  361. """Initialize a UIModuleCCSession. The conn object that is
  362. passed must have send_GET and send_POST functions"""
  363. MultiConfigData.__init__(self)
  364. self._conn = conn
  365. self.request_specifications()
  366. self.request_current_config()
  367. def request_specifications(self):
  368. """Request the module specifications from b10-cmdctl"""
  369. # this step should be unnecessary but is the current way cmdctl returns stuff
  370. # so changes are needed there to make this clean (we need a command to simply get the
  371. # full specs for everything, including commands etc, not separate gets for that)
  372. specs = self._conn.send_GET('/module_spec')
  373. for module in specs.keys():
  374. self.set_specification(isc.config.ModuleSpec(specs[module]))
  375. def update_specs_and_config(self):
  376. self.request_specifications()
  377. self.request_current_config()
  378. def request_current_config(self):
  379. """Requests the current configuration from the configuration
  380. manager through b10-cmdctl, and stores those as CURRENT"""
  381. config = self._conn.send_GET('/config_data')
  382. if 'version' not in config or config['version'] != BIND10_CONFIG_DATA_VERSION:
  383. raise ModuleCCSessionError("Bad config version")
  384. self._set_current_config(config)
  385. def _add_value_to_list(self, identifier, value, module_spec):
  386. cur_list, status = self.get_value(identifier)
  387. if not cur_list:
  388. cur_list = []
  389. if value is None:
  390. if "item_default" in module_spec["list_item_spec"]:
  391. value = module_spec["list_item_spec"]["item_default"]
  392. if value is None:
  393. raise isc.cc.data.DataNotFoundError(
  394. "No value given and no default for " + str(identifier))
  395. if value not in cur_list:
  396. cur_list.append(value)
  397. self.set_value(identifier, cur_list)
  398. else:
  399. raise isc.cc.data.DataAlreadyPresentError(value +
  400. " already in "
  401. + identifier)
  402. def _add_value_to_named_set(self, identifier, value, item_value):
  403. if type(value) != str:
  404. raise isc.cc.data.DataTypeError("Name for named_set " +
  405. identifier +
  406. " must be a string")
  407. # fail on both None and empty string
  408. if not value:
  409. raise isc.cc.data.DataNotFoundError(
  410. "Need a name to add a new item to named_set " +
  411. str(identifier))
  412. else:
  413. cur_map, status = self.get_value(identifier)
  414. if not cur_map:
  415. cur_map = {}
  416. if value not in cur_map:
  417. cur_map[value] = item_value
  418. self.set_value(identifier, cur_map)
  419. else:
  420. raise isc.cc.data.DataAlreadyPresentError(value +
  421. " already in "
  422. + identifier)
  423. def add_value(self, identifier, value_str = None, set_value_str = None):
  424. """Add a value to a configuration list. Raises a DataTypeError
  425. if the value does not conform to the list_item_spec field
  426. of the module config data specification. If value_str is
  427. not given, we add the default as specified by the .spec
  428. file. Raises a DataNotFoundError if the given identifier
  429. is not specified in the specification as a map or list.
  430. Raises a DataAlreadyPresentError if the specified element
  431. already exists."""
  432. module_spec = self.find_spec_part(identifier)
  433. if module_spec is None:
  434. raise isc.cc.data.DataNotFoundError("Unknown item " + str(identifier))
  435. # the specified element must be a list or a named_set
  436. if 'list_item_spec' in module_spec:
  437. value = None
  438. # in lists, we might get the value with spaces, making it
  439. # the third argument. In that case we interpret both as
  440. # one big string meant as the value
  441. if value_str is not None:
  442. if set_value_str is not None:
  443. value_str += set_value_str
  444. value = isc.cc.data.parse_value_str(value_str)
  445. self._add_value_to_list(identifier, value, module_spec)
  446. elif 'named_set_item_spec' in module_spec:
  447. item_name = None
  448. item_value = None
  449. if value_str is not None:
  450. item_name = isc.cc.data.parse_value_str(value_str)
  451. if set_value_str is not None:
  452. item_value = isc.cc.data.parse_value_str(set_value_str)
  453. else:
  454. if 'item_default' in module_spec['named_set_item_spec']:
  455. item_value = module_spec['named_set_item_spec']['item_default']
  456. self._add_value_to_named_set(identifier, item_name,
  457. item_value)
  458. else:
  459. raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named set")
  460. def _remove_value_from_list(self, identifier, value):
  461. if value is None:
  462. # we are directly removing a list index
  463. id, list_indices = isc.cc.data.split_identifier_list_indices(identifier)
  464. if list_indices is None:
  465. raise isc.cc.data.DataTypeError("identifier in remove_value() does not contain a list index, and no value to remove")
  466. else:
  467. self.set_value(identifier, None)
  468. else:
  469. cur_list, status = self.get_value(identifier)
  470. if not cur_list:
  471. cur_list = []
  472. elif value in cur_list:
  473. cur_list.remove(value)
  474. self.set_value(identifier, cur_list)
  475. def _remove_value_from_named_set(self, identifier, value):
  476. if value is None:
  477. raise isc.cc.data.DataNotFoundError("Need a name to remove an item from named_set " + str(identifier))
  478. elif type(value) != str:
  479. raise isc.cc.data.DataTypeError("Name for named_set " + identifier + " must be a string")
  480. else:
  481. cur_map, status = self.get_value(identifier)
  482. if not cur_map:
  483. cur_map = {}
  484. if value in cur_map:
  485. del cur_map[value]
  486. else:
  487. raise isc.cc.data.DataNotFoundError(value + " not found in named_set " + str(identifier))
  488. def remove_value(self, identifier, value_str):
  489. """Remove a value from a configuration list or named set.
  490. The value string must be a string representation of the full
  491. item. Raises a DataTypeError if the value at the identifier
  492. is not a list, or if the given value_str does not match the
  493. list_item_spec """
  494. module_spec = self.find_spec_part(identifier)
  495. if module_spec is None:
  496. raise isc.cc.data.DataNotFoundError("Unknown item " + str(identifier))
  497. value = None
  498. if value_str is not None:
  499. value = isc.cc.data.parse_value_str(value_str)
  500. if 'list_item_spec' in module_spec:
  501. if value is not None:
  502. isc.config.config_data.check_type(module_spec['list_item_spec'], value)
  503. self._remove_value_from_list(identifier, value)
  504. elif 'named_set_item_spec' in module_spec:
  505. self._remove_value_from_named_set(identifier, value)
  506. else:
  507. raise isc.cc.data.DataNotFoundError(str(identifier) + " is not a list or a named_set")
  508. def commit(self):
  509. """Commit all local changes, send them through b10-cmdctl to
  510. the configuration manager"""
  511. if self.get_local_changes():
  512. response = self._conn.send_POST('/ConfigManager/set_config',
  513. [ self.get_local_changes() ])
  514. answer = isc.cc.data.parse_value_str(response.read().decode())
  515. # answer is either an empty dict (on success), or one
  516. # containing errors
  517. if answer == {}:
  518. self.request_current_config()
  519. self.clear_local_changes()
  520. elif "error" in answer:
  521. raise ModuleCCSessionError("Error: " + str(answer["error"]) + "\n" + "Configuration not committed")
  522. else:
  523. raise ModuleCCSessionError("Unknown format of answer in commit(): " + str(answer))