|
@@ -211,59 +211,59 @@ class CommandControl():
|
|
|
self.config_data = self.get_config_data()
|
|
|
|
|
|
def get_cmd_specification(self):
|
|
|
- return self.send_command('ConfigManager', 'get_commands_spec')
|
|
|
+ return self.send_command('ConfigManager', isc.config.ccsession.COMMAND_GET_COMMANDS_SPEC)
|
|
|
|
|
|
def get_config_data(self):
|
|
|
'''Get config data for all modules from configmanager '''
|
|
|
- return self.send_command('ConfigManager', 'get_config')
|
|
|
+ return self.send_command('ConfigManager', isc.config.ccsession.COMMAND_GET_CONFIG)
|
|
|
|
|
|
def update_config_data(self, module_name, command_name):
|
|
|
'''Get lastest config data for all modules from configmanager '''
|
|
|
- if module_name == 'ConfigManager' and command_name == 'set_config':
|
|
|
+ if module_name == 'ConfigManager' and command_name == isc.config.ccsession.COMMAND_SET_CONFIG:
|
|
|
self.config_data = self.get_config_data()
|
|
|
|
|
|
def get_data_specification(self):
|
|
|
- return self.send_command('ConfigManager', 'get_module_spec')
|
|
|
+ return self.send_command('ConfigManager', isc.config.ccsession.COMMAND_GET_MODULE_SPEC)
|
|
|
|
|
|
def handle_recv_msg(self):
|
|
|
'''Handle received message, if 'shutdown' is received, return False'''
|
|
|
(message, env) = self.cc.group_recvmsg(True)
|
|
|
- while message:
|
|
|
- if 'commands_update' in message:
|
|
|
- self.command_spec[message['commands_update'][0]] = message['commands_update'][1]
|
|
|
- elif 'specification_update' in message:
|
|
|
- msgvalue = message['specification_update']
|
|
|
- self.config_spec[msgvalue[0]] = msgvalue[1]
|
|
|
- elif 'command' in message and message['command'][0] == 'shutdown':
|
|
|
- return False;
|
|
|
+ command, arg = isc.config.ccsession.parse_command(message)
|
|
|
+ while command:
|
|
|
+ if command == isc.config.ccsession.COMMAND_COMMANDS_UPDATE:
|
|
|
+ self.command_spec[arg[0]] = arg[1]
|
|
|
+ elif command == isc.config.ccsession.COMMAND_SPECIFICATION_UPDATE:
|
|
|
+ self.config_spec[arg[0]] = arg[1]
|
|
|
+ elif command == "shutdown":
|
|
|
+ return False
|
|
|
(message, env) = self.cc.group_recvmsg(True)
|
|
|
+ command, arg = isc.config.ccsession.parse_command(message)
|
|
|
|
|
|
return True
|
|
|
|
|
|
- def send_command(self, module_name, command_name, params = None):
|
|
|
+ def send_command(self, module_name, command_name, params = None):
|
|
|
'''Send the command from bindctl to proper module. '''
|
|
|
- content = [command_name]
|
|
|
- if params:
|
|
|
- content.append(params)
|
|
|
-
|
|
|
reply = {}
|
|
|
print('b10-cmdctl send command \'%s\' to %s' %(command_name, module_name))
|
|
|
try:
|
|
|
- msg = {'command' : content}
|
|
|
+ msg = isc.config.ccsession.create_command(command_name, params)
|
|
|
self.cc.group_sendmsg(msg, module_name)
|
|
|
#TODO, it may be blocked, msqg need to add a new interface waiting in timeout.
|
|
|
answer, env = self.cc.group_recvmsg(False)
|
|
|
- if answer and 'result' in answer.keys() and type(answer['result']) == list:
|
|
|
- if answer['result'][0] != 0:
|
|
|
- # todo: exception
|
|
|
- print("Error: " + str(answer['result'][1]))
|
|
|
- else:
|
|
|
- self.update_config_data(module_name, command_name)
|
|
|
- if (len(answer['result']) > 1):
|
|
|
- reply = answer['result'][1]
|
|
|
- else:
|
|
|
- print("Error: unexpected answer from %s" % module_name)
|
|
|
- print(answer)
|
|
|
+ if answer:
|
|
|
+ try:
|
|
|
+ rcode, arg = isc.config.ccsession.parse_answer(answer)
|
|
|
+ if rcode == 0:
|
|
|
+ self.update_config_data(module_name, command_name)
|
|
|
+ if arg != None:
|
|
|
+ return arg
|
|
|
+ else:
|
|
|
+ # todo: exception
|
|
|
+ print("Error: " + str(answer['result'][1]))
|
|
|
+ return {}
|
|
|
+ except isc.config.ccsession.ModuleCCSessionError as mcse:
|
|
|
+ print("Error in ccsession answer: %s" % str(mcse))
|
|
|
+ print(answer)
|
|
|
except Exception as e:
|
|
|
print(e, ':b10-cmdctl fail send command \'%s\' to %s' % (command_name, module_name))
|
|
|
|