Commit d5314b0f authored by Jelte Jansen's avatar Jelte Jansen
Browse files

more verbose manager

fixed naming in session.py (and switched result values)


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@156 e5f2f494-b856-4b98-b285-d166d9295462
parent 753a0416
......@@ -17,7 +17,17 @@ class ConfigManager:
self.config = ConfigData()
def notify_boss(self):
self.cc.group_sendmsg({"Running": "ConfigManager"}, "Boss")
self.cc.group_sendmsg({"running": "configmanager"}, "Boss")
def add_zone(self, zone_name):
self.config.add_zone(zone_name, "todo")
print "sending update zone add"
self.cc.group_sendmsg({"zone_added": zone_name }, "ParkingLot")
def remove_zone(self, zone_name):
self.config.remove_zone(zone_name)
print "sending update zone del"
self.cc.group_sendmsg({"zone_deleted": zone_name }, "ParkingLot")
def read_config(self, filename):
pass
......@@ -25,11 +35,41 @@ class ConfigManager:
def write_config(self, filename):
pass
def handle_msg(self, msg):
"""return answer message"""
answer = {}
try:
cmd = msg["command"]
if cmd:
if cmd[0] == "zone" and cmd[1] == "add":
self.add_zone(cmd[2])
answer["result"] = [ 0 ]
elif cmd[0] == "zone" and cmd[1] == "del":
self.remove_zone(cmd[2])
answer["result"] = [ 0 ]
elif cmd[o] == "zone" and cmd[1] == "list":
answer["result"] = self.zones.keys()
else:
print "unknown command: " + cmd
answer["result"] = [ 1, "Unknown command: " + cmd ]
except KeyError, ke:
print "unknown module: " + str(msg)
answer["result"] = [ 1, "Unknown module: " + str(msg) ]
except IndexError, ie:
print "missing argument"
answer["result"] = [ 1, "Missing argument in command" ]
return answer
def run(self):
while (True):
env, msg = self.cc.group_recvmsg(False)
print "message: "
msg, env = self.cc.group_recvmsg(False)
print "received message: "
print msg
answer = self.handle_msg(msg);
print "sending answer: "
print answer
self.cc.group_reply(env, answer)
print "answer sent"
pass
if __name__ == "__main__":
......
......@@ -131,11 +131,11 @@ class Session:
return seq
def group_recvmsg(self, nonblock = True):
msg = self.recvmsg(nonblock)
if msg == None:
env = self.recvmsg(nonblock)
if env == None:
return None
data = Message.from_wire(msg["msg"])
return (data, msg)
msg = Message.from_wire(env["msg"])
return (msg, env)
def group_reply(self, routing, msg):
seq = self._next_sequence()
......
......@@ -115,14 +115,30 @@ class Session
end
def group_sendmsg(msg, group, instance = "*", to = "*")
seq = next_sequence
sendmsg({ :type => "send",
:from => @lname,
:to => to,
:group => group,
:instance => instance,
:seq => next_sequence,
:seq => seq,
:msg => CC::Message.to_wire(msg),
})
seq
end
def group_sendmsg(routing, msg)
seq = next_sequence
sendmsg({ :type => "send",
:from => @lname,
:to => routing["from"],
:group => routing["group"],
:instance => routing["instance"],
:seq => seq,
:reply => fouring["seq"],
:msg => CC::Message.to_wire(msg),
})
seq
end
def group_recvmsg(nonblock = true)
......
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