def __init__(self, verbose): super(RainMoveClient, self).__init__() #Load Config self._conf = RainMoveClientConf() self.verbose = verbose self._port = self._conf.getPort() self._serveraddr = self._conf.getServeraddr() self._ca_certs = self._conf.getCaCerts() self._certfile = self._conf.getCertFile() self._keyfile = self._conf.getKeyFile() self._connMoveServer = None self.passwdtype = "ldappassmd5" #Setup log self._log = fgLog.fgLog(self._conf.getLogFile(), self._conf.getLogLevel(), "Rain Move Client", False)
class RainMoveClient(object): def __init__(self, verbose): super(RainMoveClient, self).__init__() #Load Config self._conf = RainMoveClientConf() self.verbose = verbose self._port = self._conf.getPort() self._serveraddr = self._conf.getServeraddr() self._ca_certs = self._conf.getCaCerts() self._certfile = self._conf.getCertFile() self._keyfile = self._conf.getKeyFile() self._connMoveServer = None self.passwdtype = "ldappassmd5" #Setup log self._log = fgLog.fgLog(self._conf.getLogFile(), self._conf.getLogLevel(), "Rain Move Client", False) def connection(self): connected = False s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self._connMoveServer = ssl.wrap_socket(s, ca_certs=self._ca_certs, certfile=self._certfile, keyfile=self._keyfile, cert_reqs=ssl.CERT_REQUIRED, ssl_version=ssl.PROTOCOL_TLSv1) self._log.debug("Connecting server: " + self._serveraddr + ":" + str(self._port)) self._connMoveServer.connect((self._serveraddr, self._port)) connected = True except ssl.SSLError: self._log.error("CANNOT establish SSL connection. EXIT") except socket.error: self._log.error("Error with the socket connection") except: if self.verbose: print "Error CANNOT establish connection with the server" self._log.error("ERROR: exception not controlled" + str(sys.exc_info())) return connected #_connMoveServer.write(options) #to be done in each method def disconnect(self): try: self._connMoveServer.shutdown(socket.SHUT_RDWR) self._connMoveServer.close() except: self._log.debug("In disconnect:" + str(sys.exc_info())) def check_auth(self, userId, checkauthstat): endloop = False passed = False while not endloop: ret = self._connMoveServer.read(1024) if (ret == "OK"): if self.verbose: print "Authentication OK. Your request is being processed" self._log.debug("Authentication OK") endloop = True passed = True elif (ret == "TryAuthAgain"): msg = "ERROR: Permission denied, please try again. User is " + userId self._log.error(msg) if self.verbose: print msg m = hashlib.md5() m.update(getpass()) passwd = m.hexdigest() self._connMoveServer.write(passwd) elif (ret == "NoActive"): checkauthstat.append("ERROR: The status of the user " + userId + " is not active") checkauthstat.append("NoActive") self._log.error("The status of the user " + userId + " is not active") endloop = True passed = False elif (ret == "NoUser"): checkauthstat.append("ERROR: User " + userId + " does not exist") checkauthstat.append("NoUser") self._log.error("User " + userId + " does not exist") endloop = True passed = False else: self._log.error(str(ret)) #if self.verbose: # print ret checkauthstat.append(str(ret)) endloop = True passed = False return passed def cluster(self, user, passwd, subparser_name, operation, arguments, force): status=None start_all = time.time() checkauthstat = [] msg = str(user) + "|" + str(passwd) + "|" + self.passwdtype + "|" + str(subparser_name) + "|" + str(operation) + "|" + str(arguments) + "|" + str(force) self._log.debug("Cluster: " + str(msg)) self._connMoveServer.write(msg) if self.check_auth(user, checkauthstat): status = self._connMoveServer.read(2048) else: self._log.error(str(checkauthstat[0])) if self.verbose: status = str(checkauthstat[0]) end_all = time.time() self._log.info('TIME walltime rain move client (cluster):' + str(end_all - start_all)) return status def node(self, user, passwd, subparser_name, operation, arguments, force): status=None start_all = time.time() checkauthstat = [] msg = str(user) + "|" + str(passwd) + "|" + self.passwdtype + "|" + str(subparser_name) + "|" + str(operation) + "|" + str(arguments) + "|" + str(force) self._log.debug("Node: " + str(msg)) self._connMoveServer.write(msg) if self.check_auth(user, checkauthstat): status = self._connMoveServer.read(2048) else: self._log.error(str(checkauthstat[0])) if self.verbose: status = str(checkauthstat[0]) end_all = time.time() self._log.info('TIME walltime rain move client (node):' + str(end_all - start_all)) return status def service(self, user, passwd, subparser_name, operation, arguments, force): status = None start_all = time.time() checkauthstat = [] msg = str(user) + "|" + str(passwd) + "|" + self.passwdtype + "|" + str(subparser_name) + "|" + str(operation) + "|" + str(arguments) + "|" + str(force) self._log.debug("Service: " + str(msg)) self._connMoveServer.write(msg) if self.check_auth(user, checkauthstat): status = self._connMoveServer.read(2048) else: self._log.error(str(checkauthstat[0])) if self.verbose: status = str(checkauthstat[0]) end_all = time.time() self._log.info('TIME walltime rain move client (service):' + str(end_all - start_all)) return status