def apply(self): try: client = Client(SOCKET) self.info("Connect to %s" % SOCKET) client.connect() self.info("Run command: reload periods") client.execute("reload periods") self.info("Run command: refresh cache") client.execute("refresh cache") except Exception, err: self.writeError(err, "nuauth_command error")
class NuauthCommand(Component): NAME = "nuauth_command" VERSION = "1.0" API_VERSION = 2 ROLES = {'nuauth_command_read': set(( 'getNuauthVersion', 'getUptime', 'getUsers', 'getFirewalls', 'getPacketCount', 'getDebugLevel', 'getDebugAreas', 'getUsersCount' )), 'nuauth_command_write': set(( '@nuauth_command_read', 'disconnect', 'disconnectAll', 'reload', 'refreshCache', 'setDebugLevel', 'setDebugAreas' )), } def init(self, core): self.socket_filename = "/var/run/nuauth/nuauth-command.socket" self.client = None def getClient(self): return self.client def _command(self, command): if not self.client: # Create and connect client self.client = Client(self.socket_filename) try: self.client.connect() except NuauthError, err: self.client = None raise # Execute command and convert answer to string if not self.client: self.client = Client(self.socket_filename) try: self.client.connect() except NuauthError, err: self.client = None raise