本文整理汇总了Python中store.Store.is_abstract方法的典型用法代码示例。如果您正苦于以下问题:Python Store.is_abstract方法的具体用法?Python Store.is_abstract怎么用?Python Store.is_abstract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类store.Store
的用法示例。
在下文中一共展示了Store.is_abstract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_mac_ip
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def add_mac_ip(self, drone, macaddr, IPlist):
'''We process all the IP addresses that go with a given MAC address (NICNode)
The parameters are expected to be canonical address strings like str(pyNetAddr(...)).
'''
nicnode = self.store.load_or_create(NICNode, domain=drone.domain, macaddr=macaddr)
if not Store.is_abstract(nicnode):
# This NIC already existed - let's see what IPs it already owned
currips = {}
oldiplist = self.store.load_related(nicnode, CMAconsts.REL_ipowner, IPaddrNode)
for ipnode in oldiplist:
currips[ipnode.ipaddr] = ipnode
#print >> sys.stderr, ('IP %s already related to NIC %s'
#% (str(ipnode.ipaddr), str(nicnode.macaddr)))
# See what IPs still need to be added
ips_to_add = []
for ip in IPlist:
if ip not in currips:
ips_to_add.append(ip)
# Replace the original list of IPs with those not already there...
IPlist = ips_to_add
# Now we have a NIC and IPs which aren't already related to it
for ip in IPlist:
ipnode = self.store.load_or_create(IPaddrNode, domain=drone.domain
, ipaddr=ip)
#print >> sys.stderr, ('CREATING IP %s for NIC %s'
#% (str(ipnode.ipaddr), str(nicnode.macaddr)))
if not Store.is_abstract(ipnode):
# Then this IP address already existed,
# but it wasn't related to our NIC...
# Make sure it isn't related to a different NIC
for oldnicnode in self.store.load_in_related(ipnode, CMAconsts.REL_ipowner
, GraphNode.factory):
self.store.separate(oldnicnode, CMAconsts.REL_ipowner, ipnode)
self.store.relate(nicnode, CMAconsts.REL_ipowner, ipnode)
示例2: add_mac_ip
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def add_mac_ip(self, drone, macaddr, IPlist):
'''We process all the IP addresses that go with a given MAC address (NICNode)
The parameters are expected to be canonical address strings like str(pyNetAddr(...)).
'''
nicnode = self.store.load_or_create(NICNode, domain=drone.domain, macaddr=macaddr)
macprefix = str(nicnode.macaddr)[0:8]
try:
org = str(netaddr.EUI(nicnode.macaddr).oui.registration().org)
except netaddr.NotRegisteredError:
local_OUI_map = self.config['OUI']
if macprefix in local_OUI_map:
org = local_OUI_map[macprefix]
else:
org = macprefix
if not Store.is_abstract(nicnode):
# This NIC already existed - let's see what IPs it already owned
currips = {}
oldiplist = self.store.load_related(nicnode, CMAconsts.REL_ipowner, IPaddrNode)
for ipnode in oldiplist:
currips[ipnode.ipaddr] = ipnode
#print >> sys.stderr, ('IP %s already related to NIC %s'
#% (str(ipnode.ipaddr), str(nicnode.macaddr)))
# See what IPs still need to be added
ips_to_add = []
for ip in IPlist:
if ip not in currips:
ips_to_add.append(ip)
# Replace the original list of IPs with those not already there...
IPlist = ips_to_add
# Now we have a NIC and IPs which aren't already related to it
for ip in IPlist:
ipnode = self.store.load_or_create(IPaddrNode, domain=drone.domain
, ipaddr=ip)
#print >> sys.stderr, ('CREATING IP %s for NIC %s'
#% (str(ipnode.ipaddr), str(nicnode.macaddr)))
if not Store.is_abstract(ipnode):
# Then this IP address already existed,
# but it wasn't related to our NIC...
# Make sure it isn't related to a different NIC
for oldnicnode in self.store.load_in_related(ipnode, CMAconsts.REL_ipowner
, GraphNode.factory):
self.store.separate(oldnicnode, CMAconsts.REL_ipowner, ipnode)
print >> sys.stderr, ('RELATING (%s)-[:ipowner]->(%s) [%s]'
% (str(nicnode.macaddr), str(ipnode.ipaddr), org))
self.store.relate(nicnode, CMAconsts.REL_ipowner, ipnode)
if org != macprefix and not hasattr(nicnode, 'OUI'):
nicnode.OUI = org
示例3: initclasstypeobj
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def initclasstypeobj(store, nodetype):
'''Initialize GraphNode.classtypeobjs for our "nodetype"
This involves
- Ensuring that there's an index for this class, and the NODE_nodetype class
- Caching the class that goes with this nodetype
- setting up all of our IS_A objects, including the root object if necessary,
- updating the store's uniqueindexmap[nodetype]
- updating the store's classkeymap[nodetype]
- updating GraphNode.classtypeobjs[nodetype]
This should eliminate the need to do any of these things for any class.
'''
if nodetype != CMAconsts.NODE_nodetype and CMAconsts.NODE_nodetype not in store.classkeymap:
# Have to make sure our root type node exists and is set up properly
GraphNode.initclasstypeobj(store, CMAconsts.NODE_nodetype)
ourclass = GraphNode.classmap[nodetype]
rootclass = GraphNode.classmap[CMAconsts.NODE_nodetype]
if nodetype not in store.classkeymap:
store.uniqueindexmap[nodetype] = True
keys = ourclass.__meta_keyattrs__()
ckm_entry = {'kattr': keys[0], 'index': nodetype}
if len(keys) > 1:
ckm_entry['vattr'] = keys[1]
else:
ckm_entry['value'] = 'None'
store.classkeymap[nodetype] = ckm_entry
store.db.get_or_create_index(neo4j.Node, nodetype)
ourtypeobj = store.load_or_create(rootclass, name=nodetype)
assert ourtypeobj.name == nodetype
if Store.is_abstract(ourtypeobj) and nodetype != CMAconsts.NODE_nodetype:
roottype = store.load_or_create(rootclass, name=CMAconsts.NODE_nodetype)
store.relate(ourtypeobj, CMAconsts.REL_isa, roottype)
GraphNode.classtypeobjs[nodetype] = ourtypeobj
示例4: members_ring_order
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def members_ring_order(self):
'Return all the Drones that are members of this ring - in ring order'
## FIXME - There's a cypher query that will return these all in one go
# START Drone=node:Drone(Drone="drone000001")
# MATCH Drone-[:RingNext_The_One_Ring*]->NextDrone
# RETURN NextDrone.designation, NextDrone
if self._insertpoint1 is None:
#print >> sys.stderr, 'NO INSERTPOINT1'
return
if Store.is_abstract(self._insertpoint1):
#print >> sys.stderr, ('YIELDING INSERTPOINT1:', self._insertpoint1
#, type(self._insertpoint1))
yield self._insertpoint1
return
startid = Store.id(self._insertpoint1)
# We can't pre-compile this, but we hopefully we won't use it much...
q = '''START Drone=node(%s)
MATCH p=Drone-[:%s*0..]->NextDrone
WHERE length(p) = 0 or Drone <> NextDrone
RETURN NextDrone''' % (startid, self.ournexttype)
query = neo4j.CypherQuery(CMAdb.cdb.db, q)
for elem in CMAdb.store.load_cypher_nodes(query, Drone):
yield elem
return
示例5: __init__
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
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.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
self.monitors_activated = False
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})
示例6: load_json
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def load_json(store, json, bp_class, rulesetname, basedon=None):
"""Load JSON for a single JSON ruleset into the database."""
rules = store.load_or_create(BPRules, bp_class=bp_class, json=json, rulesetname=rulesetname)
if basedon is None or not Store.is_abstract(rules):
return
parent = store.load(BPRules, bp_class=bp_class, rulesetname=basedon)
store.relate_new(rules, CMAconsts.REL_basis, parent, properties={"bp_class": bp_class})
return rules
示例7: __init__
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def __init__(self, rulesetname, basisrules=None):
GraphNode.__init__(self, domain='metadata')
self.rulesetname = rulesetname
self.basisrules = basisrules
if self.basisrules is None or not Store.is_abstract(self):
return
query = CMAconsts.QUERY_RULESET_RULES
parent = CMAdb.store.load_cypher_node(query, BPRuleSet, params={'name': basisrules})
CMAdb.store.relate_new(self, CMAconsts.REL_basedon, parent)
示例8: load_json
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def load_json(store, json, bp_class, rulesetname, basedon=None):
'''Load JSON for a single JSON ruleset into the database.'''
if bp_class not in BestPractices.wantedpackets:
raise ValueError('%s is not a valid best practice discovery name' % bp_class)
rules = store.load_or_create(BPRules, bp_class=bp_class, json=json,
rulesetname=rulesetname)
if basedon is None or not Store.is_abstract(rules):
return
parent = store.load(BPRules, bp_class=bp_class, rulesetname=basedon)
store.relate_new(rules, CMAconsts.REL_basis, parent,
properties={'bp_class': bp_class})
return rules
示例9: post_db_init
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def post_db_init(self):
'''Create IS_A relationship to our 'class' node in the database, and set creation time'''
if not self._baseinitfinished:
self._baseinitfinished = True
if Store.is_abstract(self) and self.nodetype != CMAconsts.NODE_nodetype:
store = Store.getstore(self)
if self.nodetype not in GraphNode.classtypeobjs:
GraphNode.initclasstypeobj(store, self.nodetype)
store.relate(self, CMAconsts.REL_isa, GraphNode.classtypeobjs[self.nodetype])
assert GraphNode.classtypeobjs[self.nodetype].name == self.nodetype
self.time_create_ms = int(round(time.time()*1000))
self.time_create_iso8601 = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime())
示例10: _process_mgmt_addr
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def _process_mgmt_addr(self, switch, chassisid, attrs):
'Process the ManagementAddress field in the LLDP packet'
# FIXME - not sure if I know how I should do this now - no MAC address for mgmtaddr?
mgmtaddr = attrs['ManagementAddress']
mgmtnetaddr = pyNetAddr(mgmtaddr)
atype = mgmtnetaddr.addrtype()
if atype == ADDR_FAMILY_IPV4 or atype == ADDR_FAMILY_IPV6:
# MAC addresses are permitted, but IP addresses are preferred
chassisaddr = pyNetAddr(chassisid)
chassistype = chassisaddr.addrtype()
if chassistype == ADDR_FAMILY_802: # It might be an IP address instead
adminnic = self.store.load_or_create(NICNode, domain=switch.domain
, macaddr=chassisid, ifname='(adminNIC)')
mgmtip = self.store.load_or_create(IPaddrNode, domain=switch.domain
, cidrmask='unknown', ipaddr=mgmtaddr)
if Store.is_abstract(adminnic) or Store.is_abstract(switch):
self.store.relate(switch, CMAconsts.REL_nicowner, adminnic)
if Store.is_abstract(mgmtip) or Store.is_abstract(adminnic):
self.store.relate(adminnic, CMAconsts.REL_ipowner, mgmtip)
else:
self.log.info('LLDP ATTRS: %s' % str(attrs))
if mgmtnetaddr != chassisaddr:
# Not really sure what I should be doing in this case...
self.log.warning(
'Chassis ID [%s] not a MAC addr and not the same as mgmt addr [%s]'
% (chassisid, mgmtaddr))
self.log.warning('Chassis ID [%s] != mgmt addr [%s]'
% (str(mgmtnetaddr), str(chassisaddr)))
elif atype == ADDR_FAMILY_802:
mgmtnic = self.store.load_or_create(NICNode, domain=switch.domain
, macaddr=mgmtaddr, ifname='(ManagementAddress)')
if Store.is_abstract(mgmtnic) or Store.is_abstract(switch):
self.store.relate(switch, CMAconsts.REL_nicowner, mgmtnic)
示例11: _add_service_monitoring
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def _add_service_monitoring(self, drone, monitoredservice, moninfo):
'''
We start the monitoring of 'monitoredservice' using the information
in 'moninfo' - which came from MonitoringRule.constructaction()
'''
monitorclass = moninfo['monitorclass']
monitortype = moninfo['monitortype']
if 'provider' in moninfo:
monitorprovider = moninfo['provider']
classtype = "%s::%s:%s" % (monitorclass, monitorprovider, monitortype)
else:
monitorprovider = None
classtype = "%s::%s" % (monitorclass, monitortype)
# Compute interval and timeout - based on global 'config'
params = ConfigFile.agent_params(self.config, 'monitoring', classtype, drone.designation)
monitorinterval = params['parameters']['repeat']
monitortimeout = params['parameters']['timeout']
monitorarglist = moninfo.get('arglist', {})
monargv = moninfo.get('argv', None)
# Make up a monitor name that should be unique to us -- but reproducible
# We create the monitor name from the host name, the monitor class,
# monitoring type and a hash of the arguments to the monitoring agent
# Note that this is different from the hashed service/entity name, since we could
# have multiple ways of monitoring the same entity
d = hashlib.md5()
# pylint mistakenly thinks md5 objects don't have update member
# pylint: disable=E1101
d.update('%s:%s:%s:%s'
% (drone.designation, monitorclass, monitortype, monitorprovider))
if monitorarglist is not None:
names = monitorarglist.keys()
names.sort()
for name in names:
# pylint thinks md5 objects don't have update member
# pylint: disable=E1101
d.update('"%s": "%s"' % (name, monitorarglist[name]))
monitorname = ('%s:%s:%s::%s'
% (drone.designation, monitorclass, monitortype, d.hexdigest()))
monnode = self.store.load_or_create(MonitorAction, domain=drone.domain
, monitorname=monitorname, monitorclass=monitorclass
, monitortype=monitortype, interval=monitorinterval, timeout=monitortimeout
, provider=monitorprovider, arglist=monitorarglist, argv=monargv)
if monitorclass == 'nagios':
monnode.nagiospath = self.config['monitoring']['nagiospath']
if not Store.is_abstract(monnode):
print >> sys.stderr, ('Previously monitored %s on %s'
% (monitortype, drone.designation))
monnode.activate(monitoredservice, drone)
示例12: __str__
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def __str__(self):
'Default routine for printing CMAclass objects'
result = '%s({' % self.__class__.__name__
comma = ''
for attr in Store.safe_attrs(self):
result += '%s%s = %s'% (comma, attr, str(getattr(self, attr)))
comma = ",\n "
if Store.has_node(self):
if Store.is_abstract(self):
result += comma + 'HasNode = "abstract"'
else:
result += (comma + 'HasNode = %d' %Store.id(self))
result += "\n})"
return result
示例13: __str__
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def __str__(self):
"Default routine for printing GraphNodes"
result = "%s({" % self.__class__.__name__
comma = ""
for attr in Store.safe_attrs(self):
result += "%s%s = %s" % (comma, attr, str(getattr(self, attr)))
comma = ",\n "
if Store.has_node(self):
if Store.is_abstract(self):
result += comma + 'HasNode = "abstract"'
else:
result += comma + "HasNode = %d" % Store.id(self)
result += "\n})"
return result
示例14: __init__
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
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 CypherQuery
objects for a couple of queries we know we'll need later.
'''
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.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
self.monitors_activated = False
if Drone.IPownerquery_1 is None:
Drone.IPownerquery_1 = neo4j.CypherQuery(CMAdb.cdb.db, Drone.IPownerquery_1_txt
% (CMAconsts.REL_ipowner, CMAconsts.REL_nicowner))
Drone.OwnedIPsQuery_subtxt = Drone.OwnedIPsQuery_txt \
% (CMAconsts.REL_nicowner, CMAconsts.REL_ipowner)
Drone.OwnedIPsQuery = neo4j.CypherQuery(CMAdb.cdb.db, Drone.OwnedIPsQuery_subtxt)
self.set_crypto_identity()
if Store.is_abstract(self) and not CMAdb.store.readonly:
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):
CMAdb.store.relate(self, CMAconsts.REL_bprulefor, rule,
properties={'bp_class': rule.bp_class})
示例15: processpkt
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import is_abstract [as 别名]
def processpkt(self, drone, _unused_srcaddr, jsonobj, discoverychanged):
''' Kick off discovery for a Docker or vagrant instance - as though it were a
real boy -- I mean a real Drone
'''
if not discoverychanged:
return
data = jsonobj['data']
if 'containers' not in data:
return
childtype = jsonobj['discovertype']
systems = data['containers']
#print >> sys.stderr, '=====================GOT %s packet' % (childtype)
discovery_types = self.config['containers'][childtype]['initial_discovery']
for sysid in systems:
system = ChildSystem.childfactory(drone, childtype, sysid, systems[sysid])
if not Store.is_abstract(system):
continue
# Connect it to its parent system
self.store.relate_new(system, CMAconsts.REL_parentsys, drone)
runspec = ' "runas_user": "%s",' % system.runas_user \
if system.runas_user is not None else ''
if system.runas_group is not None:
runspec += ' "runas_group": "%s",' % system.runas_group
allparams = []
for dtype in discovery_types:
# kick off discovery...
instance = '_init_%s_%s' % (dtype, system.childpath)
allparams.append(pyConfigContext(
'{"%s": "%s", "%s": "%s",%s "parameters":{"%s": "%s"}}'
% (CONFIGNAME_TYPE, dtype,
CONFIGNAME_INSTANCE, instance,
runspec,
'ASSIM_PROXY_PATH', system.childpath
)))
# kick off discovery...
#print >> sys.stderr, '=====================REQUESTING DISCOVERY: %s' % (str(allparams))
system.request_discovery(allparams)