2014-12-15 18:22:53 +00:00
|
|
|
from xml.dom.minidom import parse
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2017-08-07 19:58:51 +01:00
|
|
|
from core import logger
|
2018-06-06 22:51:45 +01:00
|
|
|
from core.conf import ConfigShim
|
2017-04-25 16:45:34 +01:00
|
|
|
from core.enumerations import NodeTypes
|
|
|
|
from core.misc import nodeutils
|
2018-06-15 22:03:27 +01:00
|
|
|
from core.service import ServiceManager, ServiceShim
|
2017-04-25 16:45:34 +01:00
|
|
|
from core.xml import xmlutils
|
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
|
2015-02-05 00:15:59 +00:00
|
|
|
class CoreDocumentParser0(object):
|
2014-12-15 18:22:53 +00:00
|
|
|
def __init__(self, session, filename, options):
|
|
|
|
self.session = session
|
|
|
|
self.filename = filename
|
|
|
|
if 'dom' in options:
|
|
|
|
# this prevents parsing twice when detecting file versions
|
|
|
|
self.dom = options['dom']
|
|
|
|
else:
|
|
|
|
self.dom = parse(filename)
|
|
|
|
self.start = options['start']
|
|
|
|
self.nodecls = options['nodecls']
|
|
|
|
|
2017-04-25 16:45:34 +01:00
|
|
|
self.np = xmlutils.get_one_element(self.dom, "NetworkPlan")
|
2014-12-15 18:22:53 +00:00
|
|
|
if self.np is None:
|
|
|
|
raise ValueError, "missing NetworkPlan!"
|
2017-04-25 16:45:34 +01:00
|
|
|
self.mp = xmlutils.get_one_element(self.dom, "MotionPlan")
|
|
|
|
self.sp = xmlutils.get_one_element(self.dom, "ServicePlan")
|
|
|
|
self.meta = xmlutils.get_one_element(self.dom, "CoreMetaData")
|
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
self.coords = self.getmotiondict(self.mp)
|
|
|
|
# link parameters parsed in parsenets(), applied in parsenodes()
|
|
|
|
self.linkparams = {}
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
self.parsedefaultservices()
|
|
|
|
self.parseorigin()
|
|
|
|
self.parsenets()
|
|
|
|
self.parsenodes()
|
|
|
|
self.parseservices()
|
|
|
|
self.parsemeta()
|
|
|
|
|
|
|
|
def getmotiondict(self, mp):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Parse a MotionPlan into a dict with node names for keys and coordinates
|
2014-12-15 18:22:53 +00:00
|
|
|
for values.
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
if mp is None:
|
|
|
|
return {}
|
|
|
|
coords = {}
|
|
|
|
for node in mp.getElementsByTagName("Node"):
|
|
|
|
nodename = str(node.getAttribute("name"))
|
|
|
|
if nodename == '':
|
|
|
|
continue
|
|
|
|
for m in node.getElementsByTagName("motion"):
|
|
|
|
if m.getAttribute("type") != "stationary":
|
|
|
|
continue
|
|
|
|
point = m.getElementsByTagName("point")
|
|
|
|
if len(point) == 0:
|
|
|
|
continue
|
|
|
|
txt = point[0].firstChild
|
|
|
|
if txt is None:
|
|
|
|
continue
|
|
|
|
xyz = map(int, txt.nodeValue.split(','))
|
|
|
|
z = None
|
|
|
|
x, y = xyz[0:2]
|
2017-04-25 16:45:34 +01:00
|
|
|
if len(xyz) == 3:
|
2014-12-15 18:22:53 +00:00
|
|
|
z = xyz[2]
|
|
|
|
coords[nodename] = (x, y, z)
|
|
|
|
return coords
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getcommonattributes(obj):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Helper to return tuple of attributes common to nodes and nets.
|
|
|
|
"""
|
2018-06-13 19:59:50 +01:00
|
|
|
node_id = obj.getAttribute("id")
|
|
|
|
try:
|
|
|
|
node_id = int(node_id)
|
|
|
|
except:
|
|
|
|
logger.debug("parsing node without integer id: %s", node_id)
|
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
name = str(obj.getAttribute("name"))
|
2017-08-07 21:02:25 +01:00
|
|
|
node_type = str(obj.getAttribute("type"))
|
|
|
|
return node_id, name, node_type
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsenets(self):
|
|
|
|
linkednets = []
|
|
|
|
for net in self.np.getElementsByTagName("NetworkDefinition"):
|
2017-08-07 21:02:25 +01:00
|
|
|
node_id, name, node_type = self.getcommonattributes(net)
|
|
|
|
nodecls = xmlutils.xml_type_to_node_class(node_type)
|
2014-12-15 18:22:53 +00:00
|
|
|
if not nodecls:
|
2017-08-07 21:02:25 +01:00
|
|
|
logger.warn("skipping unknown network node '%s' type '%s'", name, node_type)
|
2014-12-15 18:22:53 +00:00
|
|
|
continue
|
2017-08-07 21:02:25 +01:00
|
|
|
n = self.session.add_object(cls=nodecls, objid=node_id, name=name, start=self.start)
|
2014-12-15 18:22:53 +00:00
|
|
|
if name in self.coords:
|
|
|
|
x, y, z = self.coords[name]
|
|
|
|
n.setposition(x, y, z)
|
2017-04-25 16:45:34 +01:00
|
|
|
xmlutils.get_params_set_attrs(net, ("icon", "canvas", "opaque"), n)
|
2014-12-15 18:22:53 +00:00
|
|
|
if hasattr(n, "canvas") and n.canvas is not None:
|
|
|
|
n.canvas = int(n.canvas)
|
|
|
|
# links between two nets (e.g. switch-switch)
|
|
|
|
for ifc in net.getElementsByTagName("interface"):
|
|
|
|
netid = str(ifc.getAttribute("net"))
|
|
|
|
ifcname = str(ifc.getAttribute("name"))
|
|
|
|
linkednets.append((n, netid, ifcname))
|
|
|
|
self.parsemodels(net, n)
|
|
|
|
# link networks together now that they all have been parsed
|
2017-04-25 16:45:34 +01:00
|
|
|
for n, netid, ifcname in linkednets:
|
2014-12-15 18:22:53 +00:00
|
|
|
try:
|
2017-04-25 16:45:34 +01:00
|
|
|
n2 = n.session.get_object_by_name(netid)
|
2014-12-15 18:22:53 +00:00
|
|
|
except KeyError:
|
2017-04-25 16:45:34 +01:00
|
|
|
logger.warn("skipping net %s interface: unknown net %s", n.name, netid)
|
2014-12-15 18:22:53 +00:00
|
|
|
continue
|
|
|
|
upstream = False
|
|
|
|
netif = n.getlinknetif(n2)
|
|
|
|
if netif is None:
|
|
|
|
netif = n2.linknet(n)
|
|
|
|
else:
|
|
|
|
netif.swapparams('_params_up')
|
|
|
|
upstream = True
|
2017-04-25 16:45:34 +01:00
|
|
|
key = (n2.name, ifcname)
|
2014-12-15 18:22:53 +00:00
|
|
|
if key in self.linkparams:
|
2017-04-25 16:45:34 +01:00
|
|
|
for k, v in self.linkparams[key]:
|
2014-12-15 18:22:53 +00:00
|
|
|
netif.setparam(k, v)
|
|
|
|
if upstream:
|
|
|
|
netif.swapparams('_params_up')
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsenodes(self):
|
|
|
|
for node in self.np.getElementsByTagName("Node"):
|
|
|
|
id, name, type = self.getcommonattributes(node)
|
|
|
|
if type == "rj45":
|
2017-04-25 16:45:34 +01:00
|
|
|
nodecls = nodeutils.get_node_class(NodeTypes.RJ45)
|
2014-12-15 18:22:53 +00:00
|
|
|
else:
|
|
|
|
nodecls = self.nodecls
|
2017-04-25 16:45:34 +01:00
|
|
|
n = self.session.add_object(cls=nodecls, objid=id, name=name, start=self.start)
|
2014-12-15 18:22:53 +00:00
|
|
|
if name in self.coords:
|
|
|
|
x, y, z = self.coords[name]
|
|
|
|
n.setposition(x, y, z)
|
|
|
|
n.type = type
|
2017-04-25 16:45:34 +01:00
|
|
|
xmlutils.get_params_set_attrs(node, ("icon", "canvas", "opaque"), n)
|
2014-12-15 18:22:53 +00:00
|
|
|
if hasattr(n, "canvas") and n.canvas is not None:
|
|
|
|
n.canvas = int(n.canvas)
|
|
|
|
for ifc in node.getElementsByTagName("interface"):
|
|
|
|
self.parseinterface(n, ifc)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parseinterface(self, n, ifc):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Parse a interface block such as:
|
2014-12-15 18:22:53 +00:00
|
|
|
<interface name="eth0" net="37278">
|
|
|
|
<address type="mac">00:00:00:aa:00:01</address>
|
|
|
|
<address>10.0.0.2/24</address>
|
|
|
|
<address>2001::2/64</address>
|
|
|
|
</interface>
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
name = str(ifc.getAttribute("name"))
|
|
|
|
netid = str(ifc.getAttribute("net"))
|
|
|
|
hwaddr = None
|
|
|
|
addrlist = []
|
|
|
|
try:
|
2017-04-25 16:45:34 +01:00
|
|
|
net = n.session.get_object_by_name(netid)
|
2014-12-15 18:22:53 +00:00
|
|
|
except KeyError:
|
2017-04-25 16:45:34 +01:00
|
|
|
logger.warn("skipping node %s interface %s: unknown net %s", n.name, name, netid)
|
2014-12-15 18:22:53 +00:00
|
|
|
return
|
|
|
|
for addr in ifc.getElementsByTagName("address"):
|
2017-04-25 16:45:34 +01:00
|
|
|
addrstr = xmlutils.get_text_child(addr)
|
2014-12-15 18:22:53 +00:00
|
|
|
if addrstr is None:
|
|
|
|
continue
|
|
|
|
if addr.getAttribute("type") == "mac":
|
|
|
|
hwaddr = addrstr
|
|
|
|
else:
|
|
|
|
addrlist.append(addrstr)
|
2018-03-01 17:26:28 +00:00
|
|
|
i = n.newnetif(net, addrlist=addrlist, hwaddr=hwaddr, ifindex=None, ifname=name)
|
2014-12-15 18:22:53 +00:00
|
|
|
for model in ifc.getElementsByTagName("model"):
|
|
|
|
self.parsemodel(model, n, n.objid)
|
|
|
|
key = (n.name, name)
|
|
|
|
if key in self.linkparams:
|
|
|
|
netif = n.netif(i)
|
2017-04-25 16:45:34 +01:00
|
|
|
for k, v in self.linkparams[key]:
|
2014-12-15 18:22:53 +00:00
|
|
|
netif.setparam(k, v)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsemodels(self, dom, obj):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Mobility/wireless model config is stored in a ConfigurableManager's
|
2014-12-15 18:22:53 +00:00
|
|
|
config dict.
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
nodenum = int(dom.getAttribute("id"))
|
|
|
|
for model in dom.getElementsByTagName("model"):
|
|
|
|
self.parsemodel(model, obj, nodenum)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsemodel(self, model, obj, nodenum):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Mobility/wireless model config is stored in a ConfigurableManager's
|
2014-12-15 18:22:53 +00:00
|
|
|
config dict.
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
name = model.getAttribute("name")
|
|
|
|
if name == '':
|
|
|
|
return
|
|
|
|
type = model.getAttribute("type")
|
|
|
|
# convert child text nodes into key=value pairs
|
2017-04-25 16:45:34 +01:00
|
|
|
kvs = xmlutils.get_text_elements_to_list(model)
|
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
mgr = self.session.mobility
|
|
|
|
# TODO: the session.confobj() mechanism could be more generic;
|
|
|
|
# it only allows registering Conf Message callbacks, but here
|
|
|
|
# we want access to the ConfigurableManager, not the callback
|
|
|
|
if name[:5] == "emane":
|
|
|
|
mgr = self.session.emane
|
|
|
|
elif name[:5] == "netem":
|
|
|
|
mgr = None
|
|
|
|
self.parsenetem(model, obj, kvs)
|
|
|
|
|
|
|
|
# TODO: assign other config managers here
|
|
|
|
if mgr:
|
2018-06-13 19:59:50 +01:00
|
|
|
for k, v in kvs:
|
|
|
|
mgr.set_config(k, v, node_id=nodenum, config_type=name)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsenetem(self, model, obj, kvs):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Determine interface and invoke setparam() using the parsed
|
2014-12-15 18:22:53 +00:00
|
|
|
(key, value) pairs.
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
ifname = model.getAttribute("netif")
|
|
|
|
peer = model.getAttribute("peer")
|
|
|
|
key = (peer, ifname)
|
|
|
|
# nodes and interfaces do not exist yet, at this point of the parsing,
|
|
|
|
# save (key, value) pairs for later
|
|
|
|
try:
|
|
|
|
kvs = map(self.numericvalue, kvs)
|
|
|
|
except ValueError:
|
2017-04-25 16:45:34 +01:00
|
|
|
logger.warn("error parsing link parameters for '%s' on '%s'", ifname, peer)
|
2014-12-15 18:22:53 +00:00
|
|
|
self.linkparams[key] = kvs
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
@staticmethod
|
|
|
|
def numericvalue(keyvalue):
|
|
|
|
(key, value) = keyvalue
|
|
|
|
if '.' in str(value):
|
|
|
|
value = float(value)
|
|
|
|
else:
|
|
|
|
value = int(value)
|
2017-04-25 16:45:34 +01:00
|
|
|
return key, value
|
2014-12-15 18:22:53 +00:00
|
|
|
|
|
|
|
def parseorigin(self):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Parse any origin tag from the Mobility Plan and set the CoreLocation
|
|
|
|
reference point appropriately.
|
|
|
|
"""
|
|
|
|
origin = xmlutils.get_one_element(self.mp, "origin")
|
2014-12-15 18:22:53 +00:00
|
|
|
if not origin:
|
|
|
|
return
|
|
|
|
location = self.session.location
|
|
|
|
geo = []
|
2017-04-25 16:45:34 +01:00
|
|
|
attrs = ("lat", "lon", "alt")
|
2014-12-15 18:22:53 +00:00
|
|
|
for i in xrange(3):
|
|
|
|
a = origin.getAttribute(attrs[i])
|
|
|
|
if a is not None:
|
|
|
|
a = float(a)
|
|
|
|
geo.append(a)
|
|
|
|
location.setrefgeo(geo[0], geo[1], geo[2])
|
|
|
|
scale = origin.getAttribute("scale100")
|
2018-04-26 00:33:58 +01:00
|
|
|
if scale is not None and scale:
|
2014-12-15 18:22:53 +00:00
|
|
|
location.refscale = float(scale)
|
2017-04-25 16:45:34 +01:00
|
|
|
point = xmlutils.get_one_element(origin, "point")
|
2014-12-15 18:22:53 +00:00
|
|
|
if point is not None and point.firstChild is not None:
|
|
|
|
xyz = point.firstChild.nodeValue.split(',')
|
|
|
|
if len(xyz) == 2:
|
|
|
|
xyz.append('0.0')
|
|
|
|
if len(xyz) == 3:
|
2017-04-25 16:45:34 +01:00
|
|
|
xyz = map(lambda (x): float(x), xyz)
|
2014-12-15 18:22:53 +00:00
|
|
|
location.refxyz = (xyz[0], xyz[1], xyz[2])
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsedefaultservices(self):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Prior to parsing nodes, use session.services manager to store
|
2014-12-15 18:22:53 +00:00
|
|
|
default services for node types
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
for node in self.sp.getElementsByTagName("Node"):
|
|
|
|
type = node.getAttribute("type")
|
|
|
|
if type == '':
|
2017-04-25 16:45:34 +01:00
|
|
|
continue # node-specific service config
|
2014-12-15 18:22:53 +00:00
|
|
|
services = []
|
|
|
|
for service in node.getElementsByTagName("Service"):
|
|
|
|
services.append(str(service.getAttribute("name")))
|
2018-06-22 22:41:06 +01:00
|
|
|
self.session.services.default_services[type] = services
|
2017-04-25 16:45:34 +01:00
|
|
|
logger.info("default services for type %s set to %s" % (type, services))
|
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parseservices(self):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
After node objects exist, parse service customizations and add them
|
2014-12-15 18:22:53 +00:00
|
|
|
to the nodes.
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
svclists = {}
|
|
|
|
# parse services and store configs into session.services.configs
|
|
|
|
for node in self.sp.getElementsByTagName("Node"):
|
|
|
|
name = node.getAttribute("name")
|
|
|
|
if name == '':
|
2017-04-25 16:45:34 +01:00
|
|
|
continue # node type without name
|
|
|
|
n = self.session.get_object_by_name(name)
|
2014-12-15 18:22:53 +00:00
|
|
|
if n is None:
|
2017-04-25 16:45:34 +01:00
|
|
|
logger.warn("skipping service config for unknown node '%s'" % name)
|
2014-12-15 18:22:53 +00:00
|
|
|
continue
|
|
|
|
for service in node.getElementsByTagName("Service"):
|
|
|
|
svcname = service.getAttribute("name")
|
|
|
|
if self.parseservice(service, n):
|
|
|
|
if n.objid in svclists:
|
|
|
|
svclists[n.objid] += "|" + svcname
|
|
|
|
else:
|
|
|
|
svclists[n.objid] = svcname
|
2017-04-25 16:45:34 +01:00
|
|
|
# nodes in NetworkPlan but not in ServicePlan use the
|
2014-12-15 18:22:53 +00:00
|
|
|
# default services for their type
|
|
|
|
for node in self.np.getElementsByTagName("Node"):
|
|
|
|
id, name, type = self.getcommonattributes(node)
|
|
|
|
if id in svclists:
|
2017-04-25 16:45:34 +01:00
|
|
|
continue # custom config exists
|
2014-12-15 18:22:53 +00:00
|
|
|
else:
|
2017-04-25 16:45:34 +01:00
|
|
|
svclists[int(id)] = None # use defaults
|
2014-12-15 18:22:53 +00:00
|
|
|
|
|
|
|
# associate nodes with services
|
|
|
|
for objid in sorted(svclists.keys()):
|
2017-04-25 16:45:34 +01:00
|
|
|
n = self.session.get_object(objid)
|
2018-06-15 22:03:27 +01:00
|
|
|
services = svclists[objid]
|
|
|
|
if services:
|
|
|
|
services = services.split("|")
|
2018-06-22 22:41:06 +01:00
|
|
|
self.session.services.add_services(node=n, node_type=n.type, services=services)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parseservice(self, service, n):
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
|
|
|
Use session.services manager to store service customizations before
|
2014-12-15 18:22:53 +00:00
|
|
|
they are added to a node.
|
2017-04-25 16:45:34 +01:00
|
|
|
"""
|
2014-12-15 18:22:53 +00:00
|
|
|
name = service.getAttribute("name")
|
2017-04-25 16:45:34 +01:00
|
|
|
svc = ServiceManager.get(name)
|
2014-12-15 18:22:53 +00:00
|
|
|
if svc is None:
|
|
|
|
return False
|
|
|
|
values = []
|
|
|
|
startup_idx = service.getAttribute("startup_idx")
|
|
|
|
if startup_idx is not None:
|
|
|
|
values.append("startidx=%s" % startup_idx)
|
|
|
|
startup_time = service.getAttribute("start_time")
|
|
|
|
if startup_time is not None:
|
|
|
|
values.append("starttime=%s" % startup_time)
|
|
|
|
dirs = []
|
|
|
|
for dir in service.getElementsByTagName("Directory"):
|
|
|
|
dirname = dir.getAttribute("name")
|
|
|
|
dirs.append(dirname)
|
|
|
|
if len(dirs):
|
|
|
|
values.append("dirs=%s" % dirs)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
startup = []
|
|
|
|
shutdown = []
|
|
|
|
validate = []
|
|
|
|
for cmd in service.getElementsByTagName("Command"):
|
|
|
|
type = cmd.getAttribute("type")
|
2017-04-25 16:45:34 +01:00
|
|
|
cmdstr = xmlutils.get_text_child(cmd)
|
2014-12-15 18:22:53 +00:00
|
|
|
if cmdstr is None:
|
|
|
|
continue
|
|
|
|
if type == "start":
|
|
|
|
startup.append(cmdstr)
|
|
|
|
elif type == "stop":
|
|
|
|
shutdown.append(cmdstr)
|
|
|
|
elif type == "validate":
|
|
|
|
validate.append(cmdstr)
|
|
|
|
if len(startup):
|
|
|
|
values.append("cmdup=%s" % startup)
|
|
|
|
if len(shutdown):
|
|
|
|
values.append("cmddown=%s" % shutdown)
|
|
|
|
if len(validate):
|
|
|
|
values.append("cmdval=%s" % validate)
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
files = []
|
|
|
|
for file in service.getElementsByTagName("File"):
|
|
|
|
filename = file.getAttribute("name")
|
|
|
|
files.append(filename)
|
2017-04-25 16:45:34 +01:00
|
|
|
data = xmlutils.get_text_child(file)
|
2018-06-22 23:47:02 +01:00
|
|
|
self.session.services.set_service_file(node_id=n.objid, service_name=name, file_name=filename, data=data)
|
2018-06-15 22:03:27 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
if len(files):
|
|
|
|
values.append("files=%s" % files)
|
|
|
|
if not bool(service.getAttribute("custom")):
|
|
|
|
return True
|
2018-06-22 22:41:06 +01:00
|
|
|
self.session.services.set_service(n.objid, svc)
|
2018-06-15 22:03:27 +01:00
|
|
|
# set custom values for custom service
|
2018-06-22 22:41:06 +01:00
|
|
|
svc = self.session.services.get_service(n.objid, None)
|
2018-06-15 22:03:27 +01:00
|
|
|
if not svc:
|
|
|
|
raise ValueError("custom service(%s) for node(%s) does not exist", svc.name, n.objid)
|
|
|
|
values = ConfigShim.str_to_dict("|".join(values))
|
|
|
|
for name, value in values.iteritems():
|
|
|
|
ServiceShim.setvalue(svc, name, value)
|
2014-12-15 18:22:53 +00:00
|
|
|
return True
|
2017-04-25 16:45:34 +01:00
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsehooks(self, hooks):
|
|
|
|
''' Parse hook scripts from XML into session._hooks.
|
|
|
|
'''
|
|
|
|
for hook in hooks.getElementsByTagName("Hook"):
|
|
|
|
filename = hook.getAttribute("name")
|
|
|
|
state = hook.getAttribute("state")
|
2017-04-25 16:45:34 +01:00
|
|
|
data = xmlutils.get_text_child(hook)
|
2014-12-15 18:22:53 +00:00
|
|
|
if data is None:
|
2017-04-25 16:45:34 +01:00
|
|
|
data = "" # allow for empty file
|
2014-12-15 18:22:53 +00:00
|
|
|
type = "hook:%s" % state
|
2017-04-25 16:45:34 +01:00
|
|
|
self.session.set_hook(type, file_name=filename, source_name=None, data=data)
|
|
|
|
|
2014-12-15 18:22:53 +00:00
|
|
|
def parsemeta(self):
|
2017-04-25 16:45:34 +01:00
|
|
|
opt = xmlutils.get_one_element(self.meta, "SessionOptions")
|
2014-12-15 18:22:53 +00:00
|
|
|
if opt:
|
|
|
|
for param in opt.getElementsByTagName("param"):
|
|
|
|
k = str(param.getAttribute("name"))
|
|
|
|
v = str(param.getAttribute("value"))
|
|
|
|
if v == '':
|
2017-04-25 16:45:34 +01:00
|
|
|
v = xmlutils.get_text_child(param) # allow attribute/text for newlines
|
2018-06-13 19:59:50 +01:00
|
|
|
self.session.options.set_config(k, v)
|
2017-04-25 16:45:34 +01:00
|
|
|
hooks = xmlutils.get_one_element(self.meta, "Hooks")
|
2014-12-15 18:22:53 +00:00
|
|
|
if hooks:
|
|
|
|
self.parsehooks(hooks)
|
2017-04-25 16:45:34 +01:00
|
|
|
meta = xmlutils.get_one_element(self.meta, "MetaData")
|
2014-12-15 18:22:53 +00:00
|
|
|
if meta:
|
|
|
|
for param in meta.getElementsByTagName("param"):
|
|
|
|
k = str(param.getAttribute("name"))
|
|
|
|
v = str(param.getAttribute("value"))
|
|
|
|
if v == '':
|
2017-04-25 16:45:34 +01:00
|
|
|
v = xmlutils.get_text_child(param)
|
2018-06-13 19:59:50 +01:00
|
|
|
self.session.metadata.set_config(k, v)
|