def invoke(self, sessionID, service, method, *args): if not self.manager().validate(sessionID, touch=1): raise EInvalidSession('Invalid session') s = self._as_node(service) a = getattr(s, method) ## Check to see if any of the args have been encoded ## If so, decode them here.. cnt = -1 args_new = [] args_new.extend(args) for ar in args_new: cnt = cnt + 1 if type(ar) == types.StringType: if ar.startswith('<encode'): # is encode args_new[cnt] = self._decode(ar) # decode string ## Make the low-level call result = None result = apply(a, args_new) if isinstance(result, types.StringType): encode = 0 if isinstance(result, BinaryString): encode = 1 elif result.find('>>]') > -1: encode = 1 if encode: result = self._encoder_mgr.encode(result, self._encode_type) # all strings are in CDATA sections result = '<![CDATA[' + result + ']]>' return result
def invoke(self, sessionID, service, method, *args): # Raise exception if this is not a valid session if not self.manager().validate(sessionID, touch=1): raise EInvalidSession('Invalid session') s = self._as_node(service) a = getattr(s, method) ## Check to see if any of the args have been UUEncoded ## If so, decode them here.. cnt = -1 args_new = [] args_new.extend(args) for ar in args_new: cnt = cnt + 1 if type(ar) == types.StringType: if ar.startswith('begin '): # is uuencoded infile = StringIO.StringIO(ar) outfile = StringIO.StringIO() uu.decode(infile, outfile) args_new[cnt] = outfile.getvalue() result = apply(a, args_new) if isinstance(result, BinaryString): # This is the legacy ConfigTool specific base64 encoding. return ''.join(("<encode type='base64'>", base64.standard_b64encode(result), "</encode>")) return result
def subscription_create_polled(self, sessionID, node_reference_table=None, timeout=60.0): # Raise exception if this is not a valid session if not self.manager().validate(sessionID, touch=1): raise EInvalidSession('Invalid session') return SUBSCRIPTION_MANAGER.create_polled(node_reference_table, timeout)
def invoke_batch(self, sessionID, *args): if not self.manager().validate(sessionID, touch=1): raise EInvalidSession('Invalid session') results = [] for rna in args: # since we are spliting on ":" I put in a place holder # for the mpx:// before I do a split the put it back after # since mpx:// has a ":" rna = rna.replace("mpx://", '$$PLACE_HOLDER$$') rna_s = rna.split(':') service = rna_s[0].replace('$$PLACE_HOLDER$$', 'mpx://') method = rna_s[1] try: result = self.invoke(sessionID, service, method) results.append(result) except Exception, e: results.append(self._exception_string(e))
def invoke_batch_async(self, sessionID, *qualified_method_list): subscription = None if not self.manager().validate(sessionID, touch=1): if self._subscriptions.has_key(sessionID): try: subscription = self._subscriptions[sessionID] del self._subscriptions[sessionID] del self._qualified_method_list[sessionID] del self._services[sessionID] del self._methods[sessionID] SUBSCRIPTION_MANAGER.destroy(subscription) except: msglog.log( 'RNA_XMLRPC_Handler', msglog.types.WARN, "Error destroying subscription %r on stale session %r." % (subscription, sessionID)) msglog.exception() raise EInvalidSession('Invalid session') if self._subscriptions.has_key(sessionID): subscription = self._subscriptions[sessionID] if (self._qualified_method_list[sessionID] != qualified_method_list): # New batch, destroy the out of date subscription. try: del self._subscriptions[sessionID] del self._qualified_method_list[sessionID] del self._services[sessionID] del self._methods[sessionID] SUBSCRIPTION_MANAGER.destroy(subscription) except: msglog.log( 'RNA_XMLRPC_Handler', msglog.types.WARN, "Error destroying previous subscription %r." % (subscription, )) msglog.exception() subscription = None if subscription is None: # # No subscription matching the batch, create one! # Build a node_reference_table: subscription_map = {} services = [] methods = [] for i in range(0, len(qualified_method_list)): rna = qualified_method_list[i] i_method = rna.rfind(':') if i_method == -1 or (i_method == 3 and rna[:3] == "mpx"): # There is no method specified. rna_node = rna rna_method = '' else: rna_node = rna[:i_method] rna_method = rna[i_method + 1:] services.append(rna_node) methods.append(rna_method) if methods[i] == 'get': subscription_map[services[i]] = services[i] # Create the subscription using the genereated node_reference_table: subscription = SUBSCRIPTION_MANAGER.create_polled( subscription_map, 5 * 60.0) self._subscriptions[sessionID] = subscription self._qualified_method_list[sessionID] = qualified_method_list self._services[sessionID] = services self._methods[sessionID] = methods # # Now that we've added our node's, validate the other sessions. # validate_list = [] validate_list.extend(self._subscriptions.keys()) for test_session in validate_list: if not self.manager().validate(test_session, touch=0): expired = None try: expired = self._subscriptions[test_session] del self._subscriptions[test_session] del self._qualified_method_list[test_session] del self._services[test_session] del self._methods[test_session] SUBSCRIPTION_MANAGER.destroy(expired) except: msglog.log( 'RNA_XMLRPC_Handler', msglog.types.WARN, "Error destroying subscription %r on stale session %r." % (expired, test_session)) msglog.exception() # Get all 'ready' values. services = self._services[sessionID] methods = self._methods[sessionID] polled_values = SUBSCRIPTION_MANAGER.poll_all(subscription) results = [] for i in range(0, len(services)): service = services[i] try: if methods[i] == 'get': result = polled_values[service] if result is None: result = 'error: Waiting for update...' else: result = result['value'] if isinstance(result, Exception): result = self._exception_string(result) else: result = 'error: %r method not supported, only get().' % ( methods[i]) results.append(result) except Exception, e: results.append(self._exception_string(e))
def subscription_poll_all(self, sessionID, sid): # Raise exception if this is not a valid session if not self.manager().validate(sessionID, touch=1): raise EInvalidSession('Invalid session') return SUBSCRIPTION_MANAGER.poll_all(sid)
def subscription_modify(self, sessionID, sid, nid, node_reference): # Raise exception if this is not a valid session if not self.manager().validate(sessionID, touch=1): raise EInvalidSession('Invalid session') return SUBSCRIPTION_MANAGER.modify(sid, nid, node_reference)