def _canDistributeTo(self, connection, sourceNodeInfo): if not connection.active: return {self.__OK: False, "connection_id": connection.connection_id, self.__ERROR: "Inactive connection"} result = {self.__OK: True, "connection_id": connection.connection_id} sourceNodeInfo = h.dictToObject(sourceNodeInfo) try: destinationNodeInfo = h.dictToObject(self._getDistinationInfo(connection)[self.__TARGET_NODE_INFO]) result["destinationNodeInfo"] = destinationNodeInfo # Don't bother going through all the filter out rules if the source and # destionation nodes are on the same community and network. if ( (sourceNodeInfo.community_id == destinationNodeInfo.community_id) and (sourceNodeInfo.network_id == destinationNodeInfo.network_id) and not (sourceNodeInfo.gateway_node and destinationNodeInfo.gateway_node) ): pass elif sourceNodeInfo.node_id == destinationNodeInfo.node_id: result[self.__ERROR] = "Source and destination node must be different node." elif (sourceNodeInfo.gateway_node or destinationNodeInfo.gateway_node) != connection.gateway_connection: result[self.__ERROR] = " 'gateway_connection' mismatch between nodes and connection data" elif (sourceNodeInfo.community_id != destinationNodeInfo.community_id) and ( (not sourceNodeInfo.social_community) or (not destinationNodeInfo.social_community) ): result[self.__ERROR] = "cannot distribute across non social communities" elif (sourceNodeInfo.network_id != destinationNodeInfo.network_id) and ( (not sourceNodeInfo.gateway_node) or (not destinationNodeInfo.gateway_node) ): result[self.__ERROR] = "cannot distribute across networks (or communities) unless gateway" elif (sourceNodeInfo.gateway_node and destinationNodeInfo.gateway_node) and ( sourceNodeInfo.network_id == destinationNodeInfo.network_id ): result[self.__ERROR] = "gateways must only distribute across different networks" elif sourceNodeInfo.gateway_node and not destinationNodeInfo.gateway_node: result[self.__ERROR] = "gateways can only distribute to gateways" except urllib2.URLError as ex: log.exception(ex) result[self.__ERROR] = "Cannot reach destination node. " + str(ex.reason) except Exception as ex: log.exception(ex) result[self.__ERROR] = "Internal error. Cannot process destination node info" if result.has_key(self.__ERROR): result[self.__OK] = False return result
def _canDistributeTo(self, connection, sourceNodeInfo): if not connection.active: return {self.__OK: False, 'connection_id': connection.connection_id, self.__ERROR: 'Inactive connection'} result={self.__OK:True, 'connection_id': connection.connection_id } sourceNodeInfo = h.dictToObject(sourceNodeInfo) try: destinationNodeInfo = h.dictToObject(self._getDistinationInfo(connection)[self.__TARGET_NODE_INFO]) result['destinationNodeInfo'] = destinationNodeInfo # Don't bother going through all the filter out rules if the source and # destionation nodes are on the same community and network. if((sourceNodeInfo.community_id == destinationNodeInfo.community_id) and (sourceNodeInfo.network_id == destinationNodeInfo.network_id) and not (sourceNodeInfo.gateway_node and destinationNodeInfo.gateway_node)): pass elif sourceNodeInfo.node_id == destinationNodeInfo.node_id: result[self.__ERROR] = "Source and destination node must be different node." elif ((sourceNodeInfo.gateway_node or destinationNodeInfo.gateway_node) != connection.gateway_connection): result[self.__ERROR] = " 'gateway_connection' mismatch between nodes and connection data" elif ((sourceNodeInfo.community_id != destinationNodeInfo.community_id) and ((not sourceNodeInfo.social_community) or (not destinationNodeInfo.social_community))): result[self.__ERROR] = 'cannot distribute across non social communities' elif ((sourceNodeInfo.network_id != destinationNodeInfo.network_id) and ((not sourceNodeInfo.gateway_node)or(not destinationNodeInfo.gateway_node))): result[self.__ERROR] = 'cannot distribute across networks (or communities) unless gateway' elif ((sourceNodeInfo.gateway_node and destinationNodeInfo.gateway_node) and (sourceNodeInfo.network_id == destinationNodeInfo.network_id)): result[self.__ERROR] = 'gateways must only distribute across different networks' elif (sourceNodeInfo.gateway_node and not destinationNodeInfo.gateway_node): result[self.__ERROR] = 'gateways can only distribute to gateways' except urllib2.URLError as ex: log.exception(ex) result[self.__ERROR] = "Cannot reach destination node. "+str(ex.reason) except Exception as ex: log.exception(ex) result[self.__ERROR] = "Internal error. Cannot process destination node info" if result.has_key(self.__ERROR): result[self.__OK] = False return result
def __init__(self, data): self._communityDescription = None self._networkDescription = None self._nodeStatus = None if isinstance(data, dict): config = h.dictToObject(data) # Check first if node description is set. if not look for in the DB if not in the db # create it from the config data. self._communityDescription = self._initModel( CommunityModel, config.community_description.community_id, config.community_description) self._networkDescription = self._initModel( NetworkModel, config.network_description.network_id, config.network_description) self._nodeDescription = self._initModel( NodeModel, config.node_description.node_id, config.node_description) self._networkPolicyDescription = self._initModel( NetworkPolicyModel, config.network_policy_description.policy_id, config.network_policy_description) self._initServices(config.node_services) self._initFilter(config) self._initConnections(config) self._setNodeStatus() self._initConfig(config)
def __init__(self, data): self._communityDescription = None self._networkDescription = None self._nodeStatus = None if isinstance(data, dict): config = h.dictToObject(data) # Check first if node description is set. if not look for in the DB if not in the db # create it from the config data. self._communityDescription = self._initModel(CommunityModel, config.community_description.community_id, config.community_description) self._networkDescription = self._initModel(NetworkModel, config.network_description.network_id, config.network_description) self._nodeDescription = self._initModel(NodeModel, config.node_description.node_id, config.node_description) self._networkPolicyDescription = self._initModel(NetworkPolicyModel, config.network_policy_description.policy_id, config.network_policy_description) self._initServices(config.node_services) self._initFilter(config) self._initConnections(config) self._setNodeStatus() self._initConfig(config)
def getDistributeCredentialFor(self, targetUrl): #Get all the passwords for distribute if _ACCESS_CREDENTIALS_ID not in NodeModel._defaultDB: return None #check if we have any credential to access the node url. passwords = h.dictToObject(NodeModel._defaultDB[_ACCESS_CREDENTIALS_ID]) credential = passwords.passwords.get(targetUrl) return credential
def _canDistributeTo(self, connection, sourceNodeInfo): if not connection.active: return {self.__OK: False, 'connection_id': connection.connection_id, self.__ERROR: 'Inactive connection'} result={self.__OK:True, 'connection_id': connection.connection_id } sourceNodeInfo = h.dictToObject(sourceNodeInfo) try: destinationNodeInfo = h.dictToObject(self._getDistinationInfo(connection)[self.__TARGET_NODE_INFO]) result['destinationNodeInfo'] = destinationNodeInfo if ((sourceNodeInfo.gateway_node or destinationNodeInfo.gateway_node) != connection.gateway_connection): result[self.__ERROR] = " 'gateway_connection' mismatch between nodes and connection data" elif ((sourceNodeInfo.community_id != destinationNodeInfo.community_id) and ((not sourceNodeInfo.social_community) or (not destinationNodeInfo.social_community))): result[self.__ERROR] = 'cannot distribute across non social communities' elif ((sourceNodeInfo.network_id != destinationNodeInfo.network_id) and ((not sourceNodeInfo.gateway_node)or(not destinationNodeInfo.gateway_node))): result[self.__ERROR] = 'cannot distribute across networks (or communities) unless gateway' elif ((sourceNodeInfo.gateway_node and destinationNodeInfo.gateway_node) and (sourceNodeInfo.network_id == destinationNodeInfo.network_id)): result[self.__ERROR] = 'gateway must only distribute across different networks' elif (sourceNodeInfo.gateway_node and not destinationNodeInfo.gateway_node): result[self.__ERROR] = 'gateways can only distribute to gateways' except urllib2.URLError as ex: log.exception(ex) result[self.__ERROR] = "Cannot reach destination node. "+str(ex.reason) except Exception as ex: log.exception(ex) result[self.__ERROR] = "Internal error. Cannot process destination node info" if result.has_key(self.__ERROR): result[self.__OK] = False return result
def __init__(self, data): self._communityDescription = None self._networkDescription = None self._nodeStatus = None if isinstance(data, dict): config = h.dictToObject(data) # Check first if node description is set. if not look for in the DB if not in the db # create it from the config data. self._communityDescription = self._initModel(CommunityModel, config.community_description.community_id, config.community_description) self._networkDescription = self._initModel(NetworkModel, config.network_description.network_id, config.network_description) self._nodeDescription = self._initModel(NodeModel, config.node_description.node_id, config.node_description) self._networkPolicyDescription = self._initModel(NetworkPolicyModel, config.network_policy_description.policy_id, config.network_policy_description) try: self.incoming_url = appConfig['lr.distribute_incoming_url'] except: self.incoming_url = 'http://localhost/incoming' self._initServices(config.node_services) self._initFilter(config) self._initConnections(config) self._setNodeStatus() self._initConfig(config) self._initBuildVersion()