def __init__(self, designation, port=None, startaddr=None
    ,       primary_ip_addr=None, domain=CMAconsts.globaldomain
    ,       status= '(unknown)', reason='(initialization)', roles=None, key_id=''):
        '''Initialization function for the Drone class.
        We mainly initialize a few attributes from parameters as noted above...

        The first time around we also initialize a couple of class-wide query
        strings for a few queries we know we'll need later.

        We also behave as though we're a dict from the perspective of JSON attributes.
        These discovery strings are converted into pyConfigContext objects and are
        then searchable like dicts themselves - however updating these dicts has
        no direct impact on the underlying JSON strings stored in the database.

        The reason for treating these as a dict is so we can easily change
        the implementation to put JSON strings in separate nodes, or perhaps
        eventually in a separate data store.

        This is necessary because the performance of putting lots of really large
        strings in Neo4j is absolutely horrible. Putting large strings in is dumb
        and what Neo4j does with them is even dumber...
        The result is at least DUMB^2 -not 2*DUMB ;-)
        '''
        SystemNode.__init__(self, domain=domain, designation=designation)
        if roles is None:
            roles = ['host', 'drone']
        self.addrole(roles)
        self._io = CMAdb.io
        self.lastjoin = 'None'
        self._active_nic_count = None
        self.status = status
        self.reason = reason
        self.key_id = key_id
        self.startaddr = str(startaddr)
        self.primary_ip_addr = str(primary_ip_addr)
        self.time_status_ms = int(round(time.time() * 1000))
        self.time_status_iso8601 = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
        if port is not None:
            self.port = int(port)
        else:
            self.port = None

        if Drone.IPownerquery_1 is None:
            Drone.IPownerquery_1 = (Drone.IPownerquery_1_txt
                                    % (CMAconsts.REL_ipowner, CMAconsts.REL_nicowner))
            Drone.OwnedIPsQuery_subtxt = (Drone.OwnedIPsQuery_txt    \
                                          % (CMAconsts.REL_nicowner, CMAconsts.REL_ipowner))
            Drone.OwnedIPsQuery =  Drone.OwnedIPsQuery_subtxt
        self.set_crypto_identity()
        if Store.is_abstract(self) and not CMAdb.store.readonly:
            #print 'Creating BP rules for', self.designation
            from bestpractices import BestPractices
            bprules = CMAdb.io.config['bprulesbydomain']
            rulesetname = bprules[domain] if domain in bprules else bprules[CMAconsts.globaldomain]
            for rule in BestPractices.gen_bp_rules_by_ruleset(CMAdb.store, rulesetname):
                #print >> sys.stderr, 'ADDING RELATED RULE SET for', \
                    #self.designation, rule.bp_class, rule
                CMAdb.store.relate(self, CMAconsts.REL_bprulefor, rule,
                                   properties={'bp_class': rule.bp_class})
 def register_sensitivity(bpcls, pkttype):
     "Register that class 'bpcls' wants to see packet of type 'pkttype'"
     #print >> sys.stderr, '%s is looking for packet of type %s' % (bpcls, pkttype)
     if pkttype not in BestPractices.wantedpackets:
         BestPractices.wantedpackets.append(pkttype)
         SystemNode.add_json_processor(BestPractices)
     if pkttype not in BestPractices.eval_classes:
         BestPractices.eval_classes[pkttype] = []
     if bpcls not in BestPractices.eval_classes[pkttype]:
         BestPractices.eval_classes[pkttype].append(bpcls)
 def register_sensitivity(bpcls, pkttype):
     "Register that class 'bpcls' wants to see packet of type 'pkttype'"
     #print >> sys.stderr, '%s is looking for packet of type %s' % (bpcls, pkttype)
     if pkttype not in BestPractices.wantedpackets:
         BestPractices.wantedpackets.append(pkttype)
         SystemNode.add_json_processor(BestPractices)
     if pkttype not in BestPractices.eval_classes:
         BestPractices.eval_classes[pkttype] = []
     if bpcls not in BestPractices.eval_classes[pkttype]:
         BestPractices.eval_classes[pkttype].append(bpcls)
示例#4
0
 def maintest():
     'test main program'
     from cmainit import CMAinit
     from droneinfo import Drone
     from systemnode import SystemNode
     print >> sys.stderr, 'Starting'
     CMAinit(None, cleanoutdb=True, debug=True)
     if CMAdb.store.transaction_pending:
         print 'Transaction pending in:', CMAdb.store
         print 'Results:', CMAdb.store.commit()
     print ProcessNode.__meta_labels__()
     print SystemNode.__meta_labels__()
     print Drone.__meta_labels__()
     print 'keys:', Drone.__meta_keyattrs__()
     print >> sys.stderr, 'Init done'
     return 0
 def maintest():
     'test main program'
     from cmainit import CMAinit
     from droneinfo import Drone
     from systemnode import SystemNode
     print >> sys.stderr, 'Starting'
     CMAinit(None, cleanoutdb=True, debug=True)
     if CMAdb.store.transaction_pending:
         print 'Transaction pending in:', CMAdb.store
         print 'Results:', CMAdb.store.commit()
     print ProcessNode.__meta_labels__()
     print SystemNode.__meta_labels__()
     print Drone.__meta_labels__()
     print 'keys:', Drone.__meta_keyattrs__()
     print >> sys.stderr, 'Init done'
     return 0