How to use the cma.newcma.DroneInfo function in cma

To help you get started, we’ve selected a few cma examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assimilation / assimilation-official / cma / newcma.py View on Github external
self.name = str(name)
        self.parentring = parentring
        self.ourreltype = HbRing.memberprefix + self.name # Our relationship type
        self.ournexttype = HbRing.nextprefix + self.name # Our 'next' relationship type
        self.insertpoint1 = None
        self.insertpoint2 = None

        try:
            ip1node = self.node.get_single_related_node(neo4j.Direction.OUTGOING, self.ourreltype)
            if ip1node is not None:
                self.insertpoint1 = DroneInfo(ip1node)
                if self.insertpoint1 is not None:
                    try:
                      #print 'INSERTPOINT1: ', self.insertpoint1
                      ip2 = self.insertpoint1.node.get_single_related_node(neo4j.Direction.OUTGOING, self.ournexttype)
                      self.insertpoint2 = DroneInfo(ip2)
                    except ValueError:
                        pass
        except ValueError:
            pass
        # Need to figure out what to do about pre-existing members of this ring...
        # For the moment, let's make the entirely inadequate assumption that
        # the data in the database is correct.
        ## FIXME - assumption about database being correct
        HbRing.ringnames[self.name] = self
github assimilation / assimilation-official / cma / newcma.py View on Github external
'Listen for packets.  Get them dispatched.'
      while True:
        (fromaddr, framesetlist) = self.io.recvframesets()
        if fromaddr is None:
            # BROKEN! ought to be able to set blocking mode on the socket...
            #print "Failed to get a packet - sleeping."
            time.sleep(0.5)
        else:
            fromstr = repr(fromaddr)
            if CMAdb.debug: print "Received packet from [%s]" % (fromstr)

            for frameset in framesetlist:
                self.dispatcher.dispatch(fromaddr, frameset)


DroneInfo.add_json_processors(('netconfig', DroneInfo.add_netconfig_addresses),)
DroneInfo.add_json_processors(('tcplisteners', DroneInfo.add_tcplisteners),)
DroneInfo.add_json_processors(('tcpclients', DroneInfo.add_tcplisteners),)
DroneInfo.add_json_processors(('#LinkDiscovery', DroneInfo.add_linkdiscovery),)

if __name__ == '__main__':
    #
    #   "Main" program starts below...
    #   It is a test program intended to run with some real nanoprobes running
    #   somewhere out there...
    #
    OurAddr = None
    DefaultPort = 1984
    OurPort = None

    skipme = False
    for narg in range(1,len(sys.argv)):
github assimilation / assimilation-official / cma / newcma.py View on Github external
while True:
        (fromaddr, framesetlist) = self.io.recvframesets()
        if fromaddr is None:
            # BROKEN! ought to be able to set blocking mode on the socket...
            #print "Failed to get a packet - sleeping."
            time.sleep(0.5)
        else:
            fromstr = repr(fromaddr)
            if CMAdb.debug: print "Received packet from [%s]" % (fromstr)

            for frameset in framesetlist:
                self.dispatcher.dispatch(fromaddr, frameset)


DroneInfo.add_json_processors(('netconfig', DroneInfo.add_netconfig_addresses),)
DroneInfo.add_json_processors(('tcplisteners', DroneInfo.add_tcplisteners),)
DroneInfo.add_json_processors(('tcpclients', DroneInfo.add_tcplisteners),)
DroneInfo.add_json_processors(('#LinkDiscovery', DroneInfo.add_linkdiscovery),)

if __name__ == '__main__':
    #
    #   "Main" program starts below...
    #   It is a test program intended to run with some real nanoprobes running
    #   somewhere out there...
    #
    OurAddr = None
    DefaultPort = 1984
    OurPort = None

    skipme = False
    for narg in range(1,len(sys.argv)):
        if skipme:
github assimilation / assimilation-official / cma / newcma.py View on Github external
def membersfromlist(self):
        firstdrone=self.insertpoint1
        if firstdrone is None:
           return []
        ret = [firstdrone]
        firstdrone = firstdrone.node
        nextdrone = firstdrone
        while True:
            nextdrone = nextdrone.get_single_related_node(neo4j.Direction.OUTGOING, self.ournexttype)
            if nextdrone is None or nextdrone.id == firstdrone.id:  break
            ret.append(DroneInfo.find(nextdrone))
        return ret
github assimilation / assimilation-official / cma / newcma.py View on Github external
def logjson(self, jsontext):
        'Process and save away JSON discovery data'
        jsonobj = pyConfigContext(jsontext)
        if not jsonobj.has_key('discovertype') or not jsonobj.has_key('data'):
            print >>sys.stderr, 'Invalid JSON discovery packet.'
            return
        dtype = jsonobj['discovertype']
        #print "Saved discovery type %s for endpoint %s." % \
        #   (dtype, self.designation)
        self.node['JSON_' + dtype] = jsontext
        if dtype in DroneInfo._JSONprocessors:
            if CMAdb.debug: print >>sys.stderr, ('Processed %s JSON data into graph.' % dtype)
            DroneInfo._JSONprocessors[dtype](self, jsonobj)
        else:
            print >>sys.stderr, ('Stored %s JSON data without processing.' % dtype)
github assimilation / assimilation-official / cma / newcma.py View on Github external
'''
        if ringtype < HbRing.SWITCH or ringtype > HbRing.THEONERING: 
            raise ValueError("Invalid ring type [%s]" % str(ringtype))
        self.node = CMAdb.cdb.new_ring(name, parentring, ringtype=ringtype)
        self.ringtype = ringtype
        self.name = str(name)
        self.parentring = parentring
        self.ourreltype = HbRing.memberprefix + self.name # Our relationship type
        self.ournexttype = HbRing.nextprefix + self.name # Our 'next' relationship type
        self.insertpoint1 = None
        self.insertpoint2 = None

        try:
            ip1node = self.node.get_single_related_node(neo4j.Direction.OUTGOING, self.ourreltype)
            if ip1node is not None:
                self.insertpoint1 = DroneInfo(ip1node)
                if self.insertpoint1 is not None:
                    try:
                      #print 'INSERTPOINT1: ', self.insertpoint1
                      ip2 = self.insertpoint1.node.get_single_related_node(neo4j.Direction.OUTGOING, self.ournexttype)
                      self.insertpoint2 = DroneInfo(ip2)
                    except ValueError:
                        pass
        except ValueError:
            pass
        # Need to figure out what to do about pre-existing members of this ring...
        # For the moment, let's make the entirely inadequate assumption that
        # the data in the database is correct.
        ## FIXME - assumption about database being correct
        HbRing.ringnames[self.name] = self
github assimilation / assimilation-official / cma / newcma.py View on Github external
ringrel.delete()
        ringrel = None
    # Clean out the next link relationships to our dearly departed drone
        relationships = drone.node.get_relationships('all', self.ournexttype)
        # Should have exactly two link relationships (one incoming and one outgoing)
        assert len(relationships) == 2
        for rel in relationships:
            rel.delete()
            rel = None
        relationships = None
        rel = None

        if prevnode.id == nextnode.id:          # Previous length:  2
            node = prevnode             # Result length:    1
            if node is None: node = nextnode
            partner = DroneInfo(node)
            drone.stop_heartbeat(self, partner)
            partner.stop_heartbeat(self, drone)
            #prevnode.create_relationship_to(nextnode, self.ournexttype)
            self.insertpoint2 = None
            self.insertpoint1 = partner
            return

        # Previous length had to be >= 3        # Previous length:  >=3
                            # Result length:    >=2
        prevdrone = DroneInfo(prevnode['name'])
        nextdrone = DroneInfo(nextnode['name'])
        nextnext = nextnode.get_single_related_node(neo4j.Direction.OUTGOING, self.ournexttype)
        prevdrone.stop_heartbeat(self, drone)
        nextdrone.stop_heartbeat(self, drone)
        if nextnext.id != prevnode.id:          # Previous length:  >= 4
            nextdrone.start_heartbeat(self, prevdrone)  # Result length:    >= 3
github assimilation / assimilation-official / cma / newcma.py View on Github external
    @staticmethod
    def add(designation, reason, status='up'):
        'Add a drone to our set unless it is already there.'
        ret = None
        if designation in DroneInfo._droneweakrefs:
            ret = DroneInfo._droneweakrefs[designation]()
        if ret is None:
            ret = DroneInfo.find(designation)
        if ret is None:
            ret = DroneInfo(designation)
        ret.node['reason'] = reason
        ret.node['status'] = status
        return ret
github assimilation / assimilation-official / cma / newcma.py View on Github external
# Shouldn't have duplicates, but they happen...
                # FIXME: Think about how to manage duplicate IP addresses...
                # Do we really want to be looking up just by IP addresses here?
                node = ip.get_single_related_node(neo4j.Direction.OUTGOING, CMAdb.REL_iphost)
                return DroneInfo.find(node)
            print 'UHOH... COULD NOT FIND IP ADDRESS... %s' % repr(designation)
        if isinstance(designation, neo4j.Node):
            nodedesig = designation['name']
            if nodedesig in DroneInfo._droneweakrefs:
                ret = DroneInfo._droneweakrefs[nodedesig]()
                if ret is not None:  return ret
            return DroneInfo(designation)
           
        print "DESIGNATION repr(%s) = %s", (designation, repr(designation))
        if repr(designation) in DroneInfo._droneweakrefs:
            ret = DroneInfo._droneweakrefs[designation]()
        return None