Commit 1fbdb104 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

more python client side API stuff for configuration


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@555 e5f2f494-b856-4b98-b285-d166d9295462
parent c3e6c86c
......@@ -104,6 +104,8 @@ class ConfigManager:
elif cmd[0] == "get_config":
# we may not have any configuration here
conf_part = None
print("[XX] bind-cfgd got command:")
print(cmd)
if len(cmd) > 1:
try:
conf_part = data.find(self.config.data, cmd[1]['module_name'])
......
......@@ -23,16 +23,42 @@
# made there as well
from ISC.CC import Session
import isc
class CCSession:
def __init__(self, module_name, spec_file_name):
def __init__(self, module_name, spec_file_name,
config_handler, command_handler):
self._module_name = module_name
self._spec_file_name = spec_file_name
#self._spec_file_name = spec_file_name
self._config_handler = config_handler
self._command_handler = command_handler
self._data_definition = isc.config.DataDefinition(spec_file_name)
self._session = Session()
self._session.group_subscribe(module_name, "*")
self._session.group_sendmsg(self._data_definition.getDefinition(), "ConfigManager")
answer, env = self._session.group_recvmsg(False)
self._session.group_sendmsg({ "command": [ "get_config", { "module_name": module_name } ] }, "ConfigManager")
answer, env = self._session.group_recvmsg(False)
if self._config_handler:
self._config_handler(answer["result"])
print(answer)
#do we need getSocket()?
def check_command():
pass
def checkCommand():
"""Check whether there is a command on the channel.
Call the command callback function if so"""
msg, env = self._session.group_recvmsg(False)
answer = None
if msg:
if "config_update" in msg and self._config_handler:
self._config_handler(msg["config_update"])
answer = { "result": [ 0 ] }
if "command" in msg and self._command_handler:
answer = self._command_handler(msg["command"])
if answer:
self._session.group_reply(env, answer)
# Copyright (C) 2009 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# This class holds the data definition and validates data agains that
# definition. It is the python equivalent of data_def.h
#
import ast
# file objects are passed around as _io.TextIOWrapper objects
# import that so we can check those types
import _io
class DataDefinitionError(Exception):
pass
class DataDefinition:
def __init__(self, spec_file, check = True):
if type(spec_file) == _io.TextIOWrapper:
self._data_spec = __read_data_spec_file(spec_file)
elif type(spec_file) == str:
file = open(spec_file)
self._data_spec = self.__readDataSpecFile(file)
file.close()
else:
raise DataDefinitionError("Not a str or file-like object")
def validate(self, data):
"""Check whether the given piece of data conforms to this
data definition"""
# "TODO"
return True
def __readDataSpecFile(self, file, check = True):
"""Reads the data spec from the given file object.
If check is True, check whether it is of the correct form.
If it is not, an DataDefinitionError exception is raised"""
if type(file) != _io.TextIOWrapper:
raise DataDefinitionError("Not a file-like object:" + str(type(file)))
str = file.read()
# TODO catch error here and reraise as a less ugly exception
data_spec = ast.literal_eval(str)
if check:
# TODO
_check(data_spec)
pass
return data_spec
def getDefinition(self):
return self._data_spec
def _check(data_spec):
if "data_specification" not in data_spec:
raise DataDefinitionError("no data_specification element in specification")
if "config_data" in data_spec:
_check_config_spec(data_spec["config_data"])
if "commands" in data_spec:
_check_config_spec(data_spec["commands"])
def _checkConfigSpec(config_data):
# TODO
pass
def _checkCommandSpec(commands):
# TODO
pass
from isc.config.CCSession import *
from isc.config.DataDefinition import *
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment