def _connect(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((self.account.host, self.account.port)) except socket.error: raise Exception( "Could not connect to specified host and port: %s:%s" % (self.account.host, self.account.port)) self.socket = s main_message = StartupPack( (self.account.proxy_user, self.account.proxy_zone), (self.account.client_user, self.account.client_zone)) msg = iRODSMessage(type='RODS_CONNECT', msg=main_message) self.send(msg) version_msg = self.recv()
def setInfo(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((self.host, self.port)) except socket.error: raise NetworkException( "Could not connect to specified host and port!") mainMessage = StartupPack((self.dummycred, self.dummycred), (self.dummycred, self.dummycred)) msg = iRODSMessage(msg_type='RODS_CONNECT', msg=mainMessage) string = msg.pack() try: s.sendall(string) except: raise NetworkException("Unable to send message") try: msg = iRODSMessage.recv(s) except socket.error: exit(1) if msg.int_info < 0: raise get_exception_by_code(msg.int_info) msg = iRODSMessage(msg_type='RODS_API_REQ', msg=None, int_info=api_number['GET_MISC_SVR_INFO_AN']) string = msg.pack() try: s.sendall(string) except: raise NetworkException("Unable to send message") try: miscsvrinfo = iRODSMessage.recv(s) except socket.error: exit(1) if msg.int_info < 0: raise get_exception_by_code(msg.int_info) root = ET.fromstring(miscsvrinfo.msg) self.setProps("RCAT_ENABLED" if int(root[0].text) else "RCAT_DISABLED", root[2].text, root[3].text, root[4].text, int(root[1].text)) s.close() return
def _connect(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((self.account.host, self.account.port)) except socket.error: raise NetworkException( "Could not connect to specified host and port: {host}:{port}". format(host=self.account.host, port=self.account.port)) self.socket = s main_message = StartupPack( (self.account.proxy_user, self.account.proxy_zone), (self.account.client_user, self.account.client_zone)) msg = iRODSMessage(type='RODS_CONNECT', msg=main_message) self.send(msg) # server responds with version version_msg = self.recv() return version_msg.get_main_message(VersionResponse)
def test_startup_pack(self): sup = StartupPack(('rods', 'tempZone'), ('rods', 'tempZone')) sup.irodsProt = 2 sup.reconnFlag = 3 sup.proxyUser = "******" sup.proxyRcatZone = "tempZone" sup.clientUser = "******" sup.clientRcatZone = "yoyoyo" sup.relVersion = "irods3.2" sup.apiVersion = "d" sup.option = "hellO" xml_str = sup.pack() expected = "<StartupPack_PI>\ <irodsProt>2</irodsProt>\ <reconnFlag>3</reconnFlag>\ <connectCnt>0</connectCnt>\ <proxyUser>rods</proxyUser>\ <proxyRcatZone>tempZone</proxyRcatZone>\ <clientUser>rods</clientUser>\ <clientRcatZone>yoyoyo</clientRcatZone>\ <relVersion>irods3.2</relVersion>\ <apiVersion>d</apiVersion>\ <option>hellO</option>\ </StartupPack_PI>" self.assertEqual(xml_str, expected) sup2 = StartupPack(('rods', 'tempZone'), ('rods', 'tempZone')) sup2.unpack(ET().fromstring(expected)) self.assertEqual(sup2.irodsProt, 2) self.assertEqual(sup2.reconnFlag, 3) self.assertEqual(sup2.proxyUser, "rods") self.assertEqual(sup2.proxyRcatZone, "tempZone") self.assertEqual(sup2.clientUser, "rods") self.assertEqual(sup2.clientRcatZone, "yoyoyo") self.assertEqual(sup2.relVersion, "irods3.2") self.assertEqual(sup2.apiVersion, "d") self.assertEqual(sup2.option, "hellO")
def _connect(self): address = (self.account.host, self.account.port) timeout = self.pool.connection_timeout try: s = socket.create_connection(address, timeout) self._disconnected = False except socket.error: raise NetworkException( "Could not connect to specified host and port: " + "{}:{}".format(*address)) self.socket = s main_message = StartupPack( (self.account.proxy_user, self.account.proxy_zone), (self.account.client_user, self.account.client_zone), self.pool.application_name) # No client-server negotiation if not self.requires_cs_negotiation(): # Send startup pack without negotiation request msg = iRODSMessage(msg_type='RODS_CONNECT', msg=main_message) self.send(msg) # Server responds with version version_msg = self.recv() # Done return version_msg.get_main_message(VersionResponse) # Get client negotiation policy client_policy = getattr(self.account, 'client_server_policy', REQUIRE_TCP) # Sanity check validate_policy(client_policy) # Send startup pack with negotiation request main_message.option = '{};{}'.format(main_message.option, REQUEST_NEGOTIATION) msg = iRODSMessage(msg_type='RODS_CONNECT', msg=main_message) self.send(msg) # Server responds with its own negotiation policy cs_neg_msg = self.recv() response = cs_neg_msg.get_main_message(ClientServerNegotiation) server_policy = response.result # Perform the negotiation neg_result, status = perform_negotiation(client_policy=client_policy, server_policy=server_policy) # Send negotiation result to server client_neg_response = ClientServerNegotiation(status=status, result='{}={};'.format( CS_NEG_RESULT_KW, neg_result)) msg = iRODSMessage(msg_type='RODS_CS_NEG_T', msg=client_neg_response) self.send(msg) # If negotiation failed we're done if neg_result == FAILURE: self.disconnect() raise NetworkException( "Client-Server negotiation failure: {},{}".format( client_policy, server_policy)) # Server responds with version version_msg = self.recv() if neg_result == USE_SSL: self.ssl_startup() return version_msg.get_main_message(VersionResponse)
def _connect(self): address = (self.account.host, self.account.port) timeout = self.pool.connection_timeout try: s = socket.create_connection(address, timeout) except socket.error: raise NetworkException( "Could not connect to specified host and port: " + "{}:{}".format(*address)) self.socket = s main_message = StartupPack( (self.account.proxy_user, self.account.proxy_zone), (self.account.client_user, self.account.client_zone) ) # No client-server negotiation if not self.requires_cs_negotiation(): # Send startup pack without negotiation request msg = iRODSMessage(msg_type='RODS_CONNECT', msg=main_message) self.send(msg) # Server responds with version version_msg = self.recv() # Done return version_msg.get_main_message(VersionResponse) # Get client negotiation policy client_policy = getattr(self.account, 'client_server_policy', REQUIRE_TCP) # Sanity check validate_policy(client_policy) # Send startup pack with negotiation request main_message.option = '{};{}'.format(main_message.option, REQUEST_NEGOTIATION) msg = iRODSMessage(msg_type='RODS_CONNECT', msg=main_message) self.send(msg) # Server responds with its own negotiation policy cs_neg_msg = self.recv() response = cs_neg_msg.get_main_message(ClientServerNegotiation) server_policy = response.result # Perform the negotiation neg_result, status = perform_negotiation(client_policy=client_policy, server_policy=server_policy) # Send negotiation result to server client_neg_response = ClientServerNegotiation( status=status, result='{}={};'.format(CS_NEG_RESULT_KW, neg_result) ) msg = iRODSMessage(msg_type='RODS_CS_NEG_T', msg=client_neg_response) self.send(msg) # If negotiation failed we're done if neg_result == FAILURE: self.disconnect() raise NetworkException("Client-Server negotiation failure: {},{}".format(client_policy, server_policy)) # Server responds with version version_msg = self.recv() if neg_result == USE_SSL: self.ssl_startup() return version_msg.get_main_message(VersionResponse)
def test_startup_pack(self): sup = StartupPack(('rods', 'tempZone'), ('rods', 'tempZone')) sup.irodsProt = 2 sup.reconnFlag = 3 sup.proxyUser = "******" sup.proxyRcatZone = "tempZone" sup.clientUser = "******" sup.clientRcatZone = "yoyoyo" sup.relVersion = "irods3.2" sup.apiVersion = "d" sup.option = "hellO" xml_str = sup.pack() expected = "<StartupPack_PI>\ <irodsProt>2</irodsProt>\ <reconnFlag>3</reconnFlag>\ <connectCnt>0</connectCnt>\ <proxyUser>rods</proxyUser>\ <proxyRcatZone>tempZone</proxyRcatZone>\ <clientUser>rods</clientUser>\ <clientRcatZone>yoyoyo</clientRcatZone>\ <relVersion>irods3.2</relVersion>\ <apiVersion>d</apiVersion>\ <option>hellO</option>\ </StartupPack_PI>" self.assertEqual(xml_str, expected) sup2 = StartupPack(('rods', 'tempZone'), ('rods', 'tempZone')) sup2.unpack(ET.fromstring(expected)) self.assertEqual(sup2.irodsProt, 2) self.assertEqual(sup2.reconnFlag, 3) self.assertEqual(sup2.proxyUser, "rods") self.assertEqual(sup2.proxyRcatZone, "tempZone") self.assertEqual(sup2.clientUser, "rods") self.assertEqual(sup2.clientRcatZone, "yoyoyo") self.assertEqual(sup2.relVersion, "irods3.2") self.assertEqual(sup2.apiVersion, "d") self.assertEqual(sup2.option, "hellO")