def post(self, request, command): """ execute a command on the service """ e_msg = ('Failed to %s SNMP service due to system error.' % command) with self._handle_exception(request, e_msg): if (command == 'config'): service = Service.objects.get(name=self.service_name) config = request.data.get('config', {}) if (type(config) != dict): e_msg = ('config dictionary is required input') handle_exception(Exception(e_msg), request) for option in ('syslocation', 'syscontact', 'rocommunity',): if (option not in config): e_msg = ('%s is missing in config' % option) handle_exception(Exception(e_msg), request) if (config[option] is None or config[option] == ''): e_msg = ('%s cannot be empty' % option) handle_exception(Exception(e_msg), request) if ('aux' not in config): e_msg = ('aux is missing in config: %s' % config) handle_exception(Exception(e_msg), request) if (type(config['aux']) != list): e_msg = ('aux must be a list in config: %s' % config) handle_exception(Exception(e_msg), request) configure_snmp(config) self._save_config(service, config) else: self._switch_snmp(command) return Response()
def post(self, request, command): """ execute a command on the service """ e_msg = "Failed to %s SNMP service due to system error." % command with self._handle_exception(request, e_msg): if command == "config": service = Service.objects.get(name=self.service_name) config = request.data.get("config", {}) if type(config) != dict: e_msg = "config dictionary is required input" handle_exception(Exception(e_msg), request) for option in ( "syslocation", "syscontact", "rocommunity", ): if option not in config: e_msg = "%s is missing in config" % option handle_exception(Exception(e_msg), request) if config[option] is None or config[option] == "": e_msg = "%s cannot be empty" % option handle_exception(Exception(e_msg), request) if "aux" not in config: e_msg = "aux is missing in config: %s" % config handle_exception(Exception(e_msg), request) if type(config["aux"]) != list: e_msg = "aux must be a list in config: %s" % config handle_exception(Exception(e_msg), request) configure_snmp(config) self._save_config(service, config) else: self._switch_snmp(command) return Response()